This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
> > Guile could do better. To compute B / C, where B and C are > > bignums, as a floating-point value with a mantissa at most p bits > > long, Guile should find the closest integer to (B * 2^p) / C == > > (B/C) * 2^p, using only exact bignum arithmetic, and then use the > > IEEE 754 scalb function to simultaneously divide by 2^p and convert > > to double, without losing bits. > > The integer you refer to is (quotient (* B (expt 2 mantissa_bits)) C) > or this number + 1 (depending on whether the remainder is > or < > C/2). Right. > But this fails when this number is > the largest double, which is when the > result is within 2^p of max_double. You mean, it fails when the result doesn't fit into a double? That's fine; this is only to be used when the remainder is non-zero, in which case R5RS leaves us no choice (given that we don't have rationals, or inexact bignums) but to use a double. Maybe I'm missing something. > This also fails when C is large relative to B. In particular, if C > > B*2^p, then the closest integer is zero, even though the quotient is > easily representable in a double. You're right. I guess we need to multiply B by 2 until it is between C*2^(p-1) and C*2^p, and then divide by the appropriate amount. > Also, I can't find scalb on my system (linux) either in the header > files or in the libs. How does it differ from ldexp? The only difference is that scalb's exponnent is a double too. ldexp should work fine.