PDA

View Full Version : word larger numbers



lutherblisset
- 16th January 2016, 10:13
I have to multiply a byte for the word fixed 10000, and then divide the result by the fixed word 312 (example 73x10000 / 312). How can i do this when the result of the multiplication exceeds the maximum content of a word?

richard
- 16th January 2016, 11:14
dummy_word_var = 73*10000
result_word_var= div32 312


[result=2339]

HenrikOlsson
- 16th January 2016, 11:36
Or perhaps

73 */ 8205

Result = 2339

Or, if precision isn't THAT critical, since 10000/312 = 32.0513 which is pretty close to 32:

73 << 5
Result = 2336

Where obviously the last one will be the smallest and fastes option
/Henrik.

lutherblisset
- 16th January 2016, 17:24
dummy_word_var = 73*10000
result_word_var= div32 312


but 73000 isnt' larger than a word?

mark_s
- 16th January 2016, 18:43
never mind

pedja089
- 16th January 2016, 19:52
PBP uses internal 32bit register for storing results(registers R1,R2,R3,R4 if I remember correctly). Maximum number that can be stored is 4294967295
Then DIV32 divide register with 312 in this example.

WOZZY-2010
- 18th January 2016, 03:11
Look into Alexander Avtanski's N-Bit Math which is mentioned in this old post
http://www.picbasic.co.uk/forum/showthread.php?t=12433