From: Joachim Wesner <Joachim.Wesner@frankfurt.netsurf.de>
Subject: Re: sqrt performance
Date: Thu, 04 Mar 1999 19:30:32 +0100 [thread overview]
Message-ID: <36DED148.2FC2AF00@frankfurt.netsurf.de> (raw)
In-Reply-To: <199903040515.WAA19477@ellpspace.math.ualberta.ca>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3296 bytes --]
Michal Jaegermann wrote:
>
> esci wrote:
> >
> > I'm currently looking into using a table driven Taylor's series expansion.
> > Hint's and suggestions *very* welcome. I need to do this over the range
> > from 0 to 100,000,000 w/ the roots off by less than 1
>
> If you reduce that to an interval [0,1) this would mean that you
> need 10 decimal places. A decent polynomial approximation plus one
> step of a Newton iteration should bring you in that range, I think.
Not necessarily, at least not for high (aka. full 16 digits). There is a
reason that there is no polynomial based approximation for sqrt in
libffm.
First, you want uniform *relative* precision for the function over the
full range, so 0..1 won't work. However, you can take acount of the
floating point format and only operate on the mantissa and 0.25..1 or
0.5..1 using frexp and ldexp (which however, are notoriously ineffective
when using the C lib routine, clearly, you NEED assembler here).
Unfortunatelly, sqrt is notoriusly ugly in approximating even for small
intervalls, you need much higher orders (and large coefficients for the
high orders, i.e. bad with respect to numerical stability) compared to
say sin(), which is much more well behaved.
However, assuming you go for 0.5..1 where you probably need to adjust
the result by sqrt(0.5) (further slowdown, you need to test it and
decide) and you want 1e-10 final *relative* precision, you need better
1e-5 rel. precision before the final Newton step.
If anybody wants to give it a try, here are the coefficients for a
(nearly) minimax relative prec. polynomial:
For better 1e-5 rel. precision from 0.5..1 you already need a 5th order
polynomial with the coefficients
A 0:
2.07200449623728886e-001
A 1:
1.45700060266363978e+000
A 2:
-1.34960056099104825e+000
A 3:
1.11173630566745442e+000
A 4:
-5.38779078465377500e-001
A 5:
1.12443059720350031e-001
(i.e. A0 + x*A1 + x*x*A2 ...)
which gives you better than ~ 1.4e-6 rel. precision.
If you go for only forth order, you get
A 0:
2.30280650419599074e-001
A 1:
1.29379894493964541e+000
A 2:
-8.94996784387289337e-001
A 3:
4.88028708781137845e-001
A 4:
-1.17117604514064883e-001
however, max. rel. error here is just above the range, i.e. 1.1e-5
Compared to that, for 1e-8 or better 1e-9 initial rel. precision for a
full prec. version, you need >= 9th order, slow to evaluate on a machine
with pipled floating point unit. You can "vectorize" it by some tricks,
that are actually usued in libffm, but you have to further sacrifice
some precision for that.
I would be interested in the result you get, however, I fear, you won't
be able to beat the new libcpml speed !?
Best wishes,
Joachim
next prev parent reply other threads:[~1999-03-04 18:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-03-03 20:53 sqrt performance esci
1999-03-03 21:40 ` Andrei A. Dergatchev
1999-03-04 5:15 ` Michal Jaegermann
1999-03-04 18:30 ` Joachim Wesner [this message]
1999-03-04 18:48 ` sqrt performance, further comment Joachim Wesner
1999-03-04 19:41 ` Michal Jaegermann
1999-03-04 19:51 ` Joachim Wesner
1999-03-05 17:55 ` Joachim Wesner
-- strict thread matches above, loose matches on Subject: below --
1999-03-03 13:21 sqrt performance esci
1999-03-03 18:51 ` Andrei A. Dergatchev
1999-03-03 2:26 esci
1999-03-03 9:27 ` Andrei A. Dergatchev
1999-03-03 11:59 ` Kazushige Goto
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox