summaryrefslogtreecommitdiff
path: root/rational.c
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2020-01-17 10:41:03 +0900
committerKenta Murata <mrkn@mrkn.jp>2020-01-17 10:57:21 +0900
commit47465ab1ccf48d2c905dbcf3b676e30b61cc41ca (patch)
tree365c04acbbc70374c1c6e66355dd9bbf3b8eb462 /rational.c
parent73618d84e807b4157e0ba44e9a09e4c643de6c2c (diff)
rb_rational_raw: make a denominator always positive
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/rational.c b/rational.c
index f483c6d..0261c69 100644
--- a/rational.c
+++ b/rational.c
@@ -1927,6 +1927,10 @@ rb_gcdlcm(VALUE self, VALUE other)
VALUE
rb_rational_raw(VALUE x, VALUE y)
{
+ if (INT_NEGATIVE_P(y)) {
+ x = rb_int_uminus(x);
+ y = rb_int_uminus(y);
+ }
return nurat_s_new_internal(rb_cRational, x, y);
}