mirror of
https://github.com/odin-lang/Odin.git
synced 2026-08-14 17:49:16 +00:00
The runtime implementations of quaternion division are incorrect when
calculating q/r with nonzero jmag(r) and either nonzero imag(q) or
kmag(q). Notably, the inverse 1/r is still calculated correctly
because imag(1) = kmag(1) = 0.
The mistake can be verified by calculating (a/b)*b which will be very
different from both a and a * (1/b) * b.
The compile-time constant folding is correct, see exact_value.cpp
in function exact_binary_operator_value -> ExactValue_Quaternion ->
Token_Quo.
quo256 :: proc(q, r: quaternion256) -> quaternion256 { return q/r }
a: quaternion256 : 3 + 5i + 7j + 11k
b: quaternion256 : 2 + 7i + 3j + 5k
c: quaternion256 : a/b
fmt.println("comp", abs((c*b) - a))
fmt.println("run ", abs(quo256(a,b)*b - a))
// both values should be very close to zero;
// without fix, only the first is