#41154 [NEW]: settype 'float' yields incosistent results

From: Date: Fri, 20 Apr 2007 21:25:23 +0000
Subject: #41154 [NEW]: settype 'float' yields incosistent results
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-111759@lists.php.net to get a copy of this message
From:             php at michaelho dot com
Operating system: Mac OS X 10.4.9
PHP version:      5.2.1
PHP Bug Type:     Variables related
Bug description:  settype 'float' yields incosistent results

Description:
------------
Using settype() to alter FLOATs yields inconsistent values that will
sometimes fail comparison operators.

Reproduce code:
---------------
<?php
	// THIS WILL WORK
	$fltOriginal = 3 * .5;
	$fltTransformed = $fltOriginal;

	settype($fltTransformed, 'string');
	settype($fltTransformed, 'float');

	var_dump($fltOriginal);
	var_dump($fltTransformed);
	if ($fltOriginal != $fltTransformed) print ('COMPARISON FAILED -- BUG');

	print ("--------------------------\r\n");


	// THIS WILL **NOT** WORK
	$fltOriginal = 3 * .6;
	$fltTransformed = $fltOriginal;

	settype($fltTransformed, 'string');
	settype($fltTransformed, 'float');

	var_dump($fltOriginal);
	var_dump($fltTransformed);
	if ($fltOriginal != $fltTransformed) print ('COMPARISON FAILED -- BUG');
?>

Expected result:
----------------
float(1.5)
float(1.5)
--------------------------
float(1.8)
float(1.8)

Actual result:
--------------
float(1.5)
float(1.5)
--------------------------
float(1.8)
float(1.8)
COMPARISON FAILED -- BUG

-- 
Edit bug report at http://bugs.php.net/?id=41154&edit=1
-- 
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41154&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41154&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41154&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=41154&r=fixedcvs
Fixed in release:             http://bugs.php.net/fix.php?id=41154&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=41154&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=41154&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=41154&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=41154&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=41154&r=notwrong
Not enough info:              http://bugs.php.net/fix.php?id=41154&r=notenoughinfo
Submitted twice:              http://bugs.php.net/fix.php?id=41154&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=41154&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=41154&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=41154&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=41154&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=41154&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=41154&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=41154&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=41154&r=mysqlcfg


Thread (2 messages)

« previous php.bugs (#111759) next »