/* $NetBSD: s_nextafterl.c,v 1.6 2019/04/27 23:04:32 kamil Exp $ */ /* @(#)s_nextafter.c 5.1 93/09/24 */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * * Developed at SunPro, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #include __RCSID("$NetBSD: s_nextafterl.c,v 1.6 2019/04/27 23:04:32 kamil Exp $"); #include #include #include #ifdef __HAVE_LONG_DOUBLE #ifdef EXT_EXP_INFNAN #if LDBL_MAX_EXP != 0x4000 #error "Unsupported long double format" #endif #ifdef LDBL_IMPLICIT_NBIT #define LDBL_NBIT 0 #endif __strong_alias(nexttowardl, nextafterl) /* * IEEE functions * nextafterl(x,y) * return the next machine floating-point number of x in the * direction toward y. * Special cases: * If x == y, y shall be returned * If x or y is NaN, a NaN shall be returned */ long double nextafterl(long double x, long double y) { volatile long double t; union ieee_ext_u ux, uy; ux.extu_ld = x; uy.extu_ld = y; if ((ux.extu_exp == EXT_EXP_INFNAN && ((ux.extu_frach &~ LDBL_NBIT)|ux.extu_fracl) != 0) || (uy.extu_exp == EXT_EXP_INFNAN && ((uy.extu_frach &~ LDBL_NBIT)|uy.extu_fracl) != 0)) return x+y; /* x or y is nan */ if (x == y) return y; /* x=y, return y */ if (x == 0.0) { ux.extu_frach = 0; /* return +-minsubnormal */ ux.extu_fracl = 1; ux.extu_sign = uy.extu_sign; t = ux.extu_ld * ux.extu_ld; if (t == ux.extu_ld) return t; else return ux.extu_ld; /* raise underflow flag */ } if ((x>0.0) ^ (x