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 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation,
20 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
27 /* Binary search. Quite inefficient but portable. */
29 frexpl(long double x, int *exp)
31 long double exponents[20], *next;
34 /* Check for zero, nan and infinity. */
35 if (x != x || x + x == x )
42 return -frexpl(-x, exp);
47 for (next = exponents, exponents[0] = 2.0L, bit = 1;
49 bit <<= 1, next[1] = next[0] * next[0], next++);
51 for (; next >= exponents; bit >>= 1, next--)
62 for (next = exponents, exponents[0] = 0.5L, bit = 1;
64 bit <<= 1, next[1] = next[0] * next[0], next++);
66 for (; next >= exponents; bit >>= 1, next--)
86 x = frexpl(0.0L / 0.0L, &y); printf ("%.6Lg %d\n", x, y);
87 x = frexpl(1.0L / 0.0L, &y); printf ("%.6Lg %d\n", x, y);
88 x = frexpl(-1.0L / 0.0L, &y); printf ("%.6Lg %d\n", x, y);
89 x = frexpl(0.5L, &y); printf ("%.6Lg %d\n", x, y);
90 x = frexpl(0.75L, &y); printf ("%.6Lg %d\n", x, y);
91 x = frexpl(3.6L, &y); printf ("%.6Lg %d\n", x, y);
92 x = frexpl(17.8L, &y); printf ("%.6Lg %d\n", x, y);
93 x = frexpl(8.0L, &y); printf ("%.6Lg %d\n", x, y);
94 x = frexpl(0.3L, &y); printf ("%.6Lg %d\n", x, y);
95 x = frexpl(0.49L, &y); printf ("%.6Lg %d\n", x, y);
96 x = frexpl(0.049L, &y); printf ("%.6Lg %d\n", x, y);
97 x = frexpl(0.0245L, &y); printf ("%.6Lg %d\n", x, y);
98 x = frexpl(0.0625L, &y); printf ("%.6Lg %d\n", x, y);