Skip to content

Instantly share code, notes, and snippets.

@metalmatze
Created February 10, 2014 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metalmatze/8914402 to your computer and use it in GitHub Desktop.
Save metalmatze/8914402 to your computer and use it in GitHub Desktop.
This little script calculates lower numbers until there is no difference for the machine
<?php
$difference = 1.0;
$i = 0;
while(1.0 + $difference != 1.0)
{
if ($i % 5 == 0)
printf("%4.0f | %16.8e | unequal 1\n", $i, $difference);
$difference = $difference / 2.0;
$i = $i + 1;
}
printf("%4.0f | %16.8e | equal 1\n", $i, $difference);
@metalmatze
Copy link
Author

Start like php machine-accuracy.php

@metalmatze
Copy link
Author

Output:

0 |    1.00000000e+0 | unequal 1
5 |    3.12500000e-2 | unequal 1
10 |    9.76562500e-4 | unequal 1
15 |    3.05175781e-5 | unequal 1
20 |    9.53674316e-7 | unequal 1
25 |    2.98023224e-8 | unequal 1
30 |   9.31322575e-10 | unequal 1
35 |   2.91038305e-11 | unequal 1
40 |   9.09494702e-13 | unequal 1
45 |   2.84217094e-14 | unequal 1
50 |   8.88178420e-16 | unequal 1
53 |   1.11022302e-16 | equal 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment