Re: a print bug?



Summercoolness@xxxxxxxxx wrote:
it seems that the behavior of "print" is that it will round off
properly for any floating point imperfection, such as shown in the
first two samples. The third sample seems to be a bug? It doesn't
know how to handle the floating imperfection in this case.


1.2345

1.2344999999999999


print 1.2345

1.2345


print "%10.3f" % 1.2345 # seems like a bug ----------------------------------

1.234


print "%10.3f" % 1.23450001

1.235


print "%10.3f" % 1.2344

1.234


print "%10.3f" % 1.2346

1.235

>>> print "%25.22f" % 1.2345
1.2344999999999999000000

You obviously haven't yet passed your floating-point number proficiency test yet. Please restrict yourself to integers until you understand the difficulties that inaccuracies in floating-point can create ;-)

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

.



Relevant Pages

  • Re: a print bug?
    ... however, in the second line, when it is round off, it doesn't know it ... exactly in radix-2 floating point arithmetic. ... 11th decimal point with a subsequent rounding off to the 3rd decimal ... the floating point imperfection is manifested. ...
    (comp.lang.python)
  • Re: a print bug?
    ... however, in the second line, when it is round off, it doesn't know it ... the floating point imperfection is manifested. ... the customer" using print "%20.2f", then there will be a cent missing ...
    (comp.lang.python)
  • a print bug?
    ... it seems that the behavior of "print" is that it will round off ... The third sample seems to be a bug? ... know how to handle the floating imperfection in this case. ...
    (comp.lang.python)
  • Re: time.clock() going backwards??
    ... including printing the reprof the floating ... it so to ignore these bogus reads, and just reading off again. ... Is it possible this to be a bug in Python itself ... Are you running on a multi-core or a multi-processor machine? ...
    (comp.lang.python)
  • Re: An strange point
    ... I wrote a program which has a bug when the value of u is greater than ... The real error is that you do not understand the technical issues of floating ... otherwise know as finite precision computation. ... only interested in multiples of 0.1. ...
    (comp.lang.fortran)