|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[1999-04-20 15:37 UTC] andi
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Jan 15 22:00:01 2026 UTC |
Sample code: $number = 116503231466; print $number / 1000; print $number % 1000; The first print statement will print: 1150321.466 The second print statement will print: -648 instead of the expected 466. Looking at the code in operators.c, div_function calls convert_string_to_number() which promotes $number to double because strtol() returns ERANGE. Then div_function then performs a floating point divide. mod_function, however calls convert_to_long, which calls convert_to_long_base(), which ignores the ERANGE error, returning LONG_MIN on Linux. I think mod_function() should be using convert_string_to_number(), and case out the code depending on the data type of the numbers. I don't know what else uses convert_to_long() and/or convert_to_long_base(), so I don't know if these functions need to be returning a range error, though silently returning LONG_MIN seems dangerous. I'm happy to take a shot at rewriting mod_function() if that would be useful. Thanks, -Cam