Dave Korn wrote:
On 16 January 2007 18:23, Robert Dewar wrote:
Gabriel Paubert wrote:
\
No, because the instruction has actually two result values:
- the remainder, which you could safely set to zero (not 1!)
- the quotient, which is affected by the overflow and there may be
compiler and languages that rely on the exception being generated.
But the division is undefined, programs have no right to
rely on an exception being generated.
It really depends whether you think of the % operator as being an atomic
mathematical operation, or a compound function involving real division and
multiplication and subtraction. I think the wording of the standard says only
that the inequality "(a/b)*b + a%b == a" does not hold when (a/b) cannot be
represented, but does not deny the modulo operator the option of just
returning the correct result, which is representable.
I think you missed my point
For sure a/b is undefined, so the trap routine does not have to worry
about the case where the trap comes from a/b, it only has to worry
about the case where the remainder is wanted, so setting the remainder
is indeed safe.
cheers,
DaveK