To the best of my knowledge GCBASIC, nor any other BASIC Dialect, has no overflow indication.
In GCBASIC, Long is normally used as a counter or as the product of two Word's.
If the arguments need to be Long as well then, as GCBASIC has no 64Bit (or Long Long) variable, it is up to the programmer to ensure that the range of values used will not cause an overflow.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
another way might be to take the high bytes of the input values, increment them if the low byte is <> 0, and then multiply those bytes. If the result is < 65536 then no overflow will occur in the full 16 x 16 bit multiplication. This will be faster than doing a 32 bit division.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is there a way to indicate when a multiplication of 2 variables causes a long variable to overflow?
For example:
Dim xx, yy, zz as long
xx = 70000
yy = 75000
zz = xx * yy ;should = 5,250,000,000 which is greater than 2^32.
How would I know zz overflowed?
To the best of my knowledge GCBASIC, nor any other BASIC Dialect, has no overflow indication.
In GCBASIC, Long is normally used as a counter or as the product of two Word's.
If the arguments need to be Long as well then, as GCBASIC has no 64Bit (or Long Long) variable, it is up to the programmer to ensure that the range of values used will not cause an overflow.
Thanks chris!
There may be a way, but, I had to write and test code to figure out what worked and what did not work.
I found that C, carry flag, did not represent an overflow.
Then, I wrote this... seems to work.
Please test.
Clever, it could be a bit memory intensive as it will need a minimum of 32 bytes plus working space but it should be fine for larger PIC's .
I thought the same... but, could be worth the clock cycles.... :-)
Wow! So simple and yet so clever. Thanks!
Let us all know if it works!!!
another way might be to take the high bytes of the input values, increment them if the low byte is <> 0, and then multiply those bytes. If the result is < 65536 then no overflow will occur in the full 16 x 16 bit multiplication. This will be faster than doing a 32 bit division.