math¶
In [ ]:
//// test
open testing
math¶
e¶
In [ ]:
inl e () =
exp 1f64
square¶
In [ ]:
inl square x =
x ** 2
In [ ]:
//// test
5f64
|> sqrt
|> square
|> _assert_approx_eq None 5
__assert_approx_eq / actual: 5.0 / expected: 5.0
In [ ]:
//// test
e () |> square
|> _assert_approx_eq None 7.3890560989306495
__assert_approx_eq / actual: 7.389056099 / expected: 7.389056099
In [ ]:
//// test
2 * 2 / 0.4f64 |> sqrt
|> _assert_approx_eq None 3.1622776601683795
__assert_approx_eq / actual: 3.16227766 / expected: 3.16227766
In [ ]:
//// test
2f64 / 3
|> _assert_approx_eq None 0.6666666666666666
__assert_approx_eq / actual: 0.6666666667 / expected: 0.6666666667
In [ ]:
//// test
2f64 |> log
|> _assert_approx_eq None 0.6931471805599453
__assert_approx_eq / actual: 0.6931471806 / expected: 0.6931471806
In [ ]:
//// test
pi
|> _assert_approx_eq None 3.141592653589793f64
__assert_approx_eq / actual: 3.141592654 / expected: 3.141592654
In [ ]:
//// test
pi |> cos
|> _assert_eq -1f64
__assert_eq / actual: -1.0 / expected: -1.0
In [ ]:
//// test
pi
|> cos
|> fun n => n / 2f64
|> _assert_approx_eq None -0.5
__assert_approx_eq / actual: -0.5 / expected: -0.5
In [ ]:
//// test
pi / 2 |> cos
|> _assert_approx_eq None 0.00000000000000006123233995736766f64
__assert_approx_eq / actual: 6.123233996e-17 / expected: 6.123233996e-17
fsharp¶
atan2¶
In [ ]:
inl atan2 (y : f64) (x : f64) : f64 =
$'System.Math.Atan2 (!y, !x)'
In [ ]:
//// test
0 |> atan2 1
|> _assert_eq 1.5707963267948966
__assert_eq / actual: 1.570796327 / expected: 1.570796327
floor¶
In [ ]:
inl floor forall t {float}. (n : t) : t =
n |> $'floor'
In [ ]:
//// test
0.6 |> floor
|> _assert_eq 0f64
__assert_eq / actual: 0.0 / expected: 0.0
ceil¶
In [ ]:
inl ceil forall t {float}. (n : t) : t =
n |> $'ceil'
In [ ]:
//// test
0.6 |> ceil
|> _assert_eq 1f64
__assert_eq / actual: 1.0 / expected: 1.0
round¶
In [ ]:
inl round forall t {float}. (n : t) : t =
n |> $'round'
In [ ]:
//// test
0.5 |> round
|> _assert_eq 0f64
1.5 |> round
|> _assert_eq 2f64
2.5 |> round
|> _assert_eq 2f64
3.5 |> round
|> _assert_eq 4f64
__assert_eq / actual: 0.0 / expected: 0.0 __assert_eq / actual: 2.0 / expected: 2.0 __assert_eq / actual: 2.0 / expected: 2.0 __assert_eq / actual: 4.0 / expected: 4.0
log_base¶
In [ ]:
inl log_base (new_base : f64) (a : f64) : f64 =
$'System.Math.Log (!a, !new_base)'
In [ ]:
//// test
100 |> log_base 10
|> _assert_eq 2
__assert_eq / actual: 2.0 / expected: 2.0
round¶
In [ ]:
inl round forall t {float}. (x : t) : t =
x |> $'round'
In [ ]:
//// test
0.5 |> round
|> _assert_eq 0f64
__assert_eq / actual: 0.0 / expected: 0.0
In [ ]:
//// test
0.6 |> round
|> _assert_eq 1f64
__assert_eq / actual: 1.0 / expected: 1.0