aboutsummaryrefslogtreecommitdiffstats
path: root/rational.c
diff options
context:
space:
mode:
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/rational.c b/rational.c
index 212ad07faa..26324899e5 100644
--- a/rational.c
+++ b/rational.c
@@ -488,7 +488,9 @@ nurat_canonicalize(VALUE *num, VALUE *den)
static void
nurat_reduce(VALUE *x, VALUE *y)
{
- VALUE gcd = f_gcd(*x, *y);
+ VALUE gcd;
+ if (*x == ONE || *y == ONE) return;
+ gcd = f_gcd(*x, *y);
*x = f_idiv(*x, gcd);
*y = f_idiv(*y, gcd);
}