If I use the --checked+ option when compiling F# code, how do I use unchecked arithmetic for a specific operation.
Going the other way is easy, just use the FSharp.Core.Operators.Checked module; but I can't find the appropriate module to get the Unchecked versions of the operators.
The FSharp.Core.Operators.Unchecked module exists, but does not contain any of the basic arithmetic operations such as +, *, etc.
For example:
let a = FSharp.Core.uint32.MaxValue
let b = a+1u //Alter this to get it to work?
//b should be 0,
//rather than OverflowException being thrown in the previous line
b
The default unchecked operators are defined in Microsoft.FSharp.Core.Operators. If you need this in just a few places, you can refer to the operator explicitly via the full module name:
let a = FSharp.Core.uint32.MaxValue
let b = Microsoft.FSharp.Core.Operators.(+) a 1u
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With