mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
128 lines
3.3 KiB
Plaintext
128 lines
3.3 KiB
Plaintext
(system-include "carp_float.h")
|
|
|
|
(doc Float "is a smaller numerical floating point type. Its literals are
|
|
suffixed with `f`.")
|
|
(defmodule Float
|
|
(def pi 3.1415926536f)
|
|
(register MAX Float "CARP_FLT_MAX")
|
|
(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 round (Fn [Float] Int))
|
|
|
|
(register = (Fn [Float Float] Bool))
|
|
(register < (Fn [Float Float] Bool))
|
|
(register > (Fn [Float Float] Bool))
|
|
|
|
(implements pi Float.pi)
|
|
(implements + Float.+)
|
|
(implements - Float.-)
|
|
(implements * Float.*)
|
|
(implements / Float./)
|
|
(implements < Float.<)
|
|
(implements > Float.>)
|
|
(implements = Float.=)
|
|
(implements copy Float.copy)
|
|
(implements neg Float.neg)
|
|
(implements to-int Float.to-int)
|
|
(implements from-int Float.from-int)
|
|
|
|
(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]
|
|
(Generics.approx x y))
|
|
|
|
(register copy (Fn [(Ref Float)] Float))
|
|
|
|
(register abs (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 ceil (Fn [Float] Float))
|
|
(register cos (Fn [Float] Float))
|
|
(register cosh (Fn [Float] Float))
|
|
(register exp (Fn [Float] Float))
|
|
(register floor (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 mod (Fn [Float Float] Float))
|
|
(register modf (Fn [Float (Ref Float)] Float))
|
|
(register pow (Fn [Float Float] Float))
|
|
(register sin (Fn [Float] Float))
|
|
(register sinh (Fn [Float] Float))
|
|
(register sqrt (Fn [Float] Float))
|
|
(register tan (Fn [Float] Float))
|
|
(register tanh (Fn [Float] Float))
|
|
|
|
(implements abs Float.abs)
|
|
(implements acos Float.acos)
|
|
(implements asin Float.asin)
|
|
(implements atan Float.atan)
|
|
(implements atan2 Float.atan2)
|
|
(implements ceil Float.ceil)
|
|
(implements cos Float.cos)
|
|
(implements cosh Float.cosh)
|
|
(implements exp Float.exp)
|
|
(implements floor Float.floor)
|
|
(implements frexp Float.frexp)
|
|
(implements ldexp Float.ldexp)
|
|
(implements log Float.log)
|
|
(implements log10 Float.log10)
|
|
(implements mod Float.mod)
|
|
(implements modf Float.modf)
|
|
(implements pow Float.pow)
|
|
(implements sin Float.sin)
|
|
(implements sinh Float.sinh)
|
|
(implements sqrt Float.sqrt)
|
|
(implements tan Float.tan)
|
|
(implements tanh Float.tanh)
|
|
|
|
(doc zero "returns `0.0f`.")
|
|
(defn zero []
|
|
0.0f)
|
|
(implements zero Float.zero)
|
|
|
|
(defn inc [x]
|
|
(+ 1.0f x))
|
|
(implements inc Float.inc)
|
|
|
|
(defn dec [x]
|
|
(- x 1.0f))
|
|
(implements dec Float.dec)
|
|
|
|
(defn add-ref [x y]
|
|
(Float.+ @x @y))
|
|
(implements add-ref Float.add-ref)
|
|
)
|
|
|
|
(defmodule FloatRef
|
|
(defn = [a b]
|
|
(Float.= @a @b))
|
|
(implements = FloatRef.=)
|
|
|
|
(defn < [a b]
|
|
(Float.< @a @b))
|
|
(implements < FloatRef.<)
|
|
|
|
(defn > [a b]
|
|
(Float.> @a @b))
|
|
(implements > FloatRef.>)
|
|
)
|