What happens when pic divides a number by 0?
( I could'n find any thread about that.. )
Thanks.
Printable View
What happens when pic divides a number by 0?
( I could'n find any thread about that.. )
Thanks.
> 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.If the result is being returned to a Word variable, the result will be 65535.Code:A VAR BYTE
B VAR BYTE
C VAR BYTE
A = 100
B = 0
C = A / B
LCDOUT dec C
; Displays 255
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 ...Code:A VAR BYTE
B VAR BYTE
C VAR WORD
A = 100
B = 0
C = A / B
LCDOUT dec C
; Displays 65535
For word variables, the result will always be 65535Code:A VAR BYTE
B VAR BYTE
A = 100
B = 0
LCDOUT dec (A / B)
; displays 65535, even though the variables are Byte sized.
And finally, if the zero is in a constant expression, the compiler will flag an errorHTH,Code:LCDOUT $FE,$C0, dec 100/0
; Compiler error: Divide by zero while constant folding.
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.
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>