Bug #66450 [Opn]: Casting E notation strings to floats results in incorrect value

From: Date: Thu, 09 Jan 2014 17:46:32 +0000
Subject: Bug #66450 [Opn]: Casting E notation strings to floats results in incorrect value
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183672@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66450&edit=1

 ID:                 66450
 User updated by:    howard at zedcore dot com
 Reported by:        howard at zedcore dot com
-Summary:            Casting extremely large E notation strings to floats
                     results in incorrect value
+Summary:            Casting E notation strings to floats results in
                     incorrect value
 Status:             Open
 Type:               Bug
 Package:            *Programming Data Structures
 Operating System:   Debian Gnu/Linux "Wheezy" 7.2
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

It seems to affect any E notation string being cast to float.

var_dump(exp(10), (string)exp(1), exp(1) == (string)exp(1), exp(1) - (string)exp(1));

Result:

float(2.718281828459)
float(2.718281828459)
bool(false)
float(4.5297099404706E-14)


Previous Comments:
------------------------------------------------------------------------
[2014-01-09 17:40:43] howard at zedcore dot com

Description:
------------
Casting a very large float into a string and back-again results in a different value.

The string representation of both values from var_dump() is the same, and as expected.

Reproducible on PHP 5.4.4 and PHP 5.3.10 (Not able to upgrade to the latest PHP release at work but
I'll try to reproduce at home soon).

Test script:
---------------
var_dump(exp(100), (string)exp(100), exp(100) == (string)exp(100), exp(100) - (string)exp(100));

Expected result:
----------------
float(2.6881171418161E+43)
float(2.6881171418161E+43)
bool(true)
float(0)

Actual result:
--------------
float(2.6881171418161E+43)
float(2.6881171418161E+43)
bool(false)
float(3.5652673131419E+29)


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



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


Thread (4 messages)

« previous php.bugs (#183672) next »