Bug #53972 [Com]: Operator Type Casting Issue

From: Date: Wed, 09 Feb 2011 16:43:25 +0000
Subject: Bug #53972 [Com]: Operator Type Casting Issue
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-158657@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53972&edit=1 ID: 53972 Comment by: anon at anon dot anon Reported by: thipse_rahul at rediffmail dot com Summary: Operator Type Casting Issue Status: Bogus Type: Bug Package: *General Issues Operating System: Linux/Windows PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: PHP guys, will you please stop giving people broken links? Previous Comments: ------------------------------------------------------------------------ [2011-02-09 14:18:33] johannes@php.net Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is, read this: http://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. . ------------------------------------------------------------------------ [2011-02-09 13:56:31] thipse_rahul at rediffmail dot com Description: ------------ Following code snippet -- Case 1: $a = (int)((0.1+0.7) * 10); echo $a; // Result: 7 (Wrong) should give 8 Case 2: $a = (int)((0.1+0.6) * 10); echo $a; // Result: 7 Case 3: $a = (int)((0.1+0.8) * 10); echo $a; // Result: 9 Test script: --------------- $a = (int)((0.1+0.7) * 10); echo $a; Expected result: ---------------- 8 Actual result: -------------- 7 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53972&edit=1

« previous php.bugs (#158657) next »