Carp/core/Float.carp
hellerve 9848e8fb34 multiple fixes:
- don’t do function copying in benchmarking
- fix the array_update benchmark
- add Filepath.file-from-path
- add tests for the `Filepath` module
- reformat a lot of documentation
2019-02-15 14:48:49 +01:00

78 lines
2.0 KiB
Plaintext

(system-include "carp_float.h")
(defmodule Float
(def pi 3.1415926536f)
(register neg (Fn [Float] Float))
(register + (Fn [Float Float] Float))
(register - (Fn [Float Float] Float))
(register * (Fn [Float Float] Float))
(register / (Fn [Float Float] Float))
(register to-int (Fn [Float] Int))
(register to-bytes (Fn [Float] Int))
(register from-int (Fn [Int] Float))
(register copy (Fn [(Ref Float)] Float))
(register = (Fn [Float Float] Bool))
(defn /= [x y]
(not (Float.= x y)))
(register < (Fn [Float Float] Bool))
(register > (Fn [Float Float] Bool))
(defn clamp [min, max, val]
(if (> val max)
max
(if (< val min)
min
val)))
(doc approx "checks whether `x` and `y` are approximately equal.
The margin of error is 0.00001.")
(defn approx [x y]
(if (> x y)
(< (- x y) 0.00001f)
(< (- y x) 0.00001f)))
(register sin (Fn [Float] Float))
(register cos (Fn [Float] Float))
(register tan (Fn [Float] Float))
(register acos (Fn [Float] Float))
(register asin (Fn [Float] Float))
(register atan (Fn [Float] Float))
(register atan2 (Fn [Float Float] Float))
(register cosh (Fn [Float] Float))
(register sinh (Fn [Float] Float))
(register tanh (Fn [Float] Float))
(register exp (Fn [Float] Float))
(register frexp (Fn [Float (Ref Int)] Float))
(register ldexp (Fn [Float Int] Float))
(register log (Fn [Float] Float))
(register log10 (Fn [Float] Float))
(register modf (Fn [Float (Ref Float)] Float))
(register pow (Fn [Float Float] Float))
(register sqrt (Fn [Float] Float))
(register floor (Fn [Float] Float))
(register ceil (Fn [Float] Float))
(register mod (Fn [Float Float] Float))
(register copy (Fn [(Ref Float)] Float))
(register abs (Fn [Float] Float))
(doc zero "returns `0.0f`.")
(defn zero []
0.0f)
(defn add-ref [x y]
(Float.+ @x @y))
)
(defmodule FloatRef
(defn = [a b]
(Float.= @a @b))
(defn < [a b]
(Float.< @a @b))
(defn > [a b]
(Float.> @a @b))
)