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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 14:01:37 2025 UTC