php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22516 Pack&Unpack
Submitted: 2003-03-03 04:04 UTC Modified: 2003-03-03 09:23 UTC
From: eugen at iwep dot ab dot ru Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5CVS-2003-03-03 (dev) OS: Windows 2000
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2003-03-03 04:04 UTC] eugen at iwep dot ab dot ru
Hi all, Please try 
<?
$dat=pack ("f", 1.1);
$ar=unpack('fx',$dat);
print 'x='.$ar['x'].'<br>';
?>

Output:
x=1.10000002384
^^^^^^^^^^^^^^^^?????????????? maybe bug with float ?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-03 06:12 UTC] phanto@php.net
i reproduced that. seems that due to the fact that php's floats are actually doubles only half of the double gets initialized and should be initialized with 0.0 first.
 [2003-03-03 09:23 UTC] iliaa@php.net
The optimal approach at solving this problem, would be to use doubles, since in PHP floats are emulated via doubles.
<?
$dat=pack ("d", 1.1);
$ar=unpack('dx',$dat);
print 'x='.$ar['x'].'<br>';
?>

correctly will return   ["x"]=> float(1.1)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 08:01:30 2024 UTC