Re: Understanding intval() and types conversion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



so...

you're saying that 7.99999 (repeating) is equal to 8.0....

i say prove it..  as i recall the numbers might be for all practical purposes the same, they are in fact vastly different...

so, prove your assertion...

-bruce


-----Original Message-----
From: Richard Lynch <ceo@xxxxxxxxx>
Sent: Jan 25, 2005 2:57 PM
To: Jochem Maas <jochem@xxxxxxxxxxxxx>
Cc: Jordi Canals <jcanals@xxxxxxxxx>, PHP List <php-general@xxxxxxxxxxxxx>
Subject: Re:  Understanding intval() and types conversion

> my guess this is a round error issue - never noticed this problem
> before...
> this is a problem right? anybody?

You can say it is a round error issue.

You can not say it is a problem.

You simply have to be aware that the float number which you think of as
8.0000000000000000000000000000... inside of PHP may well be represented as
7.9999999999999999999999999999... down in the guts of the machine.

It may help you feel better about this if you recall from grade school
mathematics, that, in point of fact:
7.999... is EXACTLY equal to 8.000...

Those who doubt this fact are requested to remember how to convert
decimals such as:
0.333...
to fractions (1/3), and then apply that exact same method to 7.999...

You will quickly find yourself with a fraction (72/9) which is precisely
equal to 8/1 which is 8.

EVERY floating point number, then, that ends in x000... has a second
representation, exactly equal, which ends in (x-1)999...

Bottom line, however you look at it, is that you can NEVER be 100% certain
that a computer's float number will convert to what you expect in an
integer because their internal representation simply does not allow for
perfection.

This is a feature, not a bug. :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux