|
| 1 | +# 1 "float_u.ml" |
| 2 | +(**************************************************************************) |
| 3 | +(* *) |
| 4 | +(* OCaml *) |
| 5 | +(* *) |
| 6 | +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) |
| 7 | +(* Nicolas Ojeda Bar, LexiFi *) |
| 8 | +(* *) |
| 9 | +(* Copyright 2018 Institut National de Recherche en Informatique et *) |
| 10 | +(* en Automatique. *) |
| 11 | +(* *) |
| 12 | +(* All rights reserved. This file is distributed under the terms of *) |
| 13 | +(* the GNU Lesser General Public License version 2.1, with the *) |
| 14 | +(* special exception on linking described in the file LICENSE. *) |
| 15 | +(* *) |
| 16 | +(**************************************************************************) |
| 17 | + |
| 18 | +open! Stdlib |
| 19 | + |
| 20 | +[@@@ocaml.flambda_o3] |
| 21 | + |
| 22 | + |
| 23 | +external to_float : float# -> (float[@local_opt]) = "%box_float" |
| 24 | + |
| 25 | +external of_float : (float[@local_opt]) -> float# = "%unbox_float" |
| 26 | + |
| 27 | +(* CR layouts: Investigate whether it's worth making these things externals. |
| 28 | + Are there situations where the middle-end won't inline them and remove the |
| 29 | + boxing/unboxing? *) |
| 30 | + |
| 31 | +let[@inline always] neg x = of_float (Float.neg (to_float x)) |
| 32 | + |
| 33 | +let[@inline always] add x y = of_float (Float.add (to_float x) (to_float y)) |
| 34 | + |
| 35 | +let[@inline always] sub x y = of_float (Float.sub (to_float x) (to_float y)) |
| 36 | + |
| 37 | +let[@inline always] mul x y = of_float (Float.mul (to_float x) (to_float y)) |
| 38 | + |
| 39 | +let[@inline always] div x y = of_float (Float.div (to_float x) (to_float y)) |
| 40 | + |
| 41 | +let[@inline always] fma x y z = of_float (Float.fma (to_float x) (to_float y) (to_float z)) |
| 42 | + |
| 43 | +let[@inline always] rem x y = of_float (Float.rem (to_float x) (to_float y)) |
| 44 | + |
| 45 | +let[@inline always] succ x = of_float (Float.succ (to_float x)) |
| 46 | + |
| 47 | +let[@inline always] pred x = of_float (Float.pred (to_float x)) |
| 48 | + |
| 49 | +let[@inline always] abs x = of_float (Float.abs (to_float x)) |
| 50 | + |
| 51 | +let[@inline always] is_finite x = Float.is_finite (to_float x) |
| 52 | + |
| 53 | +let[@inline always] is_infinite x = Float.is_infinite (to_float x) |
| 54 | + |
| 55 | +let[@inline always] is_nan x = Float.is_nan (to_float x) |
| 56 | + |
| 57 | +let[@inline always] is_integer x = Float.is_integer (to_float x) |
| 58 | + |
| 59 | +let[@inline always] of_int x = of_float (Float.of_int x) |
| 60 | + |
| 61 | +let[@inline always] to_int x = Float.to_int (to_float x) |
| 62 | + |
| 63 | +let[@inline always] of_string x = of_float (Float.of_string x) |
| 64 | + |
| 65 | +let[@inline always] to_string x = Float.to_string (to_float x) |
| 66 | + |
| 67 | +type fpclass = Stdlib.fpclass = |
| 68 | + FP_normal |
| 69 | + | FP_subnormal |
| 70 | + | FP_zero |
| 71 | + | FP_infinite |
| 72 | + | FP_nan |
| 73 | + |
| 74 | +let[@inline always] classify_float x = Float.classify_float (to_float x) |
| 75 | + |
| 76 | +let[@inline always] pow x y = of_float (Float.pow (to_float x) (to_float y)) |
| 77 | + |
| 78 | +let[@inline always] sqrt x = of_float (Float.sqrt (to_float x)) |
| 79 | + |
| 80 | +let[@inline always] cbrt x = of_float (Float.cbrt (to_float x)) |
| 81 | + |
| 82 | +let[@inline always] exp x = of_float (Float.exp (to_float x)) |
| 83 | + |
| 84 | +let[@inline always] exp2 x = of_float (Float.exp2 (to_float x)) |
| 85 | + |
| 86 | +let[@inline always] log x = of_float (Float.log (to_float x)) |
| 87 | + |
| 88 | +let[@inline always] log10 x = of_float (Float.log10 (to_float x)) |
| 89 | + |
| 90 | +let[@inline always] log2 x = of_float (Float.log2 (to_float x)) |
| 91 | + |
| 92 | +let[@inline always] expm1 x = of_float (Float.expm1 (to_float x)) |
| 93 | + |
| 94 | +let[@inline always] log1p x = of_float (Float.log1p (to_float x)) |
| 95 | + |
| 96 | +let[@inline always] cos x = of_float (Float.cos (to_float x)) |
| 97 | + |
| 98 | +let[@inline always] sin x = of_float (Float.sin (to_float x)) |
| 99 | + |
| 100 | +let[@inline always] tan x = of_float (Float.tan (to_float x)) |
| 101 | + |
| 102 | +let[@inline always] acos x = of_float (Float.acos (to_float x)) |
| 103 | + |
| 104 | +let[@inline always] asin x = of_float (Float.asin (to_float x)) |
| 105 | + |
| 106 | +let[@inline always] atan x = of_float (Float.atan (to_float x)) |
| 107 | + |
| 108 | +let[@inline always] atan2 x y = of_float (Float.atan2 (to_float x) (to_float y)) |
| 109 | + |
| 110 | +let[@inline always] hypot x y = of_float (Float.hypot (to_float x) (to_float y)) |
| 111 | + |
| 112 | +let[@inline always] cosh x = of_float (Float.cosh (to_float x)) |
| 113 | + |
| 114 | +let[@inline always] sinh x = of_float (Float.sinh (to_float x)) |
| 115 | + |
| 116 | +let[@inline always] tanh x = of_float (Float.tanh (to_float x)) |
| 117 | + |
| 118 | +let[@inline always] acosh x = of_float (Float.acosh (to_float x)) |
| 119 | + |
| 120 | +let[@inline always] asinh x = of_float (Float.asinh (to_float x)) |
| 121 | + |
| 122 | +let[@inline always] atanh x = of_float (Float.atanh (to_float x)) |
| 123 | + |
| 124 | +let[@inline always] erf x = of_float (Float.erf (to_float x)) |
| 125 | + |
| 126 | +let[@inline always] erfc x = of_float (Float.erfc (to_float x)) |
| 127 | + |
| 128 | +let[@inline always] trunc x = of_float (Float.trunc (to_float x)) |
| 129 | + |
| 130 | +let[@inline always] round x = of_float (Float.round (to_float x)) |
| 131 | + |
| 132 | +let[@inline always] ceil x = of_float (Float.ceil (to_float x)) |
| 133 | + |
| 134 | +let[@inline always] floor x = of_float (Float.floor (to_float x)) |
| 135 | + |
| 136 | +let[@inline always] next_after x y = of_float (Float.next_after (to_float x) (to_float y)) |
| 137 | + |
| 138 | +let[@inline always] copy_sign x y = of_float (Float.copy_sign (to_float x) (to_float y)) |
| 139 | + |
| 140 | +let[@inline always] sign_bit x = Float.sign_bit (to_float x) |
| 141 | + |
| 142 | +let[@inline always] ldexp x i = of_float (Float.ldexp (to_float x) i) |
| 143 | + |
| 144 | +type t = float# |
| 145 | + |
| 146 | +let[@inline always] compare x y = Float.compare (to_float x) (to_float y) |
| 147 | + |
| 148 | +let[@inline always] equal x y = Float.equal (to_float x) (to_float y) |
| 149 | + |
| 150 | +let[@inline always] min x y = of_float (Float.min (to_float x) (to_float y)) |
| 151 | + |
| 152 | +let[@inline always] max x y = of_float (Float.max (to_float x) (to_float y)) |
| 153 | + |
| 154 | +let[@inline always] min_num x y = of_float (Float.min_num (to_float x) (to_float y)) |
| 155 | + |
| 156 | +let[@inline always] max_num x y = of_float (Float.max_num (to_float x) (to_float y)) |
0 commit comments