diff --git a/NEWS b/NEWS index 1fd03816816e..2e41ca8ba382 100644 --- a/NEWS +++ b/NEWS @@ -36,6 +36,7 @@ PHP NEWS . Fixed AST export of by-reference property hooks. (Jorg Sowa) . Fixed AST export of property hook parameter lists and attributes. (Jorg Sowa) + . Fixed float literals losing precision in AST export. (Jorg Sowa) - Curl: . Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire) diff --git a/Zend/tests/assert/expect_float_precision.phpt b/Zend/tests/assert/expect_float_precision.phpt new file mode 100644 index 000000000000..b2a1cb6ae805 --- /dev/null +++ b/Zend/tests/assert/expect_float_precision.phpt @@ -0,0 +1,25 @@ +--TEST-- +assert() message preserves float literals regardless of precision +--INI-- +zend.assertions=1 +precision=14 +--FILE-- + assert(0.30000000000000004 === 0.3), + fn() => assert(123456789012345678.0 === 0.0), + fn() => assert(0.1 === 1.5e-300), + fn() => assert(1.0 === 2.0), +] as $fn) { + try { + $fn(); + } catch (AssertionError $e) { + echo $e::class, ": ", $e->getMessage(), "\n"; + } +} +?> +--EXPECT-- +AssertionError: assert(0.30000000000000004 === 0.3) +AssertionError: assert(1.2345678901234568E+17 === 0.0) +AssertionError: assert(0.1 === 1.5E-300) +AssertionError: assert(1.0 === 2.0) diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index e884ba897d86..a7763a262d5d 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -2113,7 +2113,7 @@ static ZEND_COLD void zend_ast_export_zval(smart_str *str, const zval *zv, int p break; case IS_DOUBLE: smart_str_append_double( - str, Z_DVAL_P(zv), (int) EG(precision), /* zero_fraction */ true); + str, Z_DVAL_P(zv), /* precision */ -1, /* zero_fraction */ true); break; case IS_STRING: zend_ast_export_quoted_str(str, Z_STR_P(zv));