annotate lib/ldexpl.c @ 11653:ecb384fccb5b

fpurge: migrate into <stdio.h> * lib/fpurge.h: Delete... * lib/stdio.in.h (fpurge): ...and declare here, instead. * lib/fpurge.c (fpurge): Change declaring header. * modules/fpurge (Files): Drop deleted file. (Depends-on): Add stdio. (configure.ac): Set witness. * modules/stdio (Makefile.am): Support fpurge macros. * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Likewise. * m4/fpurge.m4 (gl_FUNC_FPURGE): Set appropriate variables. * lib/fflush.c: Update client. * tests/test-fpurge.c: Likewise. * NEWS: Mention the change. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Wed, 24 Jun 2009 06:49:00 -0600
parents 678640901735
children e8d2c6fc33ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Emulation for ldexpl.
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Contributed by Paolo Bonzini
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
10667
678640901735 Move the isnanf(), isnand(), isnanl() declarations to <math.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
4 Copyright 2002, 2003, 2007, 2008 Free Software Foundation, Inc.
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 This file is part of gnulib.
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8628
diff changeset
8 This program is free software: you can redistribute it and/or modify
4435
d4efdb886b2a Switch from LGPL to GPL.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4239
diff changeset
9 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8628
diff changeset
10 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8628
diff changeset
11 (at your option) any later version.
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12
4435
d4efdb886b2a Switch from LGPL to GPL.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4239
diff changeset
13 This program is distributed in the hope that it will be useful,
d4efdb886b2a Switch from LGPL to GPL.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4239
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
d4efdb886b2a Switch from LGPL to GPL.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4239
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d4efdb886b2a Switch from LGPL to GPL.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4239
diff changeset
16 GNU General Public License for more details.
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8628
diff changeset
18 You should have received a copy of the GNU General Public License
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8628
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
8186
c115624bf99a New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents: 5848
diff changeset
21 #include <config.h>
c115624bf99a New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents: 5848
diff changeset
22
c115624bf99a New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents: 5848
diff changeset
23 /* Specification. */
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <math.h>
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
8186
c115624bf99a New module 'math'. <math.h> replaces mathl.h.
Bruno Haible <bruno@clisp.org>
parents: 5848
diff changeset
26 #include <float.h>
8589
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
27 #include "fpucw.h"
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 long double
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 ldexpl(long double x, int exp)
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 {
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 long double factor;
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 int bit;
8589
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
34 DECL_LONG_DOUBLE_ROUNDING
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
35
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
36 BEGIN_LONG_DOUBLE_ROUNDING ();
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 /* Check for zero, nan and infinity. */
8589
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
39 if (!(isnanl (x) || x + x == x))
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 {
8589
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
41 if (exp < 0)
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
42 {
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
43 exp = -exp;
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
44 factor = 0.5L;
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
45 }
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
46 else
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
47 factor = 2.0L;
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
48
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
49 if (exp > 0)
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
50 for (bit = 1;;)
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
51 {
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
52 /* Invariant: Here bit = 2^i, factor = 2^-2^i or = 2^2^i,
8617
aacb9380395e Make ldexpl truly independent of libm
Eric Blake <ebb9@byu.net>
parents: 8589
diff changeset
53 and bit <= exp. */
8589
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
54 if (exp & bit)
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
55 x *= factor;
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
56 bit <<= 1;
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
57 if (bit > exp)
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
58 break;
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
59 factor = factor * factor;
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
60 }
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 }
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62
8589
3334000e84a6 Set the FPU control word as needed for 'long double' computations.
Bruno Haible <bruno@clisp.org>
parents: 8563
diff changeset
63 END_LONG_DOUBLE_ROUNDING ();
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 return x;
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 }
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 #if 0
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 int
4652
b09c3f1225b6 Remove K&R cruft.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4435
diff changeset
70 main (void)
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 {
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 long double x;
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 int y;
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 for (y = 0; y < 29; y++)
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 printf ("%5d %.16Lg %.16Lg\n", y, ldexpl(0.8L, y), ldexpl(0.8L, -y) * ldexpl(0.8L, y));
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 }
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 #endif