Back to index

glibc  2.9
s_ceilf.c
Go to the documentation of this file.
00001 /* s_ceilf.c -- float version of s_ceil.c.
00002  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
00003  */
00004 
00005 /*
00006  * ====================================================
00007  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00008  *
00009  * Developed at SunPro, a Sun Microsystems, Inc. business.
00010  * Permission to use, copy, modify, and distribute this
00011  * software is freely granted, provided that this notice 
00012  * is preserved.
00013  * ====================================================
00014  */
00015 
00016 #if defined(LIBM_SCCS) && !defined(lint)
00017 static char rcsid[] = "$NetBSD: s_ceilf.c,v 1.4 1995/05/10 20:46:55 jtc Exp $";
00018 #endif
00019 
00020 #include "math.h"
00021 #include "math_private.h"
00022 
00023 #ifdef __STDC__
00024 static const float huge = 1.0e30;
00025 #else
00026 static float huge = 1.0e30;
00027 #endif
00028 
00029 #ifdef __STDC__
00030        float __ceilf(float x)
00031 #else
00032        float __ceilf(x)
00033        float x;
00034 #endif
00035 {
00036        int32_t i0,j0;
00037        u_int32_t i;
00038 
00039        GET_FLOAT_WORD(i0,x);
00040        j0 = ((i0>>23)&0xff)-0x7f;
00041        if(j0<23) {
00042            if(j0<0) {       /* raise inexact if x != 0 */
00043               if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
00044                   if(i0<0) {i0=0x80000000;} 
00045                   else if(i0!=0) { i0=0x3f800000;}
00046               }
00047            } else {
00048               i = (0x007fffff)>>j0;
00049               if((i0&i)==0) return x; /* x is integral */
00050               if(huge+x>(float)0.0) {     /* raise inexact flag */
00051                   if(i0>0) i0 += (0x00800000)>>j0;
00052                   i0 &= (~i);
00053               }
00054            }
00055        } else {
00056            if(j0==0x80) return x+x;       /* inf or NaN */
00057            else return x;          /* x is integral */
00058        }
00059        SET_FLOAT_WORD(x,i0);
00060        return x;
00061 }
00062 weak_alias (__ceilf, ceilf)