diff src/number.c @ 4883:f730384b8ddf

Be more careful about canonical integer forms when dealing with ratios. 2010-01-24 Aidan Kehoe <kehoea@parhasard.net> * number.c (Fnumerator, Fdenominator, Fcanonicalize_number): Be more careful to return integers in their canonical forms here, and to give the same answer all the time when treating a rational that is itself is an integer as a ratio.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 24 Jan 2010 19:56:31 +0000
parents 2fc0e2f18322
children 1e9078742fa7 19a72041c5ed
line wrap: on
line diff
--- a/src/number.c	Wed Jan 20 17:30:29 2010 +0000
+++ b/src/number.c	Sun Jan 24 19:56:31 2010 +0000
@@ -248,12 +248,13 @@
 {
   CONCHECK_RATIONAL (rational);
 #ifdef HAVE_RATIO
-  return RATIOP (rational)
-    ? make_bignum_bg (XRATIO_NUMERATOR (rational))
-    : rational;
-#else
+  if (RATIOP (rational))
+    {
+      return
+	Fcanonicalize_number (make_bignum_bg (XRATIO_NUMERATOR (rational)));
+    }
+#endif
   return rational;
-#endif
 }
 
 DEFUN ("denominator", Fdenominator, 1, 1, 0, /*
@@ -264,12 +265,13 @@
 {
   CONCHECK_RATIONAL (rational);
 #ifdef HAVE_RATIO
-  return RATIOP (rational)
-    ? make_bignum_bg (XRATIO_DENOMINATOR (rational))
-    : make_int (1);
-#else
-  return rational;
+  if (RATIOP (rational))
+    {
+      return Fcanonicalize_number (make_bignum_bg
+				   (XRATIO_DENOMINATOR (rational)));
+    }
 #endif
+  return make_int (1);
 }
 
 
@@ -451,7 +453,7 @@
   if (RATIOP (number) &&
       bignum_fits_long_p (XRATIO_DENOMINATOR (number)) &&
       bignum_to_long (XRATIO_DENOMINATOR (number)) == 1L)
-    number = make_bignum_bg (XRATIO_NUMERATOR (number));
+    number = Fcanonicalize_number (make_bignum_bg (XRATIO_NUMERATOR (number)));
 #endif
 #ifdef HAVE_BIGNUM
   if (BIGNUMP (number) && bignum_fits_emacs_int_p (XBIGNUM_DATA (number)))