annotate lib/sqrtl.c @ 17363:5a51fb7777a9

sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin Problem reported by Marco Atzeri in <http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>. * lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]: Simply delegate to the system <sys/select.h> in this case too. Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to be needed on Solaris either. * lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]: Simply delgate to the system <sys/time.h> in this case.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 19 Mar 2013 09:08:47 -0700
parents e542fd46ad6f
children 344018b6e5d7
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 sqrtl.
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
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
4 Copyright 2002-2003, 2007, 2009-2013 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: 8563
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: 8563
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: 8563
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: 8563
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: 8563
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
15936
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
26 #if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
27
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
28 long double
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
29 sqrtl (long double x)
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
30 {
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
31 return sqrt (x);
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
32 }
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
33
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
34 #else
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
35
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
36 # include <float.h>
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 /* A simple Newton-Raphson method. */
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 long double
13051
094f6cfdb5c3 Minor formatting changes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
40 sqrtl (long double x)
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 {
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 long double delta, y;
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 int exponent;
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
8563
c3d334708928 Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents: 8186
diff changeset
45 /* Check for NaN */
c3d334708928 Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents: 8186
diff changeset
46 if (isnanl (x))
c3d334708928 Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents: 8186
diff changeset
47 return x;
c3d334708928 Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents: 8186
diff changeset
48
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 /* Check for negative numbers */
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 if (x < 0.0L)
13051
094f6cfdb5c3 Minor formatting changes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
51 return (long double) sqrt (-1);
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52
8563
c3d334708928 Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents: 8186
diff changeset
53 /* Check for zero and infinites */
c3d334708928 Better support of signalling NaNs.
Bruno Haible <bruno@clisp.org>
parents: 8186
diff changeset
54 if (x + x == x)
4239
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 return x;
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 frexpl (x, &exponent);
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 y = ldexpl (x, -exponent / 2);
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 do
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 delta = y;
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 y = (y + x / y) * 0.5L;
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 delta -= y;
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 }
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 while (delta != 0.0L);
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 return y;
b33b8603715c Transcendental functions for 'long double', from Paolo Bonzini.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 }
15936
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
70
be4d9abe9bd0 sqrtl: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
71 #endif