Underscores in Python numbers
apardon at forel.vub.ac.be
Mon Nov 21 13:42:01 CET 2005
Op 2005-11-20, Roy Smith schreef <roy at panix.com>:
> cookedm+news at physics.mcmaster.ca (David M. Cooke) wrote:
>> One example I can think of is a large number of float constants used
>> for some math routine. In that case they usually be a full 16 or 17
>> digits. It'd be handy in that case to split into smaller groups to
>> make it easier to match with tables where these constants may come
>> from. Ex:
>> def sinxx(x):
>> "computes sin x/x for 0 <= x <= pi/2 to 2e-9"
>> a2 = -0.16666 66664
>> a4 = 0.00833 33315
>> a6 = -0.00019 84090
>> a8 = 0.00000 27526
>> a10= -0.00000 00239
>> x2 = x**2
>> return 1. + x2*(a2 + x2*(a4 + x2*(a6 + x2*(a8 + x2*a10))))
>> (or least that's what I like to write). Now, if I were going to higher
>> precision, I'd have more digits of course.
> You have described, if memory serves, a Taylor series, and those
> coefficients are 1/3!, 1/5!, 1/7!, etc.
Well if you had infinite precision numbers you might be right.
However in numerial analysis, one often uses numbers which
are slightly different, in order to have a more uniform error
spread over the interval used.
More information about the Python-list