I recently started looking into F# and I must say that it is highly useful when applying to Mathematical problems. I had this Euler Problem to solve which wanted me to get the value of 2^1000.

Now if i try the same in C#,I would end of up having a overflow or truncated value as C# doesn't contain any data type that can hold such a big number. However, F# supports a datatype BigInt which can hold such large values and one line of code is all that you need to write a function to calculate it.

let rec Power (x:bigint) (y:bigint) = if y=of_int 1 then x else x* Power x (y-(1|> of_int))

The above code exemplifies why F# provides more flexibility and ease when solving mathematical problems.

Manoj ++, A Global Citizen in its making…!

10 months ago