2018-01-24 18:08:18 +03:00
|
|
|
(system-include "carp_double.h")
|
2018-01-24 17:53:18 +03:00
|
|
|
|
2017-06-26 12:15:03 +03:00
|
|
|
(defmodule Double
|
2017-12-15 00:48:19 +03:00
|
|
|
(def pi 3.141592653589793)
|
2017-11-22 20:25:03 +03:00
|
|
|
(def e 2.718281828459045)
|
2019-09-08 14:02:04 +03:00
|
|
|
(register MAX Double "CARP_DBL_MAX")
|
2017-10-24 14:52:32 +03:00
|
|
|
(register = (Fn [Double Double] Bool))
|
2017-10-20 01:27:35 +03:00
|
|
|
(register < (Fn [Double Double] Bool))
|
|
|
|
(register > (Fn [Double Double] Bool))
|
2017-11-15 16:47:03 +03:00
|
|
|
(register neg (Fn [Double] Double))
|
2017-06-26 12:15:03 +03:00
|
|
|
(register + (Fn [Double Double] Double))
|
|
|
|
(register - (Fn [Double Double] Double))
|
|
|
|
(register * (Fn [Double Double] Double))
|
|
|
|
(register / (Fn [Double Double] Double))
|
2017-10-13 17:11:23 +03:00
|
|
|
(register to-int (Fn [Double] Int))
|
|
|
|
(register from-int (Fn [Int] Double))
|
2017-11-15 16:47:03 +03:00
|
|
|
(register to-float (Fn [Double] Float))
|
|
|
|
(register from-float (Fn [Float] Double))
|
2018-05-21 19:52:11 +03:00
|
|
|
(register to-long (Fn [Double] Long))
|
|
|
|
(register from-long (Fn [Long] Double))
|
2018-06-07 19:24:30 +03:00
|
|
|
(register to-bytes (Fn [Double] Long))
|
2019-09-08 14:02:04 +03:00
|
|
|
(register copy (Fn [(Ref Double)] Double))
|
|
|
|
|
2020-05-09 19:59:47 +03:00
|
|
|
(implements + Double.+)
|
|
|
|
(implements - Double.-)
|
|
|
|
(implements * Double.*)
|
|
|
|
(implements / Double./)
|
|
|
|
(implements < Double.<)
|
|
|
|
(implements > Double.>)
|
|
|
|
(implements = Double.=)
|
|
|
|
(implements copy Double.copy)
|
|
|
|
(implements neg Double.neg)
|
|
|
|
(implements to-int Double.to-int)
|
|
|
|
(implements from-int Double.from-int)
|
|
|
|
|
2019-09-08 14:02:04 +03:00
|
|
|
(register abs (Fn [Double] Double))
|
2017-10-20 01:44:25 +03:00
|
|
|
(register acos (Fn [Double] Double))
|
2017-11-15 16:06:49 +03:00
|
|
|
(register asin (Fn [Double] Double))
|
|
|
|
(register atan (Fn [Double] Double))
|
2017-10-20 01:27:35 +03:00
|
|
|
(register atan2 (Fn [Double Double] Double))
|
2019-09-08 14:02:04 +03:00
|
|
|
(register ceil (Fn [Double] Double))
|
|
|
|
(register cos (Fn [Double] Double))
|
2017-11-15 16:06:49 +03:00
|
|
|
(register cosh (Fn [Double] Double))
|
|
|
|
(register exp (Fn [Double] Double))
|
2019-09-08 14:02:04 +03:00
|
|
|
(register floor (Fn [Double] Double))
|
2017-11-15 16:06:49 +03:00
|
|
|
(register frexp (Fn [Double (Ref Int)] Double))
|
|
|
|
(register ldexp (Fn [Double Int] Double))
|
|
|
|
(register log (Fn [Double] Double))
|
|
|
|
(register log10 (Fn [Double] Double))
|
2019-09-08 14:02:04 +03:00
|
|
|
(register mod (Fn [Double Double] Double))
|
2017-11-15 16:06:49 +03:00
|
|
|
(register modf (Fn [Double (Ref Double)] Double))
|
|
|
|
(register pow (Fn [Double Double] Double))
|
2019-09-08 14:02:04 +03:00
|
|
|
(register sin (Fn [Double] Double))
|
|
|
|
(register sinh (Fn [Double] Double))
|
2017-10-20 01:27:35 +03:00
|
|
|
(register sqrt (Fn [Double] Double))
|
2019-09-08 14:02:04 +03:00
|
|
|
(register tan (Fn [Double] Double))
|
|
|
|
(register tanh (Fn [Double] Double))
|
2017-10-24 14:52:32 +03:00
|
|
|
|
2020-05-09 19:59:47 +03:00
|
|
|
(implements abs Double.abs)
|
|
|
|
(implements acos Double.acos)
|
|
|
|
(implements asin Double.asin)
|
|
|
|
(implements atan Double.atan)
|
|
|
|
(implements atan2 Double.atan2)
|
|
|
|
(implements ceil Double.ceil)
|
|
|
|
(implements cos Double.cos)
|
|
|
|
(implements cosh Double.cosh)
|
|
|
|
(implements exp Double.exp)
|
|
|
|
(implements floor Double.floor)
|
|
|
|
(implements frexp Double.frexp)
|
|
|
|
(implements ldexp Double.ldexp)
|
|
|
|
(implements log Double.log10)
|
|
|
|
(implements mod Double.mod)
|
|
|
|
(implements modf Double.modf)
|
|
|
|
(implements pow Double.pow)
|
|
|
|
(implements sin Double.sin)
|
|
|
|
(implements sinh Double.sinh)
|
|
|
|
(implements sqrt Double.sqrt)
|
|
|
|
(implements tan Double.tan)
|
|
|
|
(implements tanh Double.tanh)
|
|
|
|
|
2019-02-15 16:48:49 +03:00
|
|
|
(doc approx "checks whether `x` and `y` are approximately equal.
|
|
|
|
|
|
|
|
The margin of error is `0.00001`.")
|
2017-10-24 14:52:32 +03:00
|
|
|
(defn approx [x y]
|
2019-09-08 14:02:04 +03:00
|
|
|
(Generics.approx x y))
|
2017-10-24 14:52:32 +03:00
|
|
|
|
2019-02-15 16:48:49 +03:00
|
|
|
(doc zero "returns the value `0.0`.")
|
2017-12-04 09:21:35 +03:00
|
|
|
(defn zero []
|
|
|
|
0.0)
|
2020-05-09 19:59:47 +03:00
|
|
|
(implements zero Double.zero)
|
2017-12-04 09:21:35 +03:00
|
|
|
|
2019-09-08 14:02:04 +03:00
|
|
|
(defn inc [x]
|
|
|
|
(+ 1.0 x))
|
2020-05-09 19:59:47 +03:00
|
|
|
(implements inc Double.inc)
|
2019-09-08 14:02:04 +03:00
|
|
|
|
|
|
|
(defn dec [x]
|
|
|
|
(- x 1.0))
|
2020-05-09 19:59:47 +03:00
|
|
|
(implements inc Double.dec)
|
2019-09-08 14:02:04 +03:00
|
|
|
|
2017-12-04 09:21:35 +03:00
|
|
|
(defn add-ref [x y]
|
2018-01-28 07:56:03 +03:00
|
|
|
(Double.+ @x @y))
|
2020-05-09 19:59:47 +03:00
|
|
|
(implements add-ref Double.add-ref)
|
2018-01-15 18:27:05 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
(defmodule DoubleRef
|
|
|
|
(defn = [a b]
|
|
|
|
(Double.= @a @b))
|
|
|
|
|
|
|
|
(defn < [a b]
|
|
|
|
(Double.< @a @b))
|
2018-01-15 18:10:11 +03:00
|
|
|
|
2018-01-15 18:27:05 +03:00
|
|
|
(defn > [a b]
|
|
|
|
(Double.> @a @b))
|
2017-10-24 14:52:32 +03:00
|
|
|
)
|