Routines for very large numbers.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Routines for very large numbers.
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
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
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Routines for very large numbers.
Thanks - threads merged.dunbarx wrote:Richard.
Of course. I only placed it in its own thread for increased visibility.
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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Routines for very large numbers.
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.


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.
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
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.
@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?
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.
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
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
Last edited by dunbarx on Wed Sep 02, 2015 1:42 pm, edited 1 time in total.
Re: Routines for very large numbers.
I'm an engineer, and form year 2000 I encounters problems with pc calculations.golive wrote:@MaxV
How do you envisage using these in practice?
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.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: longAdd and longMult
um... doesnt work for me. LC7.06 commercial.dunbarx wrote:
Both work for me.
Craig
- Attachments
-
- BigNumber.zip
- (2.23 KiB) Downloaded 281 times
Re: Routines for very large numbers.
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
Craig
Re: longAdd and longMult
Did you try mine functions? They should work (bigAdd, bigSub, bigMultiply, BigDivide, bigGreater)golive wrote:um... doesnt work for me. LC7.06 commercial.dunbarx wrote:
Both work for me.
Craig
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: longAdd and longMult
@MaxVMaxV wrote: Did you try mine functions? They should work (bigAdd, bigSub, bigMultiply, BigDivide, bigGreater)
Yes yours work nicely, thanks.
Re: Routines for very large numbers.
Hi Craigdunbarx 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
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.
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
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.
Yes they are included. BTW I downloaded the stack again and its fine heredunbarx 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

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