|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-03-03 11:20 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 20:00:01 2025 UTC |
> 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.200000As of today this has not yet been resolved, sadly for($i = 1; $i <= 10; $i++) { $dividend = round($i * 3.2, 2); echo "fmod($dividend, 3.2) > " . fmod($dividend, 3.2)."\n"; } Output: fmod(3.2, 3.2) > 0 fmod(6.4, 3.2) > 0 fmod(9.6, 3.2) > 3.2 fmod(12.8, 3.2) > 0 fmod(16, 3.2) > 3.2 fmod(19.2, 3.2) > 3.2 fmod(22.4, 3.2) > 3.2 fmod(25.6, 3.2) > 0 fmod(28.8, 3.2) > 3.2 fmod(32, 3.2) > 3.2