Numeric processing algorithm.
Kragen Sitaker
kragen at dnaco.net
Wed Sep 20 22:37:09 CEST 2000
In article <007001c01e35$b9c0e3a0$621aa7d1 at v1o9g4>,
The Majestic Moined Mogul <mogulNOSPAM at primus.ca> wrote:
>I know that Python is well known for its numeric processing power. Does
>anyone know what algorithm it uses to do so. Does it use the CORDIC?
It appears from web-searching that CORDIC is a clever set of algorithms
for computing trig and exponential functions using, among other things,
small lookup tables.
It looks like Python calculates these functions using the standard C
library math functions, which can use any algorithm whatsoever to
compute them, including CORDIC. See Modules/mathmodule.c for details.
ISTR Plauger's book on the standard C library recommends using
Chebyshev polynomials to approximate trig functions; glibc 2.1.3
(sysdeps/libm-ieee754/k_sin.c) uses some kind of polynomial
approximation, which looks to me like a truncated Taylor series.
Glibc on my machine actually calls the hardware instructions in my FPU
to compute the trig functions, though --- according to objdump:
000096d0 <sin>:
96d0: dd 44 24 04 fldl 0x4(%esp,1)
96d4: d9 fe fsin
96d6: df e0 fnstsw
96d8: a9 00 04 00 00 testl $0x400,%eax
96dd: 75 01 jne 96e0 <sin+0x10>
96df: c3 ret
96e0: d9 eb fldpi
96e2: d8 c0 fadd %st(0),%st
96e4: d9 c9 fxch %st(1)
96e6: d9 f5 fprem1
96e8: df e0 fnstsw
96ea: a9 00 04 00 00 testl $0x400,%eax
96ef: 75 f5 jne 96e6 <sin+0x16>
96f1: dd d9 fstp %st(1)
96f3: d9 fe fsin
96f5: c3 ret
I have no idea how the FPU on my machine calculates trig functions.
Probably not with CORDIC, though.
Does that answer your question?
--
<kragen at pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Perilous to all of us are the devices of an art deeper than we ourselves
possess.
-- Gandalf the Grey [J.R.R. Tolkien, "Lord of the Rings"]
More information about the Python-list
mailing list