Ilya Zakharevich on Wed, 18 Sep 2024 08:47:06 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: A missing (?) function: exponentfp(x) |
On Mon, Sep 16, 2024 at 09:36:37PM +0200, Loïc Grenié wrote: > On Sat, 14 Sep, 2024 at 11:09, Ilya Zakharevich wrote: > > > The function exponent(x) gives a very coarse value of log2(x). The > > function log(x)/log(2) gives a very fine value of log2(x) (but is > > slow, especially if x has high precision). But sometimes I prefer to > > know log2(x) with an intermediate precision; in fact, any sufficiently > > smooth monotonic function which coincides with log2 on powers of 2 > > would be enough! > > > > In particular, exponent(x) + mantissa12(x) - 1 would be OK. (Here > > mantissa12() is the (top word of) mantissa-scaled-to-[1,2].) It > > should be very cheap to calculate. It may be beneficial to have two > > flavors, returning a double, or a 1-word PARI float. > > > > expofp(x)=my(e=exponent(x));e+(precision(x,19)>>e-1); Yes, this does exactly what I wrote! However, it is not very much useful, since • As written, it is about 25 times slower than exponent(). • It needs to be rewritten — slowing it yet much more, since, as you wrote: > Works only on floating point x's. Thanks, Ilya