F# 언어에서 int 타입과 bigint 타입을 상호변환 하는 것은 의외로 쉽다.


명령 프롬프트> fsi

Microsoft (R) F# 2.0 Interactive build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;
> let a = 100I;;
val a : System.Numerics.BigInteger = 100I

> let b = int a;;
val b : int = 100

> let c = bigint b;;
val c : System.Numerics.BigInteger = 100I
> b**5;;
  b**5;;
  ^
stdin(13,1): error FS0001: The type 'int' does not support any operators named '
Pow'

> a**5;;
val it : System.Numerics.BigInteger = 10000000000I

> c**5;;
val it : System.Numerics.BigInteger = 10000000000I

> a**5 = c**5;;
val it : bool = true

let k = int "320";;
val k : int = 320

> let m = bigint "320";;

  let m = bigint "320";;
  --------^^^^^^^^^^^^

stdin(19,9): error FS0041: No overloads match for method 'BigInteger'. The avail
able overloads are shown below (or in the Error List window).
Possible overload: 'System.Numerics.BigInteger()'.
Possible overload: 'new : x:int -> System.Numerics.BigInteger'.
Possible overload: 'new : x:int64 -> System.Numerics.BigInteger'.
Type constraint mismatch. The type
    string
is not compatible with type
    int
The type 'string' is not compatible with the type 'int'
Type constraint mismatch. The type
    string
is not compatible with type
    int64
The type 'string' is not compatible with the type 'int64'

> let m = new System.Numerics.BigInteger("320");;

  let m = new System.Numerics.BigInteger("320");;
  --------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

stdin(22,9): error FS0041: No overloads match for method 'BigInteger'. The avail
able overloads are shown below (or in the Error List window).
Possible overload: 'System.Numerics.BigInteger()'.
Possible overload: 'new : x:int -> System.Numerics.BigInteger'.
Possible overload: 'new : x:int64 -> System.Numerics.BigInteger'.
Type constraint mismatch. The type
    string
is not compatible with type
    int
The type 'string' is not compatible with the type 'int'
Type constraint mismatch. The type
    string
is not compatible with type
    int64
The type 'string' is not compatible with the type 'int64'

> let m = "320" |> System.Numerics.BigInteger.Parse;;
val m : System.Numerics.BigInteger = 320I


크리에이티브 커먼즈 라이선스
Creative Commons License

 

Posted by Scripter
,