#43241 [Opn->Bgs]: Float Precision/Representation and Modulo

From: Date: Sun, 11 Nov 2007 15:08:24 +0000
Subject: #43241 [Opn->Bgs]: Float Precision/Representation and Modulo
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-119450@lists.php.net to get a copy of this message
ID: 43241 Updated by: derick@php.net Reported By: quake5 at gmx dot de -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: MacOS PHP Version: 5.2.5 New Comment: 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. . Previous Comments: ------------------------------------------------------------------------ [2007-11-11 10:49:03] felipe@php.net This is documented. See "Integer overflow" ( http://br.php.net/integer ) felipe@pena:~$ php -r 'var_dump(73.82 * 100);' float(7382) felipe@pena:~$ php -r 'var_dump(73.82 * 100 % 2);' int(1) felipe@pena:~$ php -r 'var_dump(round(73.82 * 100) % 2);' int(0) ------------------------------------------------------------------------ [2007-11-11 02:44:42] quake5 at gmx dot de Description: ------------ Float Precision/Representation and Modulo Reproduce code: --------------- <?php var_dump(73.82 * 100 % 2); ?> Expected result: ---------------- int(0) Actual result: -------------- int(1) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43241&edit=1

« previous php.bugs (#119450) next »