Advertisement
h-collector

precision test

Nov 12th, 2011
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. ini_set('precision', 64);
  2. $a=(float)12345678.0;
  3. $b=(float)12345679.0;
  4. $c=(float)1.01233995;
  5. $p=($a+$b+$c)/2;
  6. $result=($p-$b)*$p;
  7. var_dump($result);
  8. $result=(($a+$b+$c)/2.0-$b)*$b;
  9. var_dump($result);
  10.  
  11. $a='12345678.0';
  12. $b='12345679.0';
  13. $c='1.01233995';
  14. $precision = 64;
  15. $p=
  16. bcdiv(
  17.   bcadd(
  18.     bcadd($a,$b,$precision)
  19.   ,$c,$precision)
  20. ,'2',$precision);
  21. $result=
  22. bcmul(
  23.   bcsub($p,$b,$precision)
  24. ,$p,$precision);
  25. var_dump($result);
  26. $result=
  27. bcmul(
  28.   bcsub(
  29.     bcdiv(
  30.       bcadd(
  31.         bcadd($a,$b,$precision)
  32.       ,$c,$precision)
  33.     ,'2',$precision)
  34.   ,$b,$precision)
  35. ,$b,$precision);
  36. var_dump($result);
  37.  
  38. //float(76172.52840540916076861321926116943359375)
  39. //float(76172.528367340564727783203125)
  40. //string(70) "76172.5308260935915006250000000000000000000000000000000000000000000000"
  41. //string(70) "76172.5307880250000000000000000000000000000000000000000000000000000000"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement