- With OCaml 4.07.0+rc1 the value ‘max_float’ can be obtained with:
Waouw! Other possibilities?
In the OCaml 4.07 manual:
# let pi = 4.0 *. atan 1.0;;
Would not it be appropriate to use the new pre-defined ‘pi’ constant?
#let pi = Float.pi ;;
#let pi = Stdlib.Float.pi ;; (* funky *)
#let pi = Stdlib__float.pi ;; (* funkier *)
Float.pi that early in the manual is problematic because modules are only introduced one chapter later. Replacing π with
e might be a good idea to avoid giving the impression that π is not defined in the standard library.
There are plenty of ways to get pi too:
let pi = 2.0 *. asin 1.0;;
let pi = 2.0 *. acos 0.0;;
let pi = 4.0 *. atan 1.0;;
let pi = 2.0 *. Complex.(arg i);;
let pi = 2.0 *. Complex.((log i).im);;
But, could not ‘e’ also be defined in Float?
e might be an option; but I think that it is far less straigthforward than π.
Contrarily to π,
e is really easy to access with
e is rarely used as an isolated constant by itelf. The closest example than I can think of right now is Stirling formula n! ~
√(2πn) (n/e) ^ (-n) but this can also be written as
√(2πn) exp ( n log n - n). To the point that I have personally used the Euler-Mascheroni γ more often than
e (as an isolated constant).
Indeed, Euler y (or √π, or √2π …) are much more common.
let euler = 0x0.93C467E37DB0C7A4D1BE3F810152CB
let sqrt_pi = 0x1.C5BF891B4EF6AA79C3B0520D5DB938
let sqrt_2pi = 0x2.81B263FEC4E0B2CAF9483F5CE459DC