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
'프로그래밍 > F#' 카테고리의 다른 글
F# 윈도우 애플리케이션에서 마우스 이벤트 감지하기 (0) | 2010.07.23 |
---|---|
30000! 빨리 계산하기 with F# (0) | 2010.07.20 |
Pollard's rho method 소개: 정수의 인수분해(factorizing integers) with F# (0) | 2010.07.17 |
스트링 리스트에서 스트링 찾기(find) with F# (0) | 2010.07.16 |
스트링 배열 정렬(sorting)하기 with F# (0) | 2010.07.16 |