1

I tried to write my own fib function that works for large numbers (over 50) and I had no luck. First I tried the obvious solution but that overflows way to quicly. my next solution was this

    $fun fib(a:int, b:int, index:int) = if(index = 1) then
    $                                      (a+b)
    $                                   else
    $                                       fib(b, (a+b), index - 1);

Unfortunatly this also overflows.

2 Answers 2

4

You need to take a look at the IntInf module, which provides access to arbitrary precision integers.

You can convert from Int.int to IntInf.int using IntInf.fromInt.

Note, for any operations you do on them, you have to use IntInf.<operation> instead of the Int counterpart. This includes things like addition and the likes.

Sign up to request clarification or add additional context in comments.

1 Comment

so replace "int" with IntInf?
0

Note that in Poly/ML, both structure Int and IntInf offer unbounded (big) integers by default. Since the implementation uses the GNU MP library at the bottom if it, and small machine integers in the range where this is still possible, it is also quite fast.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.