Log In  

Cart #big_integer-0 | 2021-12-03 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

@zep has added the ability to have long-integer access in numbers in these last few releases of Pico-8. While I would've preferred it to be a string of any length with any number of decimal places, this is the next best thing.

In this code I have written 4-functions to ease the use of this new 32-bit format.

They are:

stringadd()
stringsub()
stringmul()
stringdiv()

They are as simple to use as having the following code for multiplication:

a="32845"
b="40211"
print(stringmul(a,b))

The results will be:
34829090

Addition is easy too:

a="12345678"
b="87654321"
print(stringadd(a,b))

The results will be 8 9's.
99999999

Negative numbers also work in this example of integer division:

a="758632"
b="-2"
print(stringdiv(a,b))

The results will be:
-379316

Run the program above to see further instructions and usage - and press (X) to go to the calculator and see how effectively it works in all 4 operands of add, subtract, multiply, and divide.

Press (O) in the calculator to save off your current calculation to the clipboard.

If you only want to add and subtract numbers up to and including 64-digits, you might be interested in my earlier outing on number crunching found HERE:

https://www.lexaloffle.com/bbs/?tid=35715

Hope This Helps !

On a side note what I'm really hoping is ZEP in the future will make a function so you can do instant complex calculations like:

valu=calculate("7.238/(4123747.98685*-89.34)^sin("..lva..")*1.3867",xx,yy)

Where xx is the number of digits to work with and yy is the number of decimal places to work with. LVA also being a normal floating point variable or string variable, both would be accepted. And it could only do calculations, no other function so it's safe to use.

Anyways, if you have any questions or comments about usage and/or would like to write improvements to my code above - I'm always welcome to learn new things, feel free to address them below.

P#101378 2021-12-03 22:36 ( Edited 2021-12-03 23:39)

Hello, @benstopics !

I'm glad my functions could assist you.

https://www.lexaloffle.com/bbs/?tid=50561
https://github.com/benstopics/cca-pico8/blob/main/ADVENT.p8

I'm actually looking forward to the day where you can do something like:

extcmd("longinteger")

Which would then force all numeric variables for that particular cart to be long integer of -2147483648 to 2147483647. Use 4-bytes per variable if needed.

A parser like a=calcsum("(1+2)*3/4") would also be nice.

P#122106 2022-12-09 17:30

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 11:14:27 | 0.039s | Q:19