This proposal extends the Go programming language to include quaternions, a hypercomplex noncommutative division algebra that generalizes the complex numbers to four dimensions. They're particularly useful for representing spatial rotations, such as in 3D graphics.
Quaternions are generally represented in the form a + bi + cj + dk, where a, b, c, and d are real numbers, and i, j, and k are the fundamental imaginary units satisfying i2 = j2 = k2 = ijk = -1.
Concretely, this proposal changes the language as follows:
- Generalizes imaginary literals to include
j and k suffixes.
- Extends numeric constants to include quaternion constants.
- Defines new numeric types for
quaternion128 and quaternion256 (and predeclares them).
- Extends the unary and binary
+ and - operators and the binary * operator to apply to quaternions.
- Defines a new
quaternion built-in function to construct quaternions from four real numbers.
- Extends the
real and imag built-in functions to also return the real and i-imaginary parts of quaternions.
- Defines new
jmag and kmag built-in functions to return the j- and k-imaginary parts of quaternions.
Also, it implies corresponding support and extensions to standard library packages.
This proposal extends the Go programming language to include quaternions, a hypercomplex noncommutative division algebra that generalizes the complex numbers to four dimensions. They're particularly useful for representing spatial rotations, such as in 3D graphics.
Quaternions are generally represented in the form a + bi + cj + dk, where a, b, c, and d are real numbers, and i, j, and k are the fundamental imaginary units satisfying i2 = j2 = k2 = ijk = -1.
Concretely, this proposal changes the language as follows:
jandksuffixes.quaternion128andquaternion256(and predeclares them).+and-operators and the binary*operator to apply to quaternions.quaternionbuilt-in function to construct quaternions from four real numbers.realandimagbuilt-in functions to also return the real and i-imaginary parts of quaternions.jmagandkmagbuilt-in functions to return the j- and k-imaginary parts of quaternions.Also, it implies corresponding support and extensions to standard library packages.