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

« back to all changes in this revision

Viewing changes to sysdeps/ieee754/dbl-64/s_ceil.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:
10
10
 * ====================================================
11
11
 */
12
12
 
 
13
#if defined(LIBM_SCCS) && !defined(lint)
 
14
static char rcsid[] = "$NetBSD: s_ceil.c,v 1.8 1995/05/10 20:46:53 jtc Exp $";
 
15
#endif
 
16
 
13
17
/*
14
18
 * ceil(x)
15
19
 * Return x rounded toward -inf to integral value
22
26
#include "math.h"
23
27
#include "math_private.h"
24
28
 
 
29
#ifdef __STDC__
25
30
static const double huge = 1.0e300;
 
31
#else
 
32
static double huge = 1.0e300;
 
33
#endif
26
34
 
27
 
double
28
 
__ceil(double x)
 
35
#ifdef __STDC__
 
36
        double __ceil(double x)
 
37
#else
 
38
        double __ceil(x)
 
39
        double x;
 
40
#endif
29
41
{
30
42
        int32_t i0,i1,j0;
31
43
        u_int32_t i,j;
32
44
        EXTRACT_WORDS(i0,i1,x);
33
45
        j0 = ((i0>>20)&0x7ff)-0x3ff;
34
46
        if(j0<20) {
35
 
            if(j0<0) {  /* raise inexact if x != 0 */
36
 
                math_force_eval(huge+x);
37
 
                /* return 0*sign(x) if |x|<1 */
38
 
                if(i0<0) {i0=0x80000000;i1=0;}
39
 
                else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
 
47
            if(j0<0) {  /* raise inexact if x != 0 */
 
48
                if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
 
49
                    if(i0<0) {i0=0x80000000;i1=0;}
 
50
                    else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
 
51
                }
40
52
            } else {
41
53
                i = (0x000fffff)>>j0;
42
54
                if(((i0&i)|i1)==0) return x; /* x is integral */
43
 
                math_force_eval(huge+x);        /* raise inexact flag */
44
 
                if(i0>0) i0 += (0x00100000)>>j0;
45
 
                i0 &= (~i); i1=0;
 
55
                if(huge+x>0.0) {        /* raise inexact flag */
 
56
                    if(i0>0) i0 += (0x00100000)>>j0;
 
57
                    i0 &= (~i); i1=0;
 
58
                }
46
59
            }
47
60
        } else if (j0>51) {
48
61
            if(j0==0x400) return x+x;   /* inf or NaN */
50
63
        } else {
51
64
            i = ((u_int32_t)(0xffffffff))>>(j0-20);
52
65
            if((i1&i)==0) return x;     /* x is integral */
53
 
            math_force_eval(huge+x);            /* raise inexact flag */
54
 
            if(i0>0) {
55
 
                if(j0==20) i0+=1;
56
 
                else {
57
 
                    j = i1 + (1<<(52-j0));
58
 
                    if(j<i1) i0+=1;     /* got a carry */
59
 
                    i1 = j;
 
66
            if(huge+x>0.0) {            /* raise inexact flag */
 
67
                if(i0>0) {
 
68
                    if(j0==20) i0+=1;
 
69
                    else {
 
70
                        j = i1 + (1<<(52-j0));
 
71
                        if(j<i1) i0+=1; /* got a carry */
 
72
                        i1 = j;
 
73
                    }
60
74
                }
 
75
                i1 &= (~i);
61
76
            }
62
 
            i1 &= (~i);
63
77
        }
64
78
        INSERT_WORDS(x,i0,i1);
65
79
        return x;
66
80
}
67
 
#ifndef __ceil
68
81
weak_alias (__ceil, ceil)
69
 
# ifdef NO_LONG_DOUBLE
 
82
#ifdef NO_LONG_DOUBLE
70
83
strong_alias (__ceil, __ceill)
71
84
weak_alias (__ceil, ceill)
72
 
# endif
73
85
#endif