Sat Mar 9 18:27:23 EST 2013
Given a,b s.t. a^2+b^2 ~= 1, is there a fast way to push this closer
to the unit circle? Direction doesn't matter so much.
( The a and b are sin and cos from a truncated taylor expansion. It is
probably possible to find out which of the two is systematically more
Exact normalization would be scaling by r = 1 / sqrt(a^2 + b^2).
This needs to somehow be approximated. Since r will be close to one,
the following taylor series could be used:
1 / (1 + x)^1/2 ~= 1 - 1/2 x
;; Approximate normalization for a^2 + b^2 close to 1
;; Exact coef: r = (a^2 + b^2)^1/2, a -> r a, b -> r b
;; Since this is close to 1 we can use 1st order Taylor:
;; r = 1 / (1 - x)^1/2 ~= 1 + 1/2 x with x = 1 - (a^2 + b^2)
;; Maybe using a -> a + (r1 * a) with r1 = 1/2 x is more stable?
;; Don't think so, since x does not have many significant bits, it's
;; probably OK to hide it in the LSBs of r.
(lambda (a b)
(let* ((a2 (* a a))
(b2 (* b b))
(x (- 1 (+ a2 b2)))
(r (+ 1 (* 0.5 x))))
(values (* r a)
(* r b)))))