coding around 32-bit limit
courtens
Posts: 101
Stupid question on my part ...-- but is there a way to code around the 32-bit limit?
I am dealing with numbers that are just within the 2,147,483,647 and -2,147,483,647 range; however, I would like the be able do divide and multiply more accurate results. I guess I could store a number in a sting and start cutting it up in parts, do the math and add them back together... any suggestions?
I am dealing with numbers that are just within the 2,147,483,647 and -2,147,483,647 range; however, I would like the be able do divide and multiply more accurate results. I guess I could store a number in a sting and start cutting it up in parts, do the math and add them back together... any suggestions?
Comments
This is of course possible, but it will be much much slower because you have to deal with each digit separately. Any CPU is best in calculating with its native datatypes. But for 64bit (2 longs) calculations the same math-rules apply as for the calculation of 2 digit decimal numbers. You need some code to handle the overflow from least significant long to most significant long.
So, in other words: Of course you can teach a propeller how to calculate with 64 bit numbers, or 128 bit numbers, or floats or big decimal ....
I know that Phil wrote some code in SPIN to do large arithmetic, have a look in the math section of OBEX.
If PASM is "unsigned by default" then what are the abs, absneg, neg, negc, negnc, negz, negnz, mins, maxs, addabs, adds, addabs, addsx, subabs, subs, subsx, sumc, sumnc, sumz, sumnz, sar, cmps and cmpsx operations for? There are more signed instructions than unsigned AFAICT.
http://obex.parallax.com/objects/90/
http://obex.parallax.com/objects/194/
http://obex.parallax.com/objects/689/
http://obex.parallax.com/objects/501/
http://obex.parallax.com/objects/202/
http://obex.parallax.com/objects/415/
If it is strictly for doing integer math writing a PASM program for add/subtract/multiply/divide would not be that difficult provided you limited it to 32bit*32bit and 64bit/32bit