PDA

View Full Version : coding around 32-bit limit



courtens
03-14-2012, 09:53 PM
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?

MagIO2
03-14-2012, 10:18 PM
I wish you a lot of fun writing the code for calculations with strings ;o)

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 ....

pedward
03-14-2012, 10:23 PM
It's a bad suggestion, but PASM treats numbers as unsigned by default, you could write (or find) a handler that offloads to PASM.

I know that Phil wrote some code in SPIN to do large arithmetic, have a look in the math section of OBEX.

courtens
03-14-2012, 10:44 PM
Thanks for the suggestions -- I changed my mind and will stay away form this idea -- at least for now.

Mark_T
03-14-2012, 11:49 PM
It's a bad suggestion, but PASM treats numbers as unsigned by default, you could write (or find) a handler that offloads to PASM.

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.

kwinn
03-15-2012, 12:30 AM
Take a look at these objects to see if they do or can be modified to do what you want. There are more objects that might be useful in the OBEX.

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