Microsoft.FSharp.Math.BigInt.pow works fine but the compiler seems to be looking for Microsoft.FSharp.Math.BigInt.Pow (uppercase 'P').

1
2
3
4
> open Microsoft.FSharp.Math.BigInt;;
> pow 2I 1000I;;
val it : bigint
= 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376I

Regards,
Carl

By on 3/26/2008 1:46 PM ()

Here's one way to do this. First define a function,

1
2
3
4
let rec myPowerOf2 n =
match n with
| 0 -> 1I
| n -> 2I*myPowerOf2(n-1)

then:

1
2
3
4
5
6
7
8
9
10
11
12
> 
val myPowerOf2 : int -> bigint

> myPowerOf2 10;;

val it : bigint = 1024I

> myPowerOf2 1000;;

val it : bigint

= 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376I

I still think there should be an easier way to do this...

By on 3/25/2008 7:56 PM ()

I couldn't find the right incantation to augment BigInt with ( ** ), but if you know that you are only working with BigInt's, you can completely override ( ** ) as follows:

1
2
3
4
5
6
7
8
9
let rec BigPow (a:bigint) (p:bigint) :bigint =
  match p with
    | _ when (p = 0I) -> 1I
    | _ when (p >= 1I) -> a * (BigPow (a) (p - 1I))
    | _ -> failwith "Shouldn't Happen"

let ( ** ) : bigint -> bigint -> bigint = BigPow

2I ** 100I

== output ==>

1
> val it : bigint = 1267650600228229401496703205376

.

By on 3/25/2008 10:06 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper