r/purescript • • Jun 27 '18

Big Int Problem

Hello,

I'm new to purescript and trying to study by solving eulers project exercises. and with 3rd had a problem:

Integer value 600851475143 is out of range for the JavaScript backend. Acceptable values fall within the range -2147483648 to 2147483647 (inclusive).

Maybe someone can help me with that,

Thanks :)

3 Upvotes

10 comments sorted by

View all comments

Show parent comment

3

u/[deleted] Jun 27 '18

Ahh, that makes sense. That literal you're trying to pass to solve is a regular old Int, which doesn't support values that high. If you're using purescript-bigints then solve needs to take a BigInt, and you'll have to use functions like fromString to construct that argument. For example:

> map solve (fromString "600851475143")

2

u/ulius Jun 27 '18

Wow Thank you very much!!! ;) You are the hero of today!!!

Rewrite code:

https://pastebin.com/wLLxYq4X

And then

> solve <$> (fromString "600851475143")

It works! But as always i dont read everything so had problem because overlooked that BigInts need to have big-integers so fixed it with

npm i big-integers

like written in documentation of BigInt. Thank you!