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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: eugen at iwep dot ab dot ru
New email:
PHP Version: OS:

 

 [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: Thu Apr 25 12:01:31 2024 UTC