Bug #78688 [Opn->Nab]: Invalid float serialization

From: Date: Fri, 18 Oct 2019 11:39:08 +0000
Subject: Bug #78688 [Opn->Nab]: Invalid float serialization
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223245@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78688&edit=1

 ID:                 78688
 Updated by:         requinix@php.net
 Reported by:        eirik at nymedia dot no
 Summary:            Invalid float serialization
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Linux/OSX
 PHP Version:        7.3.10
 Block user comment: N
 Private report:     N

 New Comment:

Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.




Previous Comments:
------------------------------------------------------------------------
[2019-10-18 11:33:58] eirik at nymedia dot no

Description:
------------
I noticed when encoding a json object that the float 440.0 was not encoded correctly. So I looked
into it, and when the float 440.0 is constructed with the following multiplication it fails to
serialize, var_export and json_encode properly (and probably others):

$var = "4.400000" * 100;

Test script:
---------------
$var = "4.400000" * 100;
var_export($var);
print PHP_EOL;
print json_encode($var);
print PHP_EOL;
print serialize($var);
print PHP_EOL;

// Output:
// 440.00000000000006
// 440.00000000000006
// d:440.00000000000006;

Expected result:
----------------
440.0
440
d:440;

Actual result:
--------------
440.00000000000006
440.00000000000006
d:440.00000000000006;


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78688&edit=1


Thread (4 messages)

« previous php.bugs (#223245) next »