Page 1 of 2
Number Bug
Posted: Sun Jan 02, 2022 6:25 am
by Andy01
Could someone please check this for me - It could be the LiveCode version I'm using
put (10000000000000000 + 1) = 10000000000000000 ? -- incorrect
put (10000000000000000 + 2) = 10000000000000002 -- correct
No wonder the numberFormat function doesn't work properly

There's heaps more
put 100000000000000000000000 * 1 = 99999999999999991611392 ? -- incorrect
Re: Number Bug
Posted: Sun Jan 02, 2022 10:14 am
by jmburnod
Hi Andy,
I get same results (LC 9.6.5)
Best regards
Jean-Marc
Re: Number Bug
Posted: Sun Jan 02, 2022 10:50 am
by Andy01
jmburnod wrote: ↑Sun Jan 02, 2022 10:14 am
Hi Andy,
I get same results (LC 9.6.5)
Best regards
Jean-Marc
Thanks Jean-Marc, wow it looks like the LiveCode programmers need to go back to the drawing board and also learn math at the same time

Their engine is running on 3 cylinders

Re: Number Bug
Posted: Sun Jan 02, 2022 11:06 am
by jmburnod
Ok this is strange but we maybe forget something.
First time i work with a so large number
Re: Number Bug
Posted: Sun Jan 02, 2022 11:22 am
by SparkOut
There are definitely limits in the way computers handle floating point integers with high numbers of digits. This cropped up a while back, and there was some discussion here about it. I believe it is the same implementation in LiveCode as many other high level languages, and is a factor of hooking into the underlying systems, rather than a shortcoming of the LiveCode programmers. There is a big number maths library coded by Geoff Canyon
viewtopic.php?f=9&t=31793
Re: Number Bug
Posted: Sun Jan 02, 2022 12:18 pm
by Andy01
Maybe you guys are right and I'm wrong. But I don't see what the problem is because it should only be a memory problem not a math problem. When you add two numbers together all your doing is just adding units and then carrying over if needed.
Re: Number Bug
Posted: Sun Jan 02, 2022 1:05 pm
by richmond62
I had a go with those examples in LC 9.6.3 on MacOS 12.2 and
the results were exactly as per the OP.
I cannot get over-excited about that as I rarely count beyond 1114109 ( Hex 10FFFD) as that's
about as far as I have to go with Unicode fonts.
Oddly enough:
HyperCard got the first one right:
-
-
Mind you, I am rather fond of the Hex number EFFED0FF

Re: Number Bug
Posted: Sun Jan 02, 2022 2:48 pm
by SparkOut
The problem isn't to do with memory, it's that numbers are handled in the engine with a limitation on the number of bits so you lose precision with very large numbers.
https://quality.livecode.com/show_bug.cgi?id=15775
It is discussed in detail in this thread
viewtopic.php?f=7&t=25132
Re: Number Bug
Posted: Sun Jan 02, 2022 4:08 pm
by dunbarx
This is an inherent limitation, and has nothing to do with LC. You cannot do arithmetic operations with more than about 17 decimal digits. There is lot of discussion on the forum about this running for a decade.
I made a function, "longAdd", that added numbers of any length when I first started playing with LC. Never needed to, just because. But Hermann made functions for all four operations, and they are in the forum somewhere.
I miss him.
Craig
Re: Number Bug
Posted: Sun Jan 02, 2022 7:57 pm
by FourthWorld
While it's true that this is more of a computer science thing than a LiveCode thing, if we can account for it in script why can't that script be included in the engine?
A bug report becomes a feature request.
Re: Number Bug
Posted: Mon Jan 03, 2022 12:09 am
by dunbarx
All true, that 17 digits ought not to be anyone's limit, But know that such a value is the equivalent of measuring the diameter of our galaxy to a precision of about a mile, or the diameter of the solar system to a tenth of a millimeter.
Craig
Re: Number Bug
Posted: Mon Jan 03, 2022 9:56 am
by richmond62
You cannot do arithmetic operations with more than about 17 decimal digits.
Then how did
HyperCard manage that?
Re: Number Bug
Posted: Mon Jan 03, 2022 3:37 pm
by dunbarx
Richmond.
I don't recall that it did. HC also was in thrall to internal limits. Should I recheck?
Craig
Re: Number Bug
Posted: Mon Jan 03, 2022 4:18 pm
by richmond62
Pictures rarely lie.
Re: Number Bug
Posted: Tue Jan 04, 2022 3:35 pm
by dunbarx
Richmond.
You are the man when it comes to pictures.
But HC has the same limitation that LC does. Any calculation that runs past 16 or 17 digits fails. I recall that Apple used "SANE", a protocol that may or may not still be used today, and that is where the , limitation lies.
Craig