1 /* Emulation for frexpl.
2 Contributed by Paolo Bonzini
4 Copyright 2002, 2003 Free Software Foundation, Inc.
6 This file is part of gnulib.
8 gnulib is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2.1, or (at your option)
13 gnulib is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with gnulib; see the file COPYING.LIB. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
29 /* Binary search. Quite inefficient but portable. */
31 frexpl(long double x, int *exp)
33 long double exponents[20], *next;
36 /* Check for zero, nan and infinity. */
37 if (x != x || x + x == x )
44 return -frexpl(-x, exp);
49 for (next = exponents, exponents[0] = 2.0L, bit = 1;
51 bit <<= 1, next[1] = next[0] * next[0], next++);
53 for (; next >= exponents; bit >>= 1, next--)
64 for (next = exponents, exponents[0] = 0.5L, bit = 1;
66 bit <<= 1, next[1] = next[0] * next[0], next++);
68 for (; next >= exponents; bit >>= 1, next--)
88 x = frexpl(0.0L / 0.0L, &y); printf ("%.6Lg %d\n", x, y);
89 x = frexpl(1.0L / 0.0L, &y); printf ("%.6Lg %d\n", x, y);
90 x = frexpl(-1.0L / 0.0L, &y); printf ("%.6Lg %d\n", x, y);
91 x = frexpl(0.5L, &y); printf ("%.6Lg %d\n", x, y);
92 x = frexpl(0.75L, &y); printf ("%.6Lg %d\n", x, y);
93 x = frexpl(3.6L, &y); printf ("%.6Lg %d\n", x, y);
94 x = frexpl(17.8L, &y); printf ("%.6Lg %d\n", x, y);
95 x = frexpl(8.0L, &y); printf ("%.6Lg %d\n", x, y);
96 x = frexpl(0.3L, &y); printf ("%.6Lg %d\n", x, y);
97 x = frexpl(0.49L, &y); printf ("%.6Lg %d\n", x, y);
98 x = frexpl(0.049L, &y); printf ("%.6Lg %d\n", x, y);
99 x = frexpl(0.0245L, &y); printf ("%.6Lg %d\n", x, y);
100 x = frexpl(0.0625L, &y); printf ("%.6Lg %d\n", x, y);