Discuss Scratch

Fallen_Programmer
Scratcher
2 posts

Scratch's Number Limitations with Large Numbers

I recently was experimenting with variable abbreviation, I did manage to create a working system until I ran into a problem…
So while I was testing it, I noticed that it wouldn't work with variables with lengths longer than 22 digits because anything longer than 22 digits gets set to 1e+21, 2e+21, 5e+23, etc. Does anyone know of a way to bypass this limit because otherwise the abbreviation for variables longer than 22 digits will be impossible because I made a system that relies on the first 3 or 4 letters of the variable but because of these limits it wont work for variables past 22 digits long. If there is none, let me know.

Last edited by Fallen_Programmer (March 22, 2023 20:19:36)

vladfein
Scratcher
100+ posts

Scratch's Number Limitations with Large Numbers

Could you please give an example of what are you trying to do with those 22-digit numbers?
You can process the as strings, for example.
Fallen_Programmer
Scratcher
2 posts

Scratch's Number Limitations with Large Numbers

I'm trying to compress large numbers like 1341234 into a shorter form like 1.34 Million but I can't find a way to do it with any numbers larger than 22 digits because they become compressed into numbers like 1e+21.
Spentine
Scratcher
1000+ posts

Scratch's Number Limitations with Large Numbers

Process the numbers as numbers, not strings.

If you want a number abbreviator just use this:

define format number(n)(float)
set[return v]to(join(letter<(n)<(0)>of(-))(join(([floor v]of((([abs v]of(n))/([10 ^ v]of((([floor v]of(([log v]of([abs v]of(n)))/(3)))*(3))+((3)*<(([abs v]of(n))/([10 ^ v]of(([floor v]of(([log v]of([abs v]of(n)))/(3)))*(3))))=(1000)>))))*([10 ^ v]of(float))))/([10 ^ v]of(float)))(join( )(item(((([floor v]of(([log v]of([abs v]of(n)))/(3)))*(3))+((3)*<(([abs v]of(n))/([10 ^ v]of([floor v]of((([log v]of([abs v]of(n)))/(3))*(3)))))=(1000)>))/(3))of[endings v]
Set the endings list to be K, M, B, T, etc.
The float specifies how many decimal places it will display.

Setting float to 3 and converting 293,243,924 will return 219.243 million. You can change it if you want.

Hope this helps!
vladfein
Scratcher
100+ posts

Scratch's Number Limitations with Large Numbers

Spentine wrote:

Process the numbers as numbers, not strings.

As @Fallen_Programmer said, you can't do math on numbers longer than 22 digits…
Spentine
Scratcher
1000+ posts

Scratch's Number Limitations with Large Numbers

vladfein wrote:

Spentine wrote:

Process the numbers as numbers, not strings.

As @Fallen_Programmer said, you can't do math on numbers longer than 22 digits…
You can. The only thing that breaks is string manipulation. Doing floor(log(n)) will effectively return the length, and dividing n by the number obtained from raising 10 to that power will return the number as x.xxxxx, which proves that computer mathematics on large numbers works properly.

Last edited by Spentine (March 22, 2023 20:41:54)

scratchy_robot
Scratcher
62 posts

Scratch's Number Limitations with Large Numbers

define find if (a) = (b) while bypassing the limit
set [a=b? v] to [false]
if <(length of (a)) = (length of (b))> then
set [c v] to [0]
repeat (length of (a))
change [c v] by [1]
if <not <(letter (c) of (a)) = (letter (c) of (b))>> then
stop [this script v]
end
end
else
stop [this script v]
end
set [a=b? v] to [true]
vladfein
Scratcher
100+ posts

Scratch's Number Limitations with Large Numbers

Spentine wrote:

You can. The only thing that breaks is string manipulation. Doing floor(log(n)) will effectively return the length, and dividing n by the number obtained from raising 10 to that power will return the number as x.xxxxx, which proves that computer mathematics on large numbers works properly.

Thank you!
TIL (Today I Learned)
10goto10
Scratcher
1000+ posts

Scratch's Number Limitations with Large Numbers

vladfein wrote:

As @Fallen_Programmer said, you can't do math on numbers longer than 22 digits…
I know this is outside of the specific issue here but there is a math problem.

Incrementing 9,007,199,254,740,992 by 1 doesn’t work. Yes, I know this is an outlier and unless you are making a clicker game it will never be a problem, but since you are experimenting with big whole numbers I just wanted to mention it.
Spentine
Scratcher
1000+ posts

Scratch's Number Limitations with Large Numbers

10goto10 wrote:

vladfein wrote:

As @Fallen_Programmer said, you can't do math on numbers longer than 22 digits…
I know this is outside of the specific issue here but there is a math problem.

Incrementing 9,007,199,254,740,992 by 1 doesn’t work. Yes, I know this is an outlier and unless you are making a clicker game it will never be a problem, but since you are experimenting with big whole numbers I just wanted to mention it.
The reason is because the mantissa (the xs in 1.xxxxx * 2^y) in computers isn’t large enough.

Javascript uses the IEEE 754 standard, which assigns one bit for the sign (positive or negative), 11 bits for the exponent, and the remaining 54 for the mantissa.

Last edited by Spentine (March 22, 2023 22:05:14)

mewtwocoder
Scratcher
7 posts

Scratch's Number Limitations with Large Numbers

I'm sorry for replying on something that's a couple months old, but I'm having a problem.

Long story short, I'm trying to multiply a random number 0 - 4294967295 by 1103515245. Every time I multiply ‘n’ (random number) by 1103515245, the output rounds up.

For example, the number 441888913 multiplied by 1103515245 gives 487631152091978700 in scratch, but 487631152091978685 in other calculators.

I'm working with hex numbers most of the time, I just need a way to accurately translate those numbers into decimal, so I can multiply them together. I tried the idea that Spentine gave, but It just wrote out the rounded number, 4.87631152091978700. Any ideas?

Last edited by mewtwocoder (June 10, 2023 07:06:14)

awesome-llama
Scratcher
1000+ posts

Scratch's Number Limitations with Large Numbers

mewtwocoder wrote:

I'm sorry for replying on something that's a couple months old, but I'm having a problem.

Long story short, I'm trying to multiply a random number 0 - 4294967295 by 1103515245. Every time I multiply ‘n’ (random number) by 1103515245, the output rounds up.

For example, the number 441888913 multiplied by 1103515245 gives 487631152091978700 in scratch, but 487631152091978685 in other calculators.

I'm working with hex numbers most of the time, I just need a way to accurately translate those numbers into decimal, so I can multiply them together. I tried the idea that Spentine gave, but It just wrote out the rounded number, 4.87631152091978700. Any ideas?
Floating point numbers have a variable precision and at the size you are dealing with, whole numbers can't be represented. You have to try something else.
mewtwocoder
Scratcher
7 posts

Scratch's Number Limitations with Large Numbers

Floating point numbers have a variable precision and at the size you are dealing with, whole numbers can't be represented. You have to try something else.

Alright, thanks for the clarification
gggamer24
Scratcher
26 posts

Scratch's Number Limitations with Large Numbers

Spentine wrote:

Process the numbers as numbers, not strings.

If you want a number abbreviator just use this:

define format number(n)(float)
set[return v]to(join(letter<(n)<(0)>of(-))(join(([floor v]of((([abs v]of(n))/([10 ^ v]of((([floor v]of(([log v]of([abs v]of(n)))/(3)))*(3))+((3)*<(([abs v]of(n))/([10 ^ v]of(([floor v]of(([log v]of([abs v]of(n)))/(3)))*(3))))=(1000)>))))*([10 ^ v]of(float))))/([10 ^ v]of(float)))(join( )(item(((([floor v]of(([log v]of([abs v]of(n)))/(3)))*(3))+((3)*<(([abs v]of(n))/([10 ^ v]of([floor v]of((([log v]of([abs v]of(n)))/(3))*(3)))))=(1000)>))/(3))of[endings v]
Set the endings list to be K, M, B, T, etc.
The float specifies how many decimal places it will display.

Setting float to 3 and converting 293,243,924 will return 219.243 million. You can change it if you want.

Hope this helps!
im having the same problem as @Fallen_Programmer and i have a few questions:
1: can the
format number (n)(float)
be put in a
forever

end
and still display fine? i have tried another script that tries to fix this problem but it can only be done once (a.k.a: not be put in a loop)
2. can it go up to Duotrigintillion (im making an incremental game and i want it to at least go to googol which is 10 times Duotrigintillion before switching to scientific notation)
3. can you put this in a project so i can see the whole thing?
if you could answer at least 1 of these questions that would be great.
thx for any and all help!

Powered by DjangoBB