roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.47k stars 315 forks source link

bug: repl in wasm cant take calculation correctly #5102

Open taorye opened 1 year ago

taorye commented 1 year ago

When I try the online repl, I just want to test if it support big number. So I typed these 10^100 and found a big error.

You can see screenshot below and take a try on yourself.

So from 10^70 until 10^308(included) will get error result. 10^309 and its succeed will get inf, can it be calculated in the future?

Screenshot_20230308_120051

Anton-4 commented 1 year ago

The issue with the wrong numbers (not inf) does not occur in the native repl so perhaps something is wrong with how 64-bit floats are represented @brian-carroll? This could also be unavoidable because wasm uses 32 bits, but I'm not sure.

@taorye may I ask for what application you require numbers exceeding 10^308?

brian-carroll commented 1 year ago

I don't think that's the right root cause.

Wasm has both 32 bit and 64 bit number types. It's just that pointers are 32 bit so it doesn't support 64 bit address spaces (>4GB) . It supports 64 bit numbers just fine if they're not addresses.

brian-carroll commented 1 year ago

So it's not a fundamental limitation of Wasm but a bug that we can presumably fix.

As for arbitrarily large numbers: we are trying to be a high performance language so we will probably never do that by default. But I imagine it could be implemented in a library some day.

Out of curiosity, what exactly are you using this kind of number for? I think the number of atoms in the universe is quite a bit smaller than this!

brian-carroll commented 1 year ago

So it's not a fundamental limitation of Wasm but a bug that we can presumably fix.

As for arbitrarily large numbers: we are trying to be a high performance language so we will probably never do that by default. But I imagine it could be implemented in a library some day.

Out of curiosity, what exactly are you using this kind of number for? The number of atoms in the universe is quite a bit smaller than this!

We do have a 128 bit number type but it's not well supported in Wasm yet.