Shop OBEX P1 Docs P2 Docs Learn Events
coding around 32-bit limit — Parallax Forums

coding around 32-bit limit

courtenscourtens Posts: 101
edited 2012-03-14 17:30 in Propeller 1
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?

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2012-03-14 15:18
    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 ....
  • pedwardpedward Posts: 1,642
    edited 2012-03-14 15:23
    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.
  • courtenscourtens Posts: 101
    edited 2012-03-14 15:44
    Thanks for the suggestions -- I changed my mind and will stay away form this idea -- at least for now.
  • Mark_TMark_T Posts: 1,981
    edited 2012-03-14 16:49
    pedward wrote: »
    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.
  • kwinnkwinn Posts: 8,697
    edited 2012-03-14 17:30
    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
Sign In or Register to comment.