#30330 [Opn->Bgs]: fmod() does not return the correct value.

From: Date: Tue, 05 Oct 2004 18:40:07 +0000
Subject: #30330 [Opn->Bgs]: fmod() does not return the correct value.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-67152@lists.php.net to get a copy of this message
ID: 30330 Updated by: derick@php.net Reported By: dbauleo at terra dot com dot br -Status: Open +Status: Bogus Bug Type: Math related Operating System: Windows 2000 PHP Version: 4.3.9 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. Thank you for your interest in PHP. . Previous Comments: ------------------------------------------------------------------------ [2004-10-05 19:46:53] dbauleo at terra dot com dot br Description: ------------ I used the fmod() function with float numbers, and it was an exact division, so it was supposed to return 0, instead of it, the Y value was returned. Reproduce code: --------------- <?php echo fmod(396456.06, 56636.58); ?> Expected result: ---------------- fmod(396456.06, 56636.58) = 0 Actual result: -------------- fmod(396456.06, 56636.58) = 56636.58 function f_mod($x,$y) { $i = floor($x / $y); $a = $x - $i * $y; return $a; } f_mod(396456.06, 56636.58) = 0 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30330&edit=1

« previous php.bugs (#67152) next »