long double _IEEE_REMAINDER_D_H(long double argx, float argy) { union _ieee_ldouble { long double ldword; long lword[2]; }; long double __remainder_d(long double x, long double y); long double y_val; int xfpclas = _fpclassifyl(argx); int yfpclas = _fpclassifyf(argy); if ((xfpclas == FP_INFINITE) || yfpclas == FP_ZERO) { union _ieee_ldouble xval; int j; xval.ldword = _DBL_NaN; /* need to emit invalid exception */ j = FE_INVALID; feraiseexcept(j); return(xval.ldword); } y_val = (long double) argy; return(__remainder_d(argx, y_val)); }
double _IEEE_REMAINDER_H_R(float argx, double argy) { union _ieee_double { double dword; long lword; }; double __remainder_r(double x, double y); double x_val; int xfpclas = _fpclassifyf(argx); int yfpclas = _fpclassify(argy); if ((xfpclas == FP_INFINITE) || yfpclas == FP_ZERO) { union _ieee_double x_val; int j; x_val.dword = _SGL_NaN; /* need to emit invalid exception */ j = FE_INVALID; feraiseexcept(j); return(x_val.dword); } x_val = (double) argx; return(__remainder_r(x_val, argy)); }
float _IEEE_BINARY_SCALE_H_I4(float x, short n) { /* Union defined to work with IEEE 64-bit floating point. */ union _ieee_double { float dword; short lword; unsigned short ulword; struct { unsigned int sign : 1; unsigned int exponent : IEEE_32_EXPO_BITS; unsigned int mantissa : IEEE_32_MANT_BITS; } parts; }; int fp_class = _fpclassifyf(x); if (fp_class==FP_NORMAL) { union _ieee_double x_val; long exponent; x_val.dword = x; exponent = x_val.parts.exponent + (int) n; if (exponent <= 0) { int j; long full_mantissa = x_val.parts.mantissa; /* need to emit underflow exception */ j = FE_UNDERFLOW; feraiseexcept(j); /* add implicit bit to mantissa */ full_mantissa |= IEEE_32_IMPLICIT_BIT; /* shift mantissa over by exponent remaining */ full_mantissa >>= -exponent + 1; /* return denormal number */ x_val.parts.exponent = 0; x_val.parts.mantissa = full_mantissa; } else if ((exponent>>IEEE_32_EXPO_BITS) != 0) {
float _IEEE_EXPONENT_H_H(float x) { union _ieee_float { float dword; int lword; struct { #if defined(_LITTLE_ENDIAN) unsigned int mantissa : IEEE_32_MANT_BITS; unsigned int exponent : IEEE_32_EXPO_BITS; unsigned int sign : 1; #else unsigned int sign : 1; unsigned int exponent : IEEE_32_EXPO_BITS; unsigned int mantissa : IEEE_32_MANT_BITS; #endif } parts; }; switch (_fpclassifyf(x)) { case FP_NAN: return(x); case FP_INFINITE: { union _ieee_float x_val; x_val.lword = IEEE_32_INFINITY; return(x_val.dword); } case FP_NORMAL: { union _ieee_float x_val; x_val.dword = x; return(x_val.parts.exponent - IEEE_32_EXPO_BIAS); } case FP_SUBNORMAL: { union _ieee_float x_val; x_val.dword = x; /* _leadz returns number of zeros before first 1 * in mantissa. Add 8 to exclude exponent bits, * but count sign bit since implicit bit needs to * be counted. */ return(-IEEE_32_EXPO_BIAS - (_leadz(x_val.parts.mantissa) - 32) + IEEE_32_EXPO_BITS); } case FP_ZERO: { union _ieee_float x_val; int j; /* raise divide-by-zero exception */ j = FE_DIVBYZERO; feraiseexcept(j); /* return negative infinity */ x_val.dword = IEEE_32_INFINITY; x_val.parts.sign = 1; return(x_val.dword); } } }
double _IEEE_NEXT_AFTER_R_H(double x, float y) { /* Union defined to work with IEEE 64-bit floating point. */ union _ieee_double { double dword; long long lword; struct { #if __BYTE_ORDER == __LITTLE_ENDIAN unsigned int mantissa : IEEE_64_MANT_BITS; unsigned int exponent : IEEE_64_EXPO_BITS; unsigned int sign : 1; #else unsigned int sign : 1; unsigned int exponent : IEEE_64_EXPO_BITS; unsigned int mantissa : IEEE_64_MANT_BITS; #endif } parts; }; int xfpclas = _fpclassify(x); int yfpclas = _fpclassifyf(y); if (xfpclas == FP_NAN) { return x; } else if (yfpclas == FP_NAN) { union _ieee_double x_val; x_val.dword = _SGL_NaN; return(x_val.dword); } else if (xfpclas == FP_ZERO && yfpclas == FP_ZERO) { return x; } else if (xfpclas == FP_INFINITE) { return x; } else if (x == (double) y) { return x; } else if (xfpclas == FP_ZERO) { union _ieee_double x_val; x_val.dword = DBL_MIN; x_val.parts.sign = x > (double) y; /* return smallest normal number */ return(x_val.dword); } else { /* first argument is normal or denormal */ union _ieee_double x_val; int j; int resfpclas; x_val.dword = x; /* move one bit in the correct direction. ** Because of the way the implicit bit works, ** the exponent field is handled correctly. */ if (x > 0) { x_val.lword += (x > (double) y) ? -1 : 1; } else { x_val.lword += (x > (double) y) ? 1 : -1; } /* test for underflow or overflow */ if (_isnormal(x_val.dword)) return(x_val.dword); /* * Raise overflow exception for infinite result and * underflow exception for too small result. Raise * inexact exception for both cases. Allow subnormal * values to return without exception. */ resfpclas = _fpclassify(x_val.dword); if (resfpclas == FP_INFINITE) { j = FE_OVERFLOW; feraiseexcept(j); } else if (resfpclas == FP_ZERO) { j = FE_UNDERFLOW; feraiseexcept(j); } else { return(x_val.dword); } j = FE_INEXACT; feraiseexcept(j); return(x_val.dword); } }
float _IEEE_REMAINDER_H_H(float argx, float argy) { union _ieee_flot { float fpword; unsigned int usword; int int32; struct { unsigned int sign : 1; unsigned int exponent : IEEE_32_EXPO_BITS; unsigned int mantissa : IEEE_32_MANT_BITS; } parts; }; union _ieee_flot x_val, y_val, nearint, tdiv, evenchk, tmp, res; unsigned int even_x = 0X00000001; int xfpclas = _fpclassifyf(argx); int yfpclas = _fpclassifyf(argy); x_val.fpword = argx; y_val.fpword = argy; if ((xfpclas == FP_INFINITE) || yfpclas == FP_ZERO) { union _ieee_flot x_val; int j; x_val.fpword = _HALF_NaN; /* need to emit invalid exception */ j = FE_INVALID; feraiseexcept(j); return(x_val.fpword); } tdiv.fpword = argx / argy; tmp.usword = tdiv.usword & (~IEEE_32_SIGN_BIT); /* check for 2**23 or greater = already integer */ if (tmp.fpword < 8388608) { /* calculate fraction */ evenchk.fpword = tdiv.fpword - (float)((int)tdiv.fpword); if (tdiv.fpword < 0.0) { nearint.int32 = (int) (tdiv.fpword - 0.5); if ((evenchk.fpword == -0.5) && ((nearint.usword & even_x) != 0)) nearint.int32 += 1; } else { nearint.int32 = (int) (tdiv.fpword + 0.5); if ((evenchk.fpword == 0.5) && ((nearint.usword & even_x) != 0)) nearint.int32 -= 1; } tdiv.fpword = (float) nearint.int32; } /* algorithm for ieee in 64-bits for x - (x/y)*y. */ res.fpword = (float) ((double) x_val.fpword - ((double) tdiv.fpword * (double) y_val.fpword)); if (res.fpword == 0.0) res.usword= res.usword | (x_val.usword & IEEE_32_SIGN_BIT); return(res.fpword); }
long double _IEEE_EXPONENT_D_H(float x) { /* Union defined to work with IEEE 128 bit floating point. */ union _ieee_ldouble { long double dword; long lword[2]; struct { unsigned int sign : 1; unsigned int exponent : IEEE_128_EXPO_BITS; unsigned int mantissa_up : IEEE_128_MANT_BITS_UP; unsigned int mantissa_low : IEEE_128_MANT_BITS_LOW; } lparts; }; union _ieee_fdouble { float dwrd; int lwrd; struct { #if __BYTE_ORDER == __LITTLE_ENDIAN unsigned int mantissa : IEEE_32_MANT_BITS; unsigned int expon : IEEE_32_EXPO_BITS; unsigned int sgn : 1; #else unsigned int sgn : 1; unsigned int expon : IEEE_32_EXPO_BITS; unsigned int mantissa : IEEE_32_MANT_BITS; #endif } parts; }; switch (_fpclassifyf(x)) { case FP_NAN: { union _ieee_ldouble x_val; x_val.dword = _DBL_NaN; return(x_val.dword); } case FP_INFINITE: { union _ieee_ldouble x_val; x_val.lword[0] = INFINITY_128_UP; x_val.lword[1] = INFINITY_128_LOW; x_val.lparts.sign = 0; return(x_val.dword); } case FP_NORMAL: { union _ieee_fdouble x_val; x_val.dwrd = x; return(x_val.parts.expon - IEEE_32_EXPO_BIAS); } case FP_SUBNORMAL: { union _ieee_fdouble x_val; int y; x_val.dwrd = x; /* _leadz returns number of zeros before first 1 * in mantissa. Add IEEE_32_EXPO_BITS to exclude * exponent bits, but count sign bit since * implicit bit needs to be counted. */ return(-IEEE_32_EXPO_BIAS - (_leadz(x_val.parts.mantissa) - 32) + IEEE_32_EXPO_BITS); } case FP_ZERO: { int j; union _ieee_ldouble x_val; /* raise divide-by-zero exception */ j = FE_DIVBYZERO; feraiseexcept(j); /* return negative infinity */ x_val.lword[0] = INFINITY_128_UP; x_val.lword[1] = INFINITY_128_LOW; x_val.lparts.sign = 1; return(x_val.dword); } } }
float _IEEE_NEXT_AFTER_H_R(float x, double y) { /* Union defined to work with IEEE 32-bit floating point. */ union _ieee_double { float dword; short lword; struct { unsigned int sign : 1; unsigned int exponent : IEEE_32_EXPO_BITS; unsigned int mantissa : IEEE_32_MANT_BITS; } parts; }; int xfpclas = _fpclassifyf(x); int yfpclas = _fpclassify(y); if (xfpclas == FP_NAN) { return x; } else if (yfpclas == FP_NAN) { union _ieee_double x_val; x_val.dword = _HALF_NaN; return(x_val.dword); } else if (xfpclas == FP_ZERO && yfpclas == FP_ZERO) { return x; } else if (xfpclas == FP_INFINITE) { return x; } else if ((double) x == y) { return x; } else if (xfpclas == FP_ZERO) { union _ieee_double x_val; x_val.dword = FLT_MIN; x_val.parts.sign = (double) x > y; /* return smallest normal number */ return(x_val.dword); } else { /* first argument is normal or denormal */ union _ieee_double x_val; int j; int resfpclas; x_val.dword = x; /* move one bit in the correct direction. ** Because of the way the implicit bit works, ** the exponent field is handled correctly. */ if (x > 0) { x_val.lword += ((double) x > y) ? -1 : 1; } else { x_val.lword += ((double) x > y) ? 1 : -1; } /* test for underflow or overflow */ if (_isnormalf(x_val.dword)) return(x_val.dword); /* * Raise overflow exception for infinite result and * underflow exception for too small result. Raise * inexact exception for both cases. Allow subnormal * values to return without exception. */ resfpclas = _fpclassifyf(x_val.dword); if (resfpclas == FP_INFINITE) { j = FE_OVERFLOW; feraiseexcept(j); } else if (resfpclas == FP_ZERO) { j = FE_UNDERFLOW; feraiseexcept(j); } else { return(x_val.dword); } j = FE_INEXACT; feraiseexcept(j); return(x_val.dword); } }