~ubuntu-branches/ubuntu/precise/eglibc/precise

« back to all changes in this revision

Viewing changes to sysdeps/ieee754/flt-32/e_sqrtf.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2011-10-04 17:48:26 UTC
  • mfrom: (216.1.23 oneiric)
  • Revision ID: package-import@ubuntu.com-20111004174826-2cyb9ewn3ucymlsx
Tags: 2.13-20ubuntu5
libc6-dev: Don't break the current {gnat,gcj}-4.4-base versons. LP: #853688.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *
9
9
 * Developed at SunPro, a Sun Microsystems, Inc. business.
10
10
 * Permission to use, copy, modify, and distribute this
11
 
 * software is freely granted, provided that this notice
 
11
 * software is freely granted, provided that this notice 
12
12
 * is preserved.
13
13
 * ====================================================
14
14
 */
15
15
 
 
16
#if defined(LIBM_SCCS) && !defined(lint)
 
17
static char rcsid[] = "$NetBSD: e_sqrtf.c,v 1.4 1995/05/10 20:46:19 jtc Exp $";
 
18
#endif
 
19
 
16
20
#include "math.h"
17
21
#include "math_private.h"
18
22
 
 
23
#ifdef __STDC__
19
24
static  const float     one     = 1.0, tiny=1.0e-30;
 
25
#else
 
26
static  float   one     = 1.0, tiny=1.0e-30;
 
27
#endif
20
28
 
21
 
float
22
 
__ieee754_sqrtf(float x)
 
29
#ifdef __STDC__
 
30
        float __ieee754_sqrtf(float x)
 
31
#else
 
32
        float __ieee754_sqrtf(x)
 
33
        float x;
 
34
#endif
23
35
{
24
36
        float z;
25
 
        int32_t sign = (int)0x80000000;
 
37
        int32_t sign = (int)0x80000000; 
26
38
        int32_t ix,s,q,m,t,i;
27
39
        u_int32_t r;
28
40
 
29
41
        GET_FLOAT_WORD(ix,x);
30
42
 
31
43
    /* take care of Inf and NaN */
32
 
        if((ix&0x7f800000)==0x7f800000) {
 
44
        if((ix&0x7f800000)==0x7f800000) {                       
33
45
            return x*x+x;               /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
34
46
                                           sqrt(-inf)=sNaN */
35
 
        }
 
47
        } 
36
48
    /* take care of zero */
37
49
        if(ix<=0) {
38
50
            if((ix&(~sign))==0) return x;/* sqrt(+-0) = +-0 */
57
69
        r = 0x01000000;         /* r = moving bit from right to left */
58
70
 
59
71
        while(r!=0) {
60
 
            t = s+r;
61
 
            if(t<=ix) {
62
 
                s    = t+r;
63
 
                ix  -= t;
64
 
                q   += r;
65
 
            }
 
72
            t = s+r; 
 
73
            if(t<=ix) { 
 
74
                s    = t+r; 
 
75
                ix  -= t; 
 
76
                q   += r; 
 
77
            } 
66
78
            ix += ix;
67
79
            r>>=1;
68
80
        }
71
83
        if(ix!=0) {
72
84
            z = one-tiny; /* trigger inexact flag */
73
85
            if (z>=one) {
74
 
                z = one+tiny;
 
86
                z = one+tiny;
75
87
                if (z>one)
76
88
                    q += 2;
77
89
                else
83
95
        SET_FLOAT_WORD(z,ix);
84
96
        return z;
85
97
}
86
 
strong_alias (__ieee754_sqrtf, __sqrtf_finite)