Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Maths error
Author | Message | ||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
Hi gang, Can anyone tell me the limitations of the MOD operator? I have the following lines: 90 upper = addr \ 65536 100 lower = addr MOD 65536 The value of addr is 2.68442e+09 which is within MMBasic's number range, however, I get an error: "Number too large for an integer". It would seem that the What gives? What I'm trying to do is manipulate numbers to allow me to PEEK and POKE to screen RAM. The PEEK and POKE commands require that the address be split into HIWORD and LOWORD 32-bit numbers. regards, hmmm, the manual says that the maximum integer is 16777100, which is clearly not large enough to hold the screen address. Can anyone think of a workaround? Bob Devries Dalby, QLD, Australia |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3210 |
Both the integer divide and the MOD operator convert both arguments to an integer first. The value held by addr is outside of the 32 bit integer range (+/- 2147483647). This trick might help. The code for PEEK/POKE actually shifts hiword up by 16 bits then adds loword to get the address. So, to access video memory you could do: 10 FOR X = &HD250 to &H1378F 20 A=PEEK(&HA000,X) 30 NEXT X This works (or should work because I have not tested it) because &H1378F is within the range that a float can represent without loosing accuracy (the variable X is a float). Geoff Geoff Graham - http://geoffg.net |
||||
domwild Guru Joined: 16/12/2005 Location: AustraliaPosts: 873 |
Hi, From memory 65536 is 2**16, but in 16 bits the max. integer that can be stored is only 65535 or 2**16 - 1. A bit like the max integer using two digits is 99 and not 100 or 10**2. Am I right or are you wrong?? Taxation as a means of achieving prosperity is like a man standing inside a bucket trying to lift himself up. Winston Churchill |
||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
According to the manual, the maximum integer is 16777100 or $FFFF8C. Regards, Bob Devries Dalby, QLD, Australia |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3210 |
In the PIC32 an integer is 32 bits which is about 4 billion. The 16777100 mentioned by Bob is the maximum integer that you can store in a floating point number without loosing accuracy. In MMBasic you do not see an integer as everything is expressed as a floating point number. As the size of a number increases floating point will start to loose track of the least significant digit, this happens at about 16777100. Geoff Geoff Graham - http://geoffg.net |
||||
Print this page |