HELP: restore my faith in Python

Alex alex at
Fri Mar 3 20:43:02 CET 2000

I think it's a matter of small numerical errors:

>>> target = 6
>>> n=((target/(limit+0.0))-(target/limit))*limit
>>> n
>>> '%.50f' % n

I think that by default, python rounds off the output of float to 10
decimal places or something.

I guess the error is in the division:

>>> '%.50f' % (6/5.0)

If this erodes your faith in python, you should also cast a dubious eye
towards C, which this output is based on.  E.g., this program:

#include <stdio.h>

int main(){
  printf("%.50f\n", 6/5.0);

gives the output 1.19999999999999995559107901499373838305473327636719,
as well.


More information about the Python-list mailing list