Back to index

glibc  2.9
s_nextafterl.c
Go to the documentation of this file.
00001 /* s_nextafterl.c -- long double version of s_nextafter.c.
00002  * Special version for i387.
00003  * Conversion to long double by Ulrich Drepper,
00004  * Cygnus Support, drepper@cygnus.com.
00005  */
00006 
00007 /*
00008  * ====================================================
00009  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00010  *
00011  * Developed at SunPro, a Sun Microsystems, Inc. business.
00012  * Permission to use, copy, modify, and distribute this
00013  * software is freely granted, provided that this notice
00014  * is preserved.
00015  * ====================================================
00016  */
00017 
00018 #if defined(LIBM_SCCS) && !defined(lint)
00019 static char rcsid[] = "$NetBSD: $";
00020 #endif
00021 
00022 /* IEEE functions
00023  *     nextafterl(x,y)
00024  *     return the next machine floating-point number of x in the
00025  *     direction toward y.
00026  *   Special cases:
00027  */
00028 
00029 #include "math.h"
00030 #include <math_private.h>
00031 
00032 #ifdef __STDC__
00033        long double __nextafterl(long double x, long double y)
00034 #else
00035        long double __nextafterl(x,y)
00036        long double x,y;
00037 #endif
00038 {
00039        u_int32_t hx,hy,ix,iy;
00040        u_int32_t lx,ly;
00041        int32_t esx,esy;
00042 
00043        GET_LDOUBLE_WORDS(esx,hx,lx,x);
00044        GET_LDOUBLE_WORDS(esy,hy,ly,y);
00045        ix = esx&0x7fff;            /* |x| */
00046        iy = esy&0x7fff;            /* |y| */
00047 
00048        /* Intel's extended format has the normally implicit 1 explicit
00049           present.  Sigh!  */
00050        if(((ix==0x7fff)&&(((hx&0x7fffffff)|lx)!=0)) ||   /* x is nan */
00051           ((iy==0x7fff)&&(((hy&0x7fffffff)|ly)!=0)))     /* y is nan */
00052           return x+y;
00053        if(x==y) return y;          /* x=y, return y */
00054        if((ix|hx|lx)==0) {                /* x == 0 */
00055            long double u;
00056            SET_LDOUBLE_WORDS(x,esy&0x8000,0,1);/* return +-minsubnormal */
00057            u = math_opt_barrier (x);
00058            u = u * u;
00059            math_force_eval (u);           /* raise underflow flag */
00060            return x;
00061        }
00062        if(esx>=0) {                /* x > 0 */
00063            if(esx>esy||((esx==esy) && (hx>hy||((hx==hy)&&(lx>ly))))) {
00064              /* x > y, x -= ulp */
00065               if(lx==0) {
00066                   if (hx <= 0x80000000) {
00067                     if (esx == 0) {
00068                      --hx;
00069                     } else {
00070                      esx -= 1;
00071                      hx = hx - 1;
00072                      if (esx > 0)
00073                        hx |= 0x80000000;
00074                     }
00075                   } else
00076                     hx -= 1;
00077               }
00078               lx -= 1;
00079            } else {                       /* x < y, x += ulp */
00080               lx += 1;
00081               if(lx==0) {
00082                   hx += 1;
00083                   if (hx==0 || (esx == 0 && hx == 0x80000000)) {
00084                      esx += 1;
00085                      hx |= 0x80000000;
00086                   }
00087               }
00088            }
00089        } else {                           /* x < 0 */
00090            if(esy>=0||(esx>esy||((esx==esy)&&(hx>hy||((hx==hy)&&(lx>ly)))))){
00091              /* x < y, x -= ulp */
00092               if(lx==0) {
00093                   if (hx <= 0x80000000) {
00094                      esx -= 1;
00095                      hx = hx - 1;
00096                      if ((esx&0x7fff) > 0)
00097                        hx |= 0x80000000;
00098                   } else
00099                     hx -= 1;
00100               }
00101               lx -= 1;
00102            } else {                       /* x > y, x += ulp */
00103               lx += 1;
00104               if(lx==0) {
00105                   hx += 1;
00106                   if (hx==0 || (esx == 0xffff8000 && hx == 0x80000000)) {
00107                      esx += 1;
00108                      hx |= 0x80000000;
00109                   }
00110               }
00111            }
00112        }
00113        esy = esx&0x7fff;
00114        if(esy==0x7fff) return x+x; /* overflow  */
00115        if(esy==0) {
00116            long double u = x*x;           /* underflow */
00117            math_force_eval (u);           /* raise underflow flag */
00118        }
00119        SET_LDOUBLE_WORDS(x,esx,hx,lx);
00120        return x;
00121 }
00122 weak_alias (__nextafterl, nextafterl)
00123 strong_alias (__nextafterl, __nexttowardl)
00124 weak_alias (__nextafterl, nexttowardl)