aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/math/number/frac.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/library/lux/math/number/frac.lux166
1 files changed, 83 insertions, 83 deletions
diff --git a/stdlib/source/library/lux/math/number/frac.lux b/stdlib/source/library/lux/math/number/frac.lux
index 149ca8e50..ea62f7c92 100644
--- a/stdlib/source/library/lux/math/number/frac.lux
+++ b/stdlib/source/library/lux/math/number/frac.lux
@@ -559,19 +559,19 @@
(..= ..positive_infinity it)
(..= ..negative_infinity it))))
-(implementation: .public equivalence
+(def: .public equivalence
(Equivalence Frac)
-
- (def: (= left right)
- (or (..= left right)
- (and (..not_a_number? left)
- (..not_a_number? right)))))
+ (implementation
+ (def: (= left right)
+ (or (..= left right)
+ (and (..not_a_number? left)
+ (..not_a_number? right))))))
-(implementation: .public order
+(def: .public order
(Order Frac)
-
- (def: equivalence ..equivalence)
- (def: < ..<))
+ (implementation
+ (def: equivalence ..equivalence)
+ (def: < ..<)))
(def: .public smallest
Frac
@@ -587,11 +587,11 @@
(..* f2^+1023))))
(with_template [<name> <composite> <identity>]
- [(implementation: .public <name>
+ [(def: .public <name>
(Monoid Frac)
-
- (def: identity <identity>)
- (def: composite <composite>))]
+ (implementation
+ (def: identity <identity>)
+ (def: composite <composite>)))]
[addition ..+ +0.0]
[multiplication ..* +1.0]
@@ -599,26 +599,26 @@
[maximum ..max (..* -1.0 ..biggest)]
)
-(implementation: .public decimal
+(def: .public decimal
(Codec Text Frac)
-
- (def: (encoded x)
- (case x
- -0.0 (let [output ("lux f64 encode" x)]
- (if (text.starts_with? "-" output)
- output
- ("lux text concat" "+" output)))
- _ (if (..< +0.0 x)
- ("lux f64 encode" x)
- ("lux text concat" "+" ("lux f64 encode" x)))))
-
- (def: (decoded input)
- (case ("lux f64 decode" input)
- {.#Some value}
- {try.#Success value}
-
- {.#None}
- {try.#Failure "Could not decode Frac"})))
+ (implementation
+ (def: (encoded x)
+ (case x
+ -0.0 (let [output ("lux f64 encode" x)]
+ (if (text.starts_with? "-" output)
+ output
+ ("lux text concat" "+" output)))
+ _ (if (..< +0.0 x)
+ ("lux f64 encode" x)
+ ("lux text concat" "+" ("lux f64 encode" x)))))
+
+ (def: (decoded input)
+ (case ("lux f64 decode" input)
+ {.#Some value}
+ {try.#Success value}
+
+ {.#None}
+ {try.#Failure "Could not decode Frac"}))))
(def: log/2
(-> Frac Frac)
@@ -777,64 +777,64 @@
{try.#Success [representation +0]}))
(with_template [<struct> <nat> <int> <error>]
- [(implementation: .public <struct>
+ [(def: .public <struct>
(Codec Text Frac)
-
- (def: (encoded value)
- (let [bits (..bits value)
- mantissa (..mantissa bits)
- exponent (//int.- (.int ..double_bias) (..exponent bits))
- sign (..sign bits)]
- (all "lux text concat"
- (case (.nat sign)
- 1 "-"
- 0 "+"
- _ (undefined))
- (at <nat> encoded (.nat mantissa))
- ".0E"
- (at <int> encoded exponent))))
-
- (def: (decoded representation)
- (let [negative? (text.starts_with? "-" representation)
- positive? (text.starts_with? "+" representation)]
- (if (or negative? positive?)
- (do [! try.monad]
- [[mantissa exponent] (..representation_exponent <nat> representation)
- [whole decimal] (case ("lux text index" 0 "." mantissa)
- {.#Some split_index}
- (do !
- [.let [after_offset (++ split_index)
- after_length (//nat.- after_offset ("lux text size" mantissa))]
- decimal (|> mantissa
- ("lux text clip" after_offset after_length)
- (at <nat> decoded))]
- (in [("lux text clip" 0 split_index mantissa)
- decimal]))
-
- {.#None}
- {try.#Failure ("lux text concat" <error> representation)})
- .let [whole ("lux text clip" 1 (-- ("lux text size" whole)) whole)]
- mantissa (at <nat> decoded (case decimal
- 0 whole
- _ ("lux text concat" whole (at <nat> encoded decimal))))
- .let [sign (if negative? 1 0)]]
- (in (..of_bits
- (all //i64.or
- (//i64.left_shifted ..sign_offset (.i64 sign))
- (//i64.left_shifted ..mantissa_size (.i64 (//int.+ (.int ..double_bias) exponent)))
- (//i64.zero ..mantissa_size (.i64 mantissa))))))
- {try.#Failure ("lux text concat" <error> representation)}))))]
+ (implementation
+ (def: (encoded value)
+ (let [bits (..bits value)
+ mantissa (..mantissa bits)
+ exponent (//int.- (.int ..double_bias) (..exponent bits))
+ sign (..sign bits)]
+ (all "lux text concat"
+ (case (.nat sign)
+ 1 "-"
+ 0 "+"
+ _ (undefined))
+ (at <nat> encoded (.nat mantissa))
+ ".0E"
+ (at <int> encoded exponent))))
+
+ (def: (decoded representation)
+ (let [negative? (text.starts_with? "-" representation)
+ positive? (text.starts_with? "+" representation)]
+ (if (or negative? positive?)
+ (do [! try.monad]
+ [[mantissa exponent] (..representation_exponent <nat> representation)
+ [whole decimal] (case ("lux text index" 0 "." mantissa)
+ {.#Some split_index}
+ (do !
+ [.let [after_offset (++ split_index)
+ after_length (//nat.- after_offset ("lux text size" mantissa))]
+ decimal (|> mantissa
+ ("lux text clip" after_offset after_length)
+ (at <nat> decoded))]
+ (in [("lux text clip" 0 split_index mantissa)
+ decimal]))
+
+ {.#None}
+ {try.#Failure ("lux text concat" <error> representation)})
+ .let [whole ("lux text clip" 1 (-- ("lux text size" whole)) whole)]
+ mantissa (at <nat> decoded (case decimal
+ 0 whole
+ _ ("lux text concat" whole (at <nat> encoded decimal))))
+ .let [sign (if negative? 1 0)]]
+ (in (..of_bits
+ (all //i64.or
+ (//i64.left_shifted ..sign_offset (.i64 sign))
+ (//i64.left_shifted ..mantissa_size (.i64 (//int.+ (.int ..double_bias) exponent)))
+ (//i64.zero ..mantissa_size (.i64 mantissa))))))
+ {try.#Failure ("lux text concat" <error> representation)})))))]
[binary //nat.binary //int.binary "Invalid binary syntax: "]
[octal //nat.octal //int.octal "Invalid octaladecimal syntax: "]
[hex //nat.hex //int.hex "Invalid hexadecimal syntax: "]
)
-(implementation: .public hash
+(def: .public hash
(Hash Frac)
-
- (def: equivalence ..equivalence)
- (def: hash ..bits))
+ (implementation
+ (def: equivalence ..equivalence)
+ (def: hash ..bits)))
(def: .public (approximately? margin_of_error standard value)
(-> Frac Frac Frac Bit)