init commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
(ns Float
|
||||
"Elixir Float module — float operations.
|
||||
|
||||
In CljElixir: (Float/round 3.14159 2), (Float/parse \"3.14\"), etc.")
|
||||
|
||||
(defn parse
|
||||
"Parses a string into a float. Returns {float rest} or :error.
|
||||
(Float/parse \"3.14\") ;=> {3.14 \"\"}
|
||||
(Float/parse \"3.14abc\") ;=> {3.14 \"abc\"}
|
||||
(Float/parse \"nope\") ;=> :error"
|
||||
[string])
|
||||
|
||||
(defn round
|
||||
"Rounds to the given number of decimal places.
|
||||
(Float/round 3.14159 2) ;=> 3.14
|
||||
(Float/round 3.5) ;=> 4.0"
|
||||
([float])
|
||||
([float precision]))
|
||||
|
||||
(defn ceil
|
||||
"Rounds up to given decimal precision.
|
||||
(Float/ceil 3.14 1) ;=> 3.2
|
||||
(Float/ceil 3.14) ;=> 4.0"
|
||||
([float])
|
||||
([float precision]))
|
||||
|
||||
(defn floor
|
||||
"Rounds down to given decimal precision.
|
||||
(Float/floor 3.14 1) ;=> 3.1
|
||||
(Float/floor 3.14) ;=> 3.0"
|
||||
([float])
|
||||
([float precision]))
|
||||
|
||||
(defn to-string
|
||||
"Converts float to string.
|
||||
(Float/to-string 3.14) ;=> \"3.14\"
|
||||
(Float/to-string 3.14 :compact) ;=> compact decimal
|
||||
(Float/to-string 3.14 [:decimals 2]) ;=> \"3.14\""
|
||||
([float])
|
||||
([float opts]))
|
||||
|
||||
(defn to-charlist
|
||||
"Converts float to charlist."
|
||||
([float])
|
||||
([float opts]))
|
||||
|
||||
(defn ratio
|
||||
"Returns {numerator denominator} for the given float.
|
||||
(Float/ratio 0.75) ;=> {3 4}"
|
||||
[float])
|
||||
|
||||
(defn min-finite
|
||||
"Returns the minimum finite float value."
|
||||
[])
|
||||
|
||||
(defn max-finite
|
||||
"Returns the maximum finite float value."
|
||||
[])
|
||||
|
||||
(defn pow
|
||||
"Returns `base` raised to `exponent` as a float.
|
||||
(Float/pow 2.0 10) ;=> 1024.0"
|
||||
[base exponent])
|
||||
Reference in New Issue
Block a user