[BACK]Return to s_ceilf.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libm / src

Annotation of src/lib/libm/src/s_ceilf.c, Revision 1.6

1.1       jtc         1: /* s_ceilf.c -- float version of s_ceil.c.
                      2:  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
                      3:  */
                      4:
                      5: /*
                      6:  * ====================================================
                      7:  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
                      8:  *
                      9:  * Developed at SunPro, a Sun Microsystems, Inc. business.
                     10:  * Permission to use, copy, modify, and distribute this
1.6     ! simonb     11:  * software is freely granted, provided that this notice
1.1       jtc        12:  * is preserved.
                     13:  * ====================================================
                     14:  */
                     15:
1.5       lukem      16: #include <sys/cdefs.h>
1.3       jtc        17: #if defined(LIBM_SCCS) && !defined(lint)
1.6     ! simonb     18: __RCSID("$NetBSD: s_ceilf.c,v 1.5 1997/10/09 11:31:19 lukem Exp $");
1.1       jtc        19: #endif
                     20:
                     21: #include "math.h"
                     22: #include "math_private.h"
                     23:
                     24: #ifdef __STDC__
                     25: static const float huge = 1.0e30;
                     26: #else
                     27: static float huge = 1.0e30;
                     28: #endif
                     29:
                     30: #ifdef __STDC__
                     31:        float ceilf(float x)
                     32: #else
                     33:        float ceilf(x)
                     34:        float x;
                     35: #endif
                     36: {
1.2       jtc        37:        int32_t i0,j0;
                     38:        u_int32_t i;
                     39:
1.1       jtc        40:        GET_FLOAT_WORD(i0,x);
                     41:        j0 = ((i0>>23)&0xff)-0x7f;
                     42:        if(j0<23) {
                     43:            if(j0<0) {  /* raise inexact if x != 0 */
                     44:                if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
1.6     ! simonb     45:                    if(i0<0) {i0=0x80000000;}
1.1       jtc        46:                    else if(i0!=0) { i0=0x3f800000;}
                     47:                }
                     48:            } else {
                     49:                i = (0x007fffff)>>j0;
                     50:                if((i0&i)==0) return x; /* x is integral */
                     51:                if(huge+x>(float)0.0) { /* raise inexact flag */
                     52:                    if(i0>0) i0 += (0x00800000)>>j0;
                     53:                    i0 &= (~i);
                     54:                }
                     55:            }
                     56:        } else {
                     57:            if(j0==0x80) return x+x;    /* inf or NaN */
                     58:            else return x;              /* x is integral */
                     59:        }
                     60:        SET_FLOAT_WORD(x,i0);
                     61:        return x;
                     62: }

CVSweb <webmaster@jp.NetBSD.org>