Bug #79338 [Nab]: fmod() not calculating properly

From: Date: Tue, 03 Mar 2020 11:38:55 +0000
Subject: Bug #79338 [Nab]: fmod() not calculating properly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225867@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79338&edit=1 ID: 79338 Updated by: cmb@php.net Reported by: ziggi at ziggi dot pl Summary: fmod() not calculating properly Status: Not a bug Type: Bug Package: *Math Functions Operating System: Windows PHP Version: 7.4.3 Block user comment: N Private report: N New Comment: Also note: <?php $num = 75.6; $denom = 25.2; $res = fmod($num, $denom); var_dump($res === $denom); // bool(false) ?> Further reading: <http://www.floating-point-gui.de/> Previous Comments: ------------------------------------------------------------------------ [2020-03-03 11:35:11] nikic@php.net > cat test.c #include <math.h> #include <stdio.h> int main() { printf("%f\n", fmod(75.6, 25.2)); return 0; } > gcc test.c -lm > ./a.out 25.200000 ------------------------------------------------------------------------ [2020-03-03 11:20:41] ziggi at ziggi dot pl Description: ------------ --- From manual page: https://php.net/function.fmod --- I would say - simple answer provided by PHP team: "The value that you expect (0) is obtained using float precision. (In C) PHP uses double, and with this type fmod() returns 1.3." I completely pointless. This is not math! This is plain bullshit!!! Perl, MySQL, Python... you name it, all have no problems!!! Test script: --------------- echo fmod(75.6, 25.2); Expected result: ---------------- 0 Actual result: -------------- 25.2 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79338&edit=1

« previous php.bugs (#225867) next »