1 /* Copyright (c) 2008-2011 Freescale Semiconductor, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of Freescale Semiconductor nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #if defined(NCSW_LINUX) && defined(__KERNEL__)
38 #include <linux/math.h>
40 #elif defined(__MWERKS__)
41 #define LOW(x) ( sizeof(x)==8 ? *(1+(int32_t*)&x) : (*(int32_t*)&x))
42 #define HIGH(x) (*(int32_t*)&x)
43 #define ULOW(x) ( sizeof(x)==8 ? *(1+(uint32_t*)&x) : (*(uint32_t*)&x))
44 #define UHIGH(x) (*(uint32_t*)&x)
46 static const double big = 1.0e300;
48 /* Macro for checking if a number is a power of 2 */
49 static __inline__ double ceil(double x)
51 int32_t i0,i1,j0; /*- cc 020130 -*/
52 uint32_t i,j; /*- cc 020130 -*/
55 j0 = ((i0>>20)&0x7ff)-0x3ff;
57 if(j0<0) { /* raise inexact if x != 0 */
58 if(big+x>0.0) {/* return 0*sign(x) if |x|<1 */
59 if(i0<0) {i0=0x80000000;i1=0;}
60 else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
63 i = (uint32_t)(0x000fffff)>>j0;
64 if(((i0&i)|i1)==0) return x; /* x is integral */
65 if(big+x>0.0) { /* raise inexact flag */
66 if(i0>0) i0 += (0x00100000)>>j0;
71 if(j0==0x400) return x+x; /* inf or NaN */
72 else return x; /* x is integral */
74 i = ((uint32_t)(0xffffffff))>>(j0-20); /*- cc 020130 -*/
75 if((i1&i)==0) return x; /* x is integral */
76 if(big+x>0.0) { /* raise inexact flag */
80 j = (uint32_t)(i1 + (1<<(52-j0)));
81 if(j<i1) i0+=1; /* got a carry */
95 #endif /* defined(NCSW_LINUX) && defined(__KERNEL__) */
98 #endif /* __MATH_EXT_H */