php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63821 incorrect pi value
Submitted: 2012-12-20 21:43 UTC Modified: 2012-12-20 23:16 UTC
From: sandaq at gmail dot com Assigned: bjori (profile)
Status: Not a bug Package: Math related
PHP Version: 5.3.20 OS: linux
Private report: No CVE-ID: None
 [2012-12-20 21:43 UTC] sandaq at gmail dot com
Description:
------------
php doesn't calculate the correct value of pi

Test script:
---------------
php-cli -r 'ini_set('precision','100'); echo pi();'

or

<?
ini_set('precision','100');
echo pi()."\n"; exit;
?>



Expected result:
----------------
3.141592653589793238462643383279502884197169399375


Actual result:
--------------
3.141592653589793115997963468544185161590576171875
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-20 22:08 UTC] bjori@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: bjori
 [2012-12-20 22:08 UTC] bjori@php.net
You'll need to complain to whatever distribution you are using.
We don't define the value unless math.h doesn't define it for some wacky reason 
on your platform, in which case we fallback on 3.14159265358979323846.
 [2012-12-20 22:17 UTC] sandaq at gmail dot com
My distro is centos and pi is defined in math.h as correct value:
3.1415926535897932384626433832795029L

This happens on winxp also
 [2012-12-20 22:30 UTC] sandaq at gmail dot com
also tested on 3 different linux centos and 1 debian all with defined correct value of pi in math.h, all gave the same wrong output.
 [2012-12-20 22:32 UTC] sandaq at gmail dot com
-Status: Closed +Status: Assigned
 [2012-12-20 22:32 UTC] sandaq at gmail dot com
you still think its a distro problem?
 [2012-12-20 23:16 UTC] cataphract@php.net
-Status: Assigned +Status: Not a bug
 [2012-12-20 23:16 UTC] cataphract@php.net
Nothing to see here, read about floating point numbers and their rounding error.

In[9]:= Pi \
        //SetPrecision[#,MachinePrecision]& \
        //SetPrecision[#,Infinity]& \
        //N[#,100]&

Out[9]= 3.1415926535897931159979634685441851615905761718750000000000000000000\
 
>    00000000000000000000000000000000
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 07 06:01:28 2024 UTC