Skip to content

Use -1 "precision" in gen_stub.php #8734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use PhpParser\PrettyPrinterAbstract;

error_reporting(E_ALL);
ini_set("precision", "17");
ini_set("precision", "-1");

const PHP_70_VERSION_ID = 70000;
const PHP_80_VERSION_ID = 80000;
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @var float
* @cvalue M_E
*/
const M_E = 2.7182818284590452354;
const M_E = 2.718281828459045;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is M_E declared here and no other math constants?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, indeed, that looks fishy. We use the definitions provided by libc, if available, and only define the macros ourselves otherwise. There is nothing special about M_E compared to the other constants (like M_PI).

However, given that we already go to great lengths to have portable floating point arithmetic, it may not be the best idea to rely on definitions provided by libc.


final class __PHP_Incomplete_Class
{
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions ext/standard/tests/math/constants.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--TEST--
Math constants
--INI--
precision=14
precision=-1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we want to assert the full precision, double is used for both x86/x64 build

--FILE--
<?php
$constants = array(
Expand All @@ -27,21 +27,21 @@ foreach($constants as $constant) {
printf("%-10s: %s\n", $constant, constant($constant));
}
?>
--EXPECTREGEX--
M_E : 2.718281[0-9]*
M_LOG2E : 1.442695[0-9]*
M_LOG10E : 0.434294[0-9]*
M_LN2 : 0.693147[0-9]*
M_LN10 : 2.302585[0-9]*
M_PI : 3.141592[0-9]*
M_PI_2 : 1.570796[0-9]*
M_PI_4 : 0.785398[0-9]*
M_1_PI : 0.318309[0-9]*
M_2_PI : 0.636619[0-9]*
M_SQRTPI : 1.772453[0-9]*
M_2_SQRTPI: 1.128379[0-9]*
M_LNPI : 1.144729[0-9]*
M_EULER : 0.577215[0-9]*
M_SQRT2 : 1.414213[0-9]*
M_SQRT1_2 : 0.707106[0-9]*
M_SQRT3 : 1.732050[0-9]*
--EXPECT--
M_E : 2.718281828459045
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on all platforms, the output should be strictly the same

M_LOG2E : 1.4426950408889634
M_LOG10E : 0.4342944819032518
M_LN2 : 0.6931471805599453
M_LN10 : 2.302585092994046
M_PI : 3.141592653589793
M_PI_2 : 1.5707963267948966
M_PI_4 : 0.7853981633974483
M_1_PI : 0.3183098861837907
M_2_PI : 0.6366197723675814
M_SQRTPI : 1.772453850905516
M_2_SQRTPI: 1.1283791670955126
M_LNPI : 1.1447298858494002
M_EULER : 0.5772156649015329
M_SQRT2 : 1.4142135623730951
M_SQRT1_2 : 0.7071067811865476
M_SQRT3 : 1.7320508075688772
2 changes: 0 additions & 2 deletions ext/standard/tests/math/constants_basic.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
Test for pre-defined math constants
--INI--
precision=14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var_dump uses (correctly) always the full/-1 precision

--FILE--
<?php
echo "M_E= ";
Expand Down