Incorrect compilation of large integer multiplications

Have trouble while compiling large integer multiplications. Here’s an example

https://rescript-lang.org/try?code=DYUwLgBAxg9gTnEVIF4IFYAMmICoICMmATACx5FkBQVokAlgHawJJgERpbZ6Enn5KpGnQhMWiZMU4Ri2HoP68hQA

This yields the desired result in vanilla JS with the number type.

Integers are 32 bit and are not mapped to number types in JS. Use float values instead, if you are doing any crucial calculation stuff.

let correct = 500. *. 1024. *. 1024.

let incorrect1 = 5000. *. 1024. *. 1024.

let incorrect2 = 20000. *. 1024. *. 1024.

Playground Link

Related: Numbers overflow problem

2 Likes