php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66188 var_export exports double wrong
Submitted: 2013-11-28 00:02 UTC Modified: 2013-11-29 09:18 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: chudinov at yahoo dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.4.22 OS: Windows
Private report: No CVE-ID: None
 [2013-11-28 00:02 UTC] chudinov at yahoo dot com
Description:
------------
var_export exports double numbers with wrong precision and as wrong number.
For example 1.1 will be exported as 1.1000000000000001
This bug is introduced in 5.4.22

Test script:
---------------
echo var_export(1.1, true);

Expected result:
----------------
echo var_export(1.1, true);
1.1


Actual result:
--------------
1.1000000000000001

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-29 00:23 UTC] phpmpan at mpan dot pl
Both outputs are equally valid according to how floating-point numbers are used. 1.1 is equivalent of 1.1000000000000001 and it doesn't matter which one you use.

None of the outputs is valid if you want to convey actual, unchanged value, as the actual value of 1.1(dec) is infinite sequence 1.0(0011)(bin) which, stored in a 64-bit IEEE-754 value, is equal to decimal 1.100000000000000088817841970012523233890533447265625.

Hence either this is NaB or the bug is that `var_export` doesn't use full precision available.
 [2013-11-29 09:18 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-11-29 09:18 UTC] nikic@php.net
var_export since recently uses the (typically larger) serialize_precision ini setting, rather than the precision one used for normal output.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 04:01:32 2024 UTC