ocaml: phase 6 Float module fleshed out (+6 tests, 598 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
New Float members: zero / one / minus_one abs / neg add / sub / mul / div (lift host '+.' '-.' '*.' '/.') max / min (if-based) equal / compare (Float.compare returns -1 / 0 / 1) to_int (host floor) of_int (identity in dynamic runtime) of_string (delegates to _int_of_string) Aligns Float with Int's API and lets baselines use Float.add / Float.compare / etc without lifting the symbols themselves. Float.add 3.5 4.5 = 8 Float.compare 2.5 5.0 = -1 Float.abs -3.7 = 3.7 Float.max 3.14 2.71 = 3.14
This commit is contained in:
@@ -630,6 +630,7 @@
|
||||
|
||||
module Float = struct
|
||||
let to_string f = _string_of_float f
|
||||
let of_string s = _int_of_string s
|
||||
let sqrt f = _float_sqrt f
|
||||
let sin f = _float_sin f
|
||||
let cos f = _float_cos f
|
||||
@@ -638,6 +639,22 @@
|
||||
let ceil f = _float_ceil f
|
||||
let round f = _float_round f
|
||||
let pi = 3.141592653589793
|
||||
let zero = 0.0
|
||||
let one = 1.0
|
||||
let minus_one = -1.0
|
||||
let abs f = if f < 0.0 then 0.0 -. f else f
|
||||
let neg f = 0.0 -. f
|
||||
let add a b = a +. b
|
||||
let sub a b = a -. b
|
||||
let mul a b = a *. b
|
||||
let div a b = a /. b
|
||||
let max a b = if a > b then a else b
|
||||
let min a b = if a < b then a else b
|
||||
let equal a b = a = b
|
||||
let compare a b =
|
||||
if a < b then -1 else if a > b then 1 else 0
|
||||
let to_int f = _float_floor f
|
||||
let of_int n = n
|
||||
end ;;
|
||||
|
||||
module Printf = struct
|
||||
|
||||
Reference in New Issue
Block a user