F # int64 for int

How to convert Int64 type to Int32 type in F # without using Microsoft.FSharp.Compatibility.Int32.of_int64 ?

I do this because interactivity does not work when I try:

 open Microsoft.FSharp.Compatibility 

When adding FSharp.PowerPack as a reference, it says:

error FS0039: Compatibility namespace not defined.

Edit: Does anyone have an answer to the question? Suggestions about int types are useful and informative, but I have the same problem opening up the powerpack namespace in F # interactive.

+6
type-conversion f #
source share
3 answers

F # 1.9.6 has a type conversion function, so you can do this:

 let num = 1000 let num64 = int64(num) 
+15
source share

Please note that with this type of conversion, when you reduce the size of the value, the most significant bytes are discarded, so your data may be truncated:

 > let bignum = 4294967297L;; val bignum : int64 > let myint = int32(bignum);; val myint : int32 > myint;; val it : int32 = 1 
+10
source share

Note that the functions for converting to each integer type have the same names as the types themselves and are defined in the library specification (see below). (With the release of CTP (1.9.6.2), most of the library and namespace has changed a bit compared to previous versions, but it is likely to be more β€œstable” as it moves forward.)

http://research.microsoft.com/fsharp/manual/FSharp.Core/Microsoft.FSharp.Core.Operators.html

+1
source share

All Articles