Reputation: 31
Consider:
9223372034707292159. 1 um/mod
For example, it raises a division-by-zero error on my machine. Why? The divisor is 1 (not 0!) and 9223372034707292159 fits within an unsigned double.
The same goes for fm/mod and sm/rem.
I'm using Gforth, but these are core Forth words.
Upvotes: 2
Views: 147
Reputation: 8554
See the specification for UM/MOD ( ud u1 -- u2 u3 )
:
An ambiguous condition exists if u1 is zero or if the quotient lies outside the range of a single-cell unsigned integer.
If you use a Forth system having a cell size of 32 bits, then in the given case the quotient lies outside the rage of a single-cell unsigned integer, and then it's an ambiguous condition and the behavior of a system is not specified by the standard.
Certainly, a better error message would be "integer overflow" than "division by zero" in this case.
[update] As it later appeared, in Gforth "the -fast engine does make some compromises speed vs. accuracy of error messages".
Upvotes: 4