aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/lux/math.lux20
-rw-r--r--stdlib/source/lux/math/ratio.lux3
2 files changed, 10 insertions, 13 deletions
diff --git a/stdlib/source/lux/math.lux b/stdlib/source/lux/math.lux
index 1ed87f1e8..12c32b853 100644
--- a/stdlib/source/lux/math.lux
+++ b/stdlib/source/lux/math.lux
@@ -76,26 +76,22 @@
[pow "invokestatic:java.lang.Math:pow:double,double"]
)
-(def: (gcd' a b)
- (-> Int Int Int)
- (case b
- 0 a
- _ (gcd' b (i.% b a))))
-
(def: #export (gcd a b)
{#;doc "Greatest Common Divisor."}
- (-> Int Int Int)
- (gcd' (Int/abs a) (Int/abs b)))
+ (-> Nat Nat Nat)
+ (case b
+ +0 a
+ _ (gcd b (n.% b a))))
(def: #export (lcm x y)
{#;doc "Least Common Multiple."}
- (-> Int Int Int)
+ (-> Nat Nat Nat)
(case [x y]
- (^or [_ 0] [0 _])
- 0
+ (^or [_ +0] [+0 _])
+ +0
_
- (|> x (i./ (gcd x y)) (i.* y) Int/abs)
+ (|> x (n./ (gcd x y)) (n.* y))
))
## [Syntax]
diff --git a/stdlib/source/lux/math/ratio.lux b/stdlib/source/lux/math/ratio.lux
index 5fb82c8a5..c2c9e7183 100644
--- a/stdlib/source/lux/math/ratio.lux
+++ b/stdlib/source/lux/math/ratio.lux
@@ -24,7 +24,8 @@
(def: #hidden (normalize (^slots [#numerator #denominator]))
(-> Ratio Ratio)
- (let [common (math;gcd numerator denominator)
+ (let [common (nat-to-int (math;gcd (int-to-nat (i:abs numerator))
+ (int-to-nat (i:abs denominator))))
numerator (i./ common numerator)
denominator (i./ common denominator)]
{#numerator (if (and (i.< 0 numerator)