Negative dividend: makes DivMod raise EDivByZero, makes mod return wrong value
Original Reporter info from Mantis: Michalis @michaliskambi
-
Reporter name: Michalis Kamburelis
Original Reporter info from Mantis: Michalis @michaliskambi
- Reporter name: Michalis Kamburelis
Description:
(Observed with released 2.4.0, tagging with "2.4.1" in mantis as there's no "2.4.0" choice yet.)
Submitting this as one bug, although I'm not sure --- maybe these are two not related bugs (one for Math.DivMod, one for the "mod" operator). Neither of these problems were observed with 2.2.4.
The program calculates "-9 div/mod 5" in two ways: 1. call "div" and "mod" operators separately, 2. call DivMod.
Running with 2.2.4 we get correct results from both approaches:
$ fpc -gl divmod.pas
$ ./divmod
-1 -4
-1 -4
Running with 2.4.0 we get:
$ fpc -gl divmod.pas
$ ./divmod
-1 2
An unhandled exception occurred at $080637FD :
EDivByZero : Division by zero<br/>
$080637FD
$0804812E main, line 10 of divmod.pas
So the "-9 mod 5" returns wrong value (2) and DivMod(-9, ...) raises EDivByZero exception.
Mantis conversion info:
- Mantis ID: 15453
- OS: Debian GNU/Linux
- OS Build: (testing)
- Platform: i386
- Version: 2.4.0
- Fixed in version: 2.4.2
- Fixed in revision: 15201 (#78e19bdd)
- Target version: 2.4.2