revjim.net Rotating Header Image

Posts on ‘May 7th, 2003’

funny PHP math

After my funny math in Python demonstration, Matt decided to do it in Java and then again with even more types. So… I decided to try it in PHP.
Here's the code:
print("Let's do some math!\n");

$One = 1;
$Ten = 10;
$Pointone = 0.1;

print("loose: 1/10 = " . $One/$Ten . "\n");

$intOne = (int) 1;
$intTen = (int) 10;
$intPointone = (int) [...]

funny math

Math within a computer will never be perfect. Python, as Matt points out, trys to do the best that it can with what it has. By default, it assumes all numbers are integers and computation using them should only be as accurate as an integer can be. Hence:
>>> 1/10
0

We all know that one divided by [...]