View Full Version : Division by 0
sirvo
- 3rd August 2007, 20:55
What happens when pic divides a number by 0?
( I could'n find any thread about that.. )
Thanks.
Darrel Taylor
- 3rd August 2007, 22:43
> What happens when PBP divides a number by 0?
That depends on how you are using them.
If you have BYTE sized variables, and are returning the result to a byte sized variable, the result is 255.
A VAR BYTE
B VAR BYTE
C VAR BYTE
A = 100
B = 0
C = A / B
LCDOUT dec C
; Displays 255
If the result is being returned to a Word variable, the result will be 65535.
A VAR BYTE
B VAR BYTE
C VAR WORD
A = 100
B = 0
C = A / B
LCDOUT dec C
; Displays 65535
And if the division is done inside another formula or Statement like LCDOUT, the result is assumed to be word sized, and the result will be 65535 ...
A VAR BYTE
B VAR BYTE
A = 100
B = 0
LCDOUT dec (A / B)
; displays 65535, even though the variables are Byte sized.
For word variables, the result will always be 65535
And finally, if the zero is in a constant expression, the compiler will flag an error
LCDOUT $FE,$C0, dec 100/0
; Compiler error: Divide by zero while constant folding.
HTH,
sirvo
- 3rd August 2007, 23:18
Thanks again Darrel. There could not be a better explanation.
Another thing.. Man, these instant interrupts stuffs that you show us are pretty handy.. after using it I discover how usefull it is....
Regards.
Darrel Taylor
- 4th August 2007, 01:11
Thanks again Darrel. There could not be a better explanation.
Thanks Sylvio,
I'm sure Melanie could have at least made it more interesting. :)
And, I'm glad you like the Instant Interrupts!
I might be a little biased, but I don't think I could write a decent program without them anymore.
Keep the questions coming.
They're good one's.
<br>
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.