Page 3 of 5
Re: Routines for very large numbers.
Posted: Tue Sep 01, 2015 5:30 pm
by dunbarx
Richard.
Of course. I only placed it in its own thread for increased visibility.
Now that MaxV has chimed in, perhaps we can put this whole 64-bit limitation to rest. Finally.
Craig
Re: Routines for very large numbers.
Posted: Tue Sep 01, 2015 5:35 pm
by FourthWorld
dunbarx wrote:Richard.
Of course. I only placed it in its own thread for increased visibility.
Thanks - threads merged.
The taxonomy of the forums is a bit unwieldy, so I can appreciate the desire to move this thread to another location. Which section do you think might be more useful for others who might look for such things?
Re: Routines for very large numbers.
Posted: Tue Sep 01, 2015 7:07 pm
by hpsh
has to say thanks for the code

and i am really sorry for being complete useless here
was abel to make a code that could multiply some big numbers, but of some reason, it fail at 1010101*1010101.
Re: Routines for very large numbers.
Posted: Tue Sep 01, 2015 10:31 pm
by dunbarx
Hi.
LC can do "99999999" * "99999999". That is two large eight digit numbers. But as soon as you go into the ninth digit of even one of those, the native limit kicks in, and you get errors in the lowest digits in the product.
So your routine with two seven-digit numbers has something awry.
Craig
Re: Routines for very large numbers.
Posted: Wed Sep 02, 2015 3:03 am
by golive
@MaxV
Thanks for your routines. They work well.
Presumably the native behavior will be faster. So I guess one would want to test the numbers to see when the native behavior will be OK to use.
How do you envisage using these in practice?
Re: Routines for very large numbers.
Posted: Wed Sep 02, 2015 3:24 am
by dunbarx
Both MaxV's routines and mine work by breaking long numeric strings into shorter ones and then reassembling with just a few very small calculations. It isn't a matter of crunching large numbers. In either case, any process of any reasonable length would be nearly instantaneous.
The beneift of being able to use integers of any length may crop up here and there. As I posted earlier, within native limits, you cannot locate yourself in the observable universe closer than a few million miles. This now can be refined as desired; one only needs 40 or so digits to be able to locate oneself in that universe to within the diameter of a proton.
Craig
Re: Routines for very large numbers.
Posted: Wed Sep 02, 2015 9:15 am
by MaxV
golive wrote:@MaxV
How do you envisage using these in practice?
I'm an engineer, and form year 2000 I encounters problems with pc calculations.
The problem it's huge, but it's invisible to normal men.
For example a 16 bit processor limit is: 65'536. So you start to have some troubles with numbers bigger of 65'536. Many math libraries use the native processor features to be quick, but it's a mess with big numbers. You have to check always what is the biggest number you'll get in your calculations and to choose always the correct library, test it and test it, again and again.
Most of people approximate, without realizing it; but sometimes happens that those calculation are completely wrong.
It happens most with formulas containing exponentials and square roots, when numbers become extremely big or smallers.
Re: longAdd and longMult
Posted: Thu Sep 03, 2015 1:17 am
by golive
dunbarx wrote:
Both work for me.
Craig
um... doesnt work for me. LC7.06 commercial.
Re: Routines for very large numbers.
Posted: Thu Sep 03, 2015 4:04 am
by dunbarx
I tried the routines again, to make sure there were no typos. They work. Are you sure about typos on your end? I cannot imagine that v 6.7, where I am, is different from v. 7. Please check, though I am sure the problem is trivial. But if not, the problem is profound, and must be pounced upon.
Craig
Re: longAdd and longMult
Posted: Thu Sep 03, 2015 9:14 am
by MaxV
golive wrote:dunbarx wrote:
Both work for me.
Craig
um... doesnt work for me. LC7.06 commercial.
Did you try mine functions? They should work
(bigAdd, bigSub, bigMultiply, BigDivide, bigGreater)
Re: longAdd and longMult
Posted: Fri Sep 04, 2015 1:19 am
by golive
MaxV wrote:
Did you try mine functions? They should work (bigAdd, bigSub, bigMultiply, BigDivide, bigGreater)
@MaxV
Yes yours work nicely, thanks.
Re: Routines for very large numbers.
Posted: Fri Sep 04, 2015 1:27 am
by golive
dunbarx wrote:I tried the routines again, to make sure there were no typos. They work. Are you sure about typos on your end? I cannot imagine that v 6.7, where I am, is different from v. 7. Please check, though I am sure the problem is trivial. But if not, the problem is profound, and must be pounced upon.
Craig
Hi Craig
FYI I supplied my stack above so you should see what I see.
Not a biggie, as we now have MaxV's solution as well.
Re: Routines for very large numbers.
Posted: Fri Sep 04, 2015 4:00 am
by dunbarx
Hi.
The stack "bigNumber" was corrupted when I tried to open it. Sorry...
Just a thought. The "longMult" handler requires both the "addZero" and "longAdd" handlers as well. You did include those, right?
Craig
Re: Routines for very large numbers.
Posted: Sat Sep 05, 2015 5:46 am
by golive
dunbarx wrote:Hi.
The stack "bigNumber" was corrupted when I tried to open it. Sorry...
Just a thought. The "longMult" handler requires both the "addZero" and "longAdd" handlers as well. You did include those, right?
Craig
Yes they are included. BTW I downloaded the stack again and its fine here
I notice in variables (my picture above) arg1 has a space in it for:
put longMult(123456789,10) into tNum
But not for:
put longMult(12345678,10) into tNum
Code: Select all
on mouseUp
put longMult(123456789,10) into tNum
answer tNum
end mouseUp
--Requires the "addZero" and "longAdd" functions below
function longMult arg1,arg2
put the number of chars of arg1 into index1
put the number of chars of arg2 into index2
if index1 > 8 then
repeat with y = index1 down to 1 step -8
put space after char y of arg1
if the length of word 1 of arg1 <= 8 then exit repeat
end repeat
end if
if index2 > 8 then
repeat with y = index2 down to 1 step -8
put space after char y of arg2
if the length of word 1 of arg2 <= 8 then exit repeat
end repeat
end if
put the number of words of arg1 into arg1WordCount
put the number of words of arg2 into arg2WordCount
repeat with y = 1 to arg1WordCount
repeat with u = 1 to arg2WordCount
get ((arg1WordCount - y) * 8) + ((arg2WordCount - u) * 8)
put word y of arg1 * word u of arg2 & addZero((it)) & return after temp
end repeat
end repeat
repeat with y = 1 to the number of lines of temp - 1
put longAdd(line y of temp,line y + 1 of temp) into line y + 1 of temp
end repeat
return the last line of temp
end longMult
function addZero var
repeat var
put 0 after zeros
end repeat
return zeros
end addZero
Re: Routines for very large numbers.
Posted: Sun Sep 06, 2015 5:12 pm
by istech
I have been testing the routines over the last couple days and all but one appear to work as expected. The function in question is "BigDivide"
Can someone confirm that if you do.
put bigDivide(99999999,10) into t
answer t
LC stops responding or crashes. This does not happen on every calculation only on some trying to narrow it down.