diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-12-01 10:25:01 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-12-01 10:25:01 +0000 |
commit | b2f4e6bf9660bc322f5f1145d77d26ba41a153fd (patch) | |
tree | 91e6474e6397e7d7806a789a906109b728770109 /ufloor_log2.c | |
parent | 2599eb53f9946b1879d0657098027d29bf191a28 (diff) | |
download | mpfr-b2f4e6bf9660bc322f5f1145d77d26ba41a153fd.tar.gz |
Port all the IEEE dependent remaining functions so that it uses a generic way to compute the result if it detects that the double is not in IEEE format ( _GMP_IEEE_FLOATS == 0).
MPFR now should work well on non-IEEE machines.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2567 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'ufloor_log2.c')
-rw-r--r-- | ufloor_log2.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/ufloor_log2.c b/ufloor_log2.c index 7d8e05494..4b9c4a8a5 100644 --- a/ufloor_log2.c +++ b/ufloor_log2.c @@ -24,12 +24,37 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-impl.h" -/* returns floor(log(d)/log(2)) */ +/* returns floor(log(abs(d))/log(2)) */ long __gmpfr_floor_log2 (double d) { +#if _GMP_IEEE_FLOATS union ieee_double_extract x; x.d = d; return (long) x.s.exp - 1023; +#else + long exp; + double m; + + /* Get Abs */ + if (d < 0.0) + d = -d; + + if (d == 0.0) + return -1023; + else if (d >= 1.0) + { + exp = -1; + for( m= 1.0 ; m <= d ; m *=2.0 ) + exp++; + } + else + { + exp = 0; + for( m= 1.0 ; m > d ; m *= (1.0/2.0) ) + exp--; + } + return exp; +#endif } |