Tuesday, March 19, 2013

Checked module

(In learning from "Programming F# 3.0, 2nd Edition")

Operators.Checked Module (F#) (in Japanese)

F#'s Microsoft.FSharp.Core.Operators.Checked is to check which signed numbers are overflowed or not.
> let maxInt = System.Int32.MaxValue;;

val maxInt : int = 2147483647

> maxInt + 1;;
val it : int = -2147483648
> maxInt - 1;;
val it : int = 2147483646
> open Checked;;
> maxInt + 1;;
System.OverflowException: 算術演算の結果オーバーフローが発生しました。
   場所 <StartupCode$FSI_0008>.$FSI_0008.main@()
Stopped due to error

No comments:

Post a Comment