Subversion Repositories Kolibri OS

Rev

Rev 4872 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
 
2
/*
3
 * ====================================================
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * Developed at SunPro, a Sun Microsystems, Inc. business.
7
 * Permission to use, copy, modify, and distribute this
8
 * software is freely granted, provided that this notice
9
 * is preserved.
10
 * ====================================================
11
 */
12
13
 
14
 * ceil(x)
15
 * Return x rounded toward -inf to integral value
16
 * Method:
17
 *	Bit twiddling.
18
 * Exception:
19
 *	Inexact flag raised if x not equal to ceil(x).
20
 */
21
22
 
23
24
 
25
26
 
27
static const double huge = 1.0e300;
28
#else
29
static double huge = 1.0e300;
30
#endif
31
32
 
33
	double ceil(double x)
34
#else
35
	double ceil(x)
36
	double x;
37
#endif
38
{
39
	__int32_t i0,i1,j0;
40
	__uint32_t i,j;
41
	EXTRACT_WORDS(i0,i1,x);
42
	j0 = ((i0>>20)&0x7ff)-0x3ff;
43
	if(j0<20) {
44
	    if(j0<0) { 	/* raise inexact if x != 0 */
45
		if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
46
		    if(i0<0) {i0=0x80000000;i1=0;}
47
		    else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
48
		}
49
	    } else {
50
		i = (0x000fffff)>>j0;
51
		if(((i0&i)|i1)==0) return x; /* x is integral */
52
		if(huge+x>0.0) {	/* raise inexact flag */
53
		    if(i0>0) i0 += (0x00100000)>>j0;
54
		    i0 &= (~i); i1=0;
55
		}
56
	    }
57
	} else if (j0>51) {
58
	    if(j0==0x400) return x+x;	/* inf or NaN */
59
	    else return x;		/* x is integral */
60
	} else {
61
	    i = ((__uint32_t)(0xffffffff))>>(j0-20);
62
	    if((i1&i)==0) return x;	/* x is integral */
63
	    if(huge+x>0.0) { 		/* raise inexact flag */
64
		if(i0>0) {
65
		    if(j0==20) i0+=1;
66
		    else {
67
			j = i1 + (1<<(52-j0));
68
			if(j
69
			i1 = j;
70
		    }
71
		}
72
		i1 &= (~i);
73
	    }
74
	}
75
	INSERT_WORDS(x,i0,i1);
76
	return x;
77
}
78
79
 
80
>