Number Bug

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderator: Klaus

Andy01
Posts: 14
Joined: Wed Dec 22, 2021 3:26 am

Number Bug

Post by Andy01 » Sun Jan 02, 2022 6:25 am

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Number Bug

Post by jmburnod » Sun Jan 02, 2022 10:14 am

Hi Andy,
I get same results (LC 9.6.5)
Best regards
Jean-Marc
https://alternatic.ch

Andy01
Posts: 14
Joined: Wed Dec 22, 2021 3:26 am

Re: Number Bug

Post by Andy01 » Sun Jan 02, 2022 10:50 am

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 🙄

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Number Bug

Post by jmburnod » Sun Jan 02, 2022 11:06 am

Ok this is strange but we maybe forget something.
First time i work with a so large number
https://alternatic.ch

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Number Bug

Post by SparkOut » Sun Jan 02, 2022 11:22 am

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

Andy01
Posts: 14
Joined: Wed Dec 22, 2021 3:26 am

Re: Number Bug

Post by Andy01 » Sun Jan 02, 2022 12:18 pm

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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: Number Bug

Post by richmond62 » Sun Jan 02, 2022 1:05 pm

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:
-
SShot 2022-01-02 at 14.11.04.png
-
Mind you, I am rather fond of the Hex number EFFED0FF :D

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Number Bug

Post by SparkOut » Sun Jan 02, 2022 2:48 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Number Bug

Post by dunbarx » Sun Jan 02, 2022 4:08 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Number Bug

Post by FourthWorld » Sun Jan 02, 2022 7:57 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Number Bug

Post by dunbarx » Mon Jan 03, 2022 12:09 am

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: Number Bug

Post by richmond62 » Mon Jan 03, 2022 9:56 am

You cannot do arithmetic operations with more than about 17 decimal digits.
Then how did HyperCard manage that?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Number Bug

Post by dunbarx » Mon Jan 03, 2022 3:37 pm

Richmond.

I don't recall that it did. HC also was in thrall to internal limits. Should I recheck?

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10080
Joined: Fri Feb 19, 2010 10:17 am

Re: Number Bug

Post by richmond62 » Mon Jan 03, 2022 4:18 pm

Pictures rarely lie.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Number Bug

Post by dunbarx » Tue Jan 04, 2022 3:35 pm

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

Post Reply