Sujet : Re: Radians Or Degrees?
De : terje.mathisen (at) *nospam* tmsw.no (Terje Mathisen)
Groupes : comp.lang.c comp.archDate : 16. Mar 2024, 16:59:19
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <ut4fkn$2vfdf$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.18.1
MitchAlsup1 wrote:
Michael S wrote:
To make it less tempting, you could try to push for inclusion of
rsqrt() into basic set. Long overdue, IMHO.
Many Newton-Raphson iterations converge more rapidly with RSQRT than
with SQRT, for reasons I never looked that deeply into.
The classic NR iteration for rsqrt() uses only fmul & fadd/fsub, while the naive sqrt() version needs a divide in every iteration.
Personally I prefer to use the y = rsqrt(x) form and then just multiply by x in the end:
y = sqrt(x) = x/sqrt(x) = rsqrt(x)*x
In order to get the rounding correct from this form you can probably just square the final result and compare this with the original input?
Right now, I can't think of any other transcendental that I really want
to elevate to higher status. It seems to me that elevation of log2(x)
and of 2**x will do no harm, but I am not sure about usefulness.
Ln2 and EXP2 are the basis of My 66000 log and EXP families, performed in
HW function unit.
Ln2 has the property that a binade [1..2) maps directly to another binade
[2..4); exp2 has a similar property. Ln2 is easier to get good accuracy
from than Ln or Log as a starting point. But in any event:: you are always within a high precision multiply of the correct result = round(53×106);
Exactly the same reasoning I used to compute rsqrt() over the [1.0 - 4.0> range, or (simplifying the exp logic) over [0.5 - 2.0> so that the last exp bit maps to the first vs second half of the range. Back before we got approximate rsqrt() lookup opcodes, I wrote code that took the last exp bit and the first n mantissa bits and looked up an optimal starting point for that value + 0.5 ulp. Getting 11-12 bits this way means approximatly correct float after a single iteration and useful double after two.
Terje
-- - <Terje.Mathisen at tmsw.no>"almost all programming can be viewed as an exercise in caching"