Re: PHP can't add up??!

From: Joe (yojimbo99_at_uboot.com)
Date: 02/04/04


Date: Wed, 04 Feb 2004 17:31:34 +0100

Toby Newman wrote:

> Please can someone explain why the following code generates
> -0.049999999999999 rather than -0.05?
>
> <?php
> echo(8.23 + (-8.28));
> ?>
>
> Thanks!
> Toby

I think you have to go through the basics of 'how are floating point
numbers represented in computers'. As far as I remember is it a long
time existing problem of how to generate an exact binary representation
of decimal numbers for usage in computers...

Some hints if you need more

http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch02_05.htm
http://www.cs.rpi.edu/~hollingd/comporg/notes/fp/fp.pdf

or find some information yourself:

http://www.google.at/search?hl=de&ie=UTF-8&oe=UTF-8&q=rounding+floating+point+binary+representation&btnG=Google+Suche&meta=

Hope it helps a bit.
Joe



Relevant Pages

  • Re: A Simplified Number System
    ... > their one-hand representation with 12 alternatives with ... Binary is of interest and use mainly to certain theoreticians and ... Floating point can indeed pose difficulties. ... If the human can be excluded, the computers can ...
    (sci.lang)
  • Re: Rounding of the double
    ... If you're going to use floating point arithmetic then I really do recommend that you understand what a floating point representation of a number means. ... Floating point representations cannot be exact UNLESS you have a convention for knowing what all the decimal places out to infinity are - EVEN IF THOSE DIGITS ARE ZERO. ... Numerical mathemeticians have been doing this for centuries - and in some ways it was all much more important before we had computers which could carry 16 sig figs like they were nothing. ...
    (microsoft.public.vc.mfc)
  • Re: scwewy answers that dont belong
    ... I'm fully cognizant that computers don't make mistakes, ... not this thread entitled "Excel bug?". ... depending on the precision of the decimal representation, ... it is interesting that a decimal representation ...
    (microsoft.public.excel.worksheet.functions)
  • Re: God Proven to Exist According to Mainline Physics
    ... deny or remain agnostic about humans and computers ... But the equivalence lies solely in the representation. ... The reason why we represent information processing systems as IPSs (or ... neighbouring circuits, or there's quantum tunneling between circuits ...
    (talk.origins)
  • Re: God Proven to Exist According to Mainline Physics
    ... deny or remain agnostic about humans and computers ... But the equivalence lies solely in the representation. ... as Turing machines, or as Algorithmic Information Systems, etc.) is ... neighbouring circuits, or there's quantum tunneling between circuits ...
    (talk.origins)