4 ms·
I notice that your bit-twiddling version avoids the conditional branch for choosing whether to round up or down. Nice, but not easier to explain. (0x00800000 >
by pascal_cuoq 13y ago
I notice that your bit-twiddling version avoids
the conditional branch for choosing whether to round up or
down. Nice, but not easier to explain.
(0x00800000 >> exponent) is easier to explain that what
I did (1 << (23 - e)).
> C tends to make this sort of thing relatively verbose.
If this were assembly, there would be a chance that the
test for whether to return the argument without change can
be factored with the computation of the quantity (23 - e)
(which would be computed directly from the unbiased exponent),
so I would really have to try both before deciding on a variant.
> although I write this sort of stuff professionally,…
Since you are reading this (assuming you are reading this),
may I ask you what tools you use? I have been making do
with CRlibm and a good C compiler, occasionally relying on
long double when extra precision was needed, but it has been
close to inadequate a few times.
Is there a standard multi-precision floating-point calculator
that all floating-point experts use for quick computations,
with hexadecimal input and output, or does one have to build
one's own?
I was thinking of forcing myself to learn either bc or Gappa,
but they both seem to have horrible syntax
(that is, not a syntax similar to something I'm used to).
- stephencanon 13y ago> If this were assembly, there would be a chance that the test for whether to return the argument without change can be factored with the computation of the quantity (23 - e) (which would be computed directly from the unbiased exponent), so I would really have to try both before deciding on a variant. It works out exactly as you suggest. Tools: MPFR and GMP are extremely useful if using GPLv3 code doesn’t pose a problem for you and the small performance overhead of arbitrary-precision isn’t an issue. I have a small “big float” (not arbitrary precision, just more than enough digits than needed to design math library routines for “standard” precisions) library that I wrote myself. It’s not very complete but it has everything I need for library development.