mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 14:50:19 +02:00
(scm_make_ratio): Check for numerator equal to
SCM_MOST_NEGATIVE_FIXNUM and bignum denominator the negative of that, giving integer -1.
This commit is contained in:
parent
f39032937e
commit
dd5130cadf
1 changed files with 10 additions and 2 deletions
|
@ -357,18 +357,26 @@ scm_make_ratio (SCM numerator, SCM denominator)
|
||||||
*/
|
*/
|
||||||
if (SCM_INUMP (numerator))
|
if (SCM_INUMP (numerator))
|
||||||
{
|
{
|
||||||
|
long x = SCM_INUM (numerator);
|
||||||
if (SCM_EQ_P (numerator, SCM_INUM0))
|
if (SCM_EQ_P (numerator, SCM_INUM0))
|
||||||
return SCM_INUM0;
|
return SCM_INUM0;
|
||||||
if (SCM_INUMP (denominator))
|
if (SCM_INUMP (denominator))
|
||||||
{
|
{
|
||||||
long x, y;
|
long y;
|
||||||
x = SCM_INUM (numerator);
|
|
||||||
y = SCM_INUM (denominator);
|
y = SCM_INUM (denominator);
|
||||||
if (x == y)
|
if (x == y)
|
||||||
return SCM_MAKINUM(1);
|
return SCM_MAKINUM(1);
|
||||||
if ((x % y) == 0)
|
if ((x % y) == 0)
|
||||||
return SCM_MAKINUM (x / y);
|
return SCM_MAKINUM (x / y);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* When x == SCM_MOST_NEGATIVE_FIXNUM we could have the negative
|
||||||
|
of that value for the denominator, as a bignum. */
|
||||||
|
long abs_x = (x >= 0 ? x : -x);
|
||||||
|
if (mpz_cmpabs_ui (SCM_I_BIG_MPZ (denominator), abs_x) == 0)
|
||||||
|
return SCM_MAKINUM(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (SCM_BIGP (numerator))
|
else if (SCM_BIGP (numerator))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue