guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GMP code committed -- watch for bugs.


From: Rob Browning
Subject: Re: GMP code committed -- watch for bugs.
Date: Sun, 06 Apr 2003 13:43:40 -0500
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-pc-linux-gnu)

Mikael Djurfeldt <address@hidden> writes:

>               numbits = mpz_sizeinbase (SCM_I_BIG_MPZ (num), 2);
>               if (UNSIGNED) numbits++;
>               scm_remember_upto_here_1 (num);
>               if (numbits > (sizeof (ITYPE) * 8))
>                 scm_out_of_range (s_caller, num);
>
> Firstly, you probably intended to write "if (!UNSIGNED)" (to make room
> for the sign bit).

Indeed.

> Secondly, that doesn't work either.  For example, the absolute value
> of LLONG_MIN requires 64 bits, even though it is a signed number.
> So, regardless if we have "if (UNSIGNED)" or "if (!UNSIGNED)" there
> will always be a case where a valid long_long or ulong_long will
> cause an out_of_range error.

Hmm.  Actually it looks like mpz_sizeinbase includes the needed sign
bit in its computation (for some reason I thought it didn't).  So I
don't think we need the numbits++ at all.

-- 
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592  F9A0 25C8 D377 8C7E 73A4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]