Edit report at http://bugs.php.net/bug.php?id=52405&edit=1
ID: 52405 Comment by: chrisbabar at hotmail dot com Reported by: chrisbabar at hotmail dot com Summary: Inaccurate Pi calculation Status: Bogus Type: Bug Package: *Math Functions Operating System: Ubuntu 10.04 LTS PHP Version: 5.3.2 New Comment: I think I understand what you are saying - however this is essentially the same problem - without any float to string processing: <?php // Outputs bool(true) var_dump(3.14159265358979311599796 === 3.14159265358979323846264); ?> And if this is expected because of the limitations with the precision - should the precision of PHP be limited to 15 decimal places? Previous Comments: ------------------------------------------------------------------------ [2010-07-22 15:50:43] ahar...@php.net Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is, read this: http://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. ------------------------------------------------------------------------ [2010-07-22 15:44:47] chrisbabar at hotmail dot com Description: ------------ PHP seems to calculate pi incorrectly after 15 decimal places when calling the pi() function. I have used http://en.wikipedia.org/wiki/Pi as a reference for the correct value of pi. Test script: --------------- <?php ini_set("precision", 24); echo pi(); ?> Expected result: ---------------- 3.14159265358979323846264 Actual result: -------------- 3.14159265358979311599796 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52405&edit=1