RE: [PHP] Math Weirdness
| From: | Ford, Mike | Date: | Tue, 15 Jul 2008 10:24:00 +0000 |
| Subject: | RE: [PHP] Math Weirdness | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-276816@lists.php.net to get a copy of this message | ||
On 14 July 2008 20:47, tedd advised:
> Round-off errors normally don't enter into things unless your doing
> multiplication and division operations. At that point, what you get
> back from the operation is an approximation and not the actual
> number.
Bull! Nearly all computer floating point numbers are approximations
because of being held in binary rather than decimal. Any number with a
(decimal) fractional part that doesn't end with the digit 5 is
necessarily an approximation, and that's only half the story. So as soon
as you involve numbers like 0.1 or 0.2, you've already got minor
inaccuracies which will propagate through any kind of arithmetic -- it's
just worse with multiplication or division because these tend to result
in inaccuracy in more significant digits!
Bottom line: a floating point value should *always* be treated with an
appropriate degree of suspicion.
Cheers!
Mike
--
Mike Ford, Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus,
Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 812 4730
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm