Submitted by jsalai49 on

Forums:

Chris,

did you ever have in mind to include arbitrary precision arithmetics in SB?

Of course, not in code, nor a genuine one (as in Liberty Basic), but linked to external gmp.lib. AFAIK, there are libraries for all platforms, including Android...

I understand it is a huge work behind it, but due to flexibility of string and array functions in SB, IMHO, it would be possible...

As I wrote above, only a thought

Cheers

figosdev replied on Permalink

## i wrote a "long addition"

i wrote a "long addition" program in qbasic that added two strings of considerable length-- how arbitrary is arbitrary?

MGA replied on Permalink

## Arbitrary long integers

Arbitrary long integers might be all that is needed with +-* operations. In JB, I just finished a fractions calculator that keeps maths in perfect precision for +-* and / operations and could calculate e constant to 50 decimal places with such tools. (JB has arbitrary long integer for +-*)

That reminds me, I wanted to see if there were a Taylor series for roots.

I have often thought about doing what figosdev claims to have done. I wonder if subtraction is not so very different than addition. You would need addition to do multiplication. I wonder about doing it just for integers. hmm...

"How arbitrary is arbitrary?"

Long as it takes? Well I know from e constant calculation, the factorials were getting quite ridiculous at 42, there's your answer, 42!

figosdev replied on Permalink

## a spoiler mark, what i did

a spoiler mark, what i did was loop (from right to left) through each string, convert each place to integer, and (one step at a time, just like by hand) do the steps you would do to add the long numbers on paper-- carry the 1 and everything.

i did it as an animation so that you could watch each step, including carry the one. but obviously for an everyday function youd want to take out the delay and the display on the screen, and just add the numbers.

as to whether subtraction is the same-- almost.

you know as well as i do, that subtraction involves borrowing instead.

addition is the easiest. im sure many of us are up to the task if we become interested enough. best of all, it can all be done in basic (though i would surely use fig.)

MGA replied on Permalink

## I have long addition and subtraction

't hurt the results though.Onto being fruitful... ;-))

figosdev replied on Permalink

## if youre wondering if im

if youre wondering if im really impressed-- yep.

MGA replied on Permalink

## Im too

;-)) 1 hour and 40 mins until this day is over, can I get mult done also?

figosdev replied on Permalink

## given the speed you got the

given the speed you got the others? i would say yes, if you arent ready to upload it already.

MGA replied on Permalink

## And multiply!

't bad but got hung up by not clearing a carry over when there wasn't one.figosdev replied on Permalink

## nice.

nice.

MGA replied on Permalink

## Working on division

Working on division, I have encountered crossroads for decisions.

To maintain perfect precision, I have left the Remainder part intact, so 13 / 12 = 1 R:1

or I could write it as 1_1/12

and 26/24 could be reduced to same 1_1/12, they can be reduced because I have both MOD and GCD working for string Math.

So one crossroad or decision point is which format is more satisfactory?

The other crossroad is when converting to decimal, you more often than not sacrifice perfect precision as 1/12 expressed in decimal form even to 100 places is infinitely less precise than 1_1/12.

Oh! writing this out here, I just discovered 1 R:1 is incomplete! R:1 what???? You need the 12, so 1_1/12 IS BETTER expression of 13 divided by 12, perfect and complete.

SO! the 4 main operations of arithmetic can be maintained, perfectly precise. Basically because any number you write down to operate on has to be finite.

figosdev replied on Permalink

## "r:1" and "1/12" are both

"r:1" and "1/12" are both correct. the /12 is implied as it is one of the two numbers given in the first place.

MGA replied on Permalink

## example

add 1 R:1 and 3 R:3 == ??? R:... lacks info

but

add 1_1/3 and 3_3/5 == 4_14/15 see? more info

The second form serves as a complete number and perfect compared to any decimal expansion.

figosdev replied on Permalink

## it depends on how it is

it depends on how it is called.

if you call your division routine with 1234567890987654321 / 5, then we all know r:1 means "and 1/5."

if you get two numbers from a file and divide the two, we only know what r:1 means if we open the file.

so youre right-- at least sometimes. and its probably best to put /5 after the 1.