Integer overflow in factorial demo
Closed this issue · 2 comments
matprec commented
Currently, the value is stored as an i32. It can only hold values from ~±2*10^10, hence store factorials <= fact(12). Everything above will overflow. This can be observed by the naked eye when computing factorial 17 and 18, as they'll go negative :D
I see two options - use an i64 as datatype or restrict to factorials <=12 instead of 20.
badboy commented
Thanks for coming here.
Right now that's intentional (though I should add a paragraph explaining that).
In order to use i64 we need to do the string formatting on the Rust side as well (as JavaScript doesn't have i64 at all). I will hopefully get to it next week.