Jump to content
Excelsior Forums
R0bur

Why the integer division by negative divisors is prohibited?

Recommended Posts

Runtime error occures:

#RTS: unhandled exception #6: zero or negative divisor at line 6 of negdiv.mod

while executing negdiv.exe generated from the source code:

MODULE negdiv;
VAR a, b, c: INTEGER;
BEGIN
    a := 100;
    b := -10;
    c := a DIV b;
END negdiv.

Share this post


Link to post
Share on other sites

That's a question to the authors of the specification. Use / and REM instead of DIV and MOD if the divisor can be negative.

Share this post


Link to post
Share on other sites
1 minute ago, snowman said:

That's a question to the authors of the specification. Use / and REM instead of DIV and MOD if the divisor can be negative.

Ok, thank you!

I don't have Modula-2 specification on hand and [PIM] provides these samples:

15 DIV 4 = 3
-15 DIV 4 = -3
15 DIV (-4) = -3

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×