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

Conversation

mvorisek
Copy link
Contributor

@mvorisek mvorisek commented Jun 8, 2022

https://3v4l.org/FkrAj - only -1 results in the shortest 64-bit IEEE 754 floating-point representation possible, 17 can print more unneeded digits

also improve two math constants tests by asserting the exact values

@@ -6,7 +6,7 @@
* @var float
* @cname 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.

@@ -3518,7 +3518,7 @@ static const zend_function_entry class_AssertionError_methods[] = {
static void register_basic_functions_symbols(int module_number)
{
REGISTER_DOUBLE_CONSTANT("M_E", M_E, CONST_CS | CONST_PERSISTENT);
ZEND_ASSERT(M_E == 2.7182818284590451);
ZEND_ASSERT(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.

needed as compared as string here, https://3v4l.org/9C9LV

@@ -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

@@ -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

@mvorisek mvorisek marked this pull request as ready for review June 8, 2022 20:41
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

@cmb69
Copy link
Member

cmb69 commented Jun 12, 2022

@bwoebi, @kocsismate, what do you think about this PR?

@mvorisek
Copy link
Contributor Author

@bwoebi @kocsismate @cmb69 this PR sits here for a long time but is finished, can you please review?

@nikic
Copy link
Member

nikic commented Jul 23, 2022

This looks reasonable, but needs a rebase.

@mvorisek
Copy link
Contributor Author

rebased

@cmb69 cmb69 closed this in b0c0a2c Jul 23, 2022
@cmb69
Copy link
Member

cmb69 commented Jul 23, 2022

Thank you!

@mvorisek mvorisek deleted the patch-1 branch July 23, 2022 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants