^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Linux/PA-RISC Project (http://www.parisc-linux.org/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Floating-point emulation code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * BEGIN_DESC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * File:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * @(#) pa/spmath/sfsub.c $Revision: 1.1 $
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Purpose:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Single_subtract: subtract two single precision values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * External Interfaces:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * sgl_fsub(leftptr, rightptr, dstptr, status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Internal Interfaces:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Theory:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * <<please update with a overview of the operation of this file>>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * END_DESC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "float.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "sgl_float.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * Single_subtract: subtract two single precision values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) sgl_fsub(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) sgl_floating_point *leftptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) sgl_floating_point *rightptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) sgl_floating_point *dstptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned int *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) register unsigned int left, right, result, extent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) register unsigned int signless_upper_left, signless_upper_right, save;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) register int result_exponent, right_exponent, diff_exponent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) register int sign_save, jumpsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) register boolean inexact = FALSE, underflowtrap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* Create local copies of the numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) left = *leftptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) right = *rightptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /* A zero "save" helps discover equal operands (for later), *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * and is used in swapping operands (if needed). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) Sgl_xortointp1(left,right,/*to*/save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * check first operand for NaN's or infinity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if ((result_exponent = Sgl_exponent(left)) == SGL_INFINITY_EXPONENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (Sgl_iszero_mantissa(left))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (Sgl_isnotnan(right))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (Sgl_isinfinity(right) && save==0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * invalid since operands are same signed infinity's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) Set_invalidflag();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) Sgl_makequietnan(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *dstptr = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * return infinity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *dstptr = left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * is NaN; signaling or quiet?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (Sgl_isone_signaling(left))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* trap if INVALIDTRAP enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* make NaN quiet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) Set_invalidflag();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) Sgl_set_quiet(left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * is second operand a signaling NaN?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) else if (Sgl_is_signalingnan(right))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* trap if INVALIDTRAP enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* make NaN quiet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) Set_invalidflag();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) Sgl_set_quiet(right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *dstptr = right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * return quiet NaN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *dstptr = left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) } /* End left NaN or Infinity processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * check second operand for NaN's or infinity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (Sgl_isinfinity_exponent(right))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (Sgl_iszero_mantissa(right))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* return infinity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) Sgl_invert_sign(right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) *dstptr = right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * is NaN; signaling or quiet?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (Sgl_isone_signaling(right))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* trap if INVALIDTRAP enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* make NaN quiet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) Set_invalidflag();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) Sgl_set_quiet(right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * return quiet NaN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) *dstptr = right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) } /* End right NaN or Infinity processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* Invariant: Must be dealing with finite numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* Compare operands by removing the sign */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) Sgl_copytoint_exponentmantissa(left,signless_upper_left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) Sgl_copytoint_exponentmantissa(right,signless_upper_right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* sign difference selects sub or add operation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if(Sgl_ismagnitudeless(signless_upper_left,signless_upper_right))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* Set the left operand to the larger one by XOR swap *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * First finish the first word using "save" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) Sgl_xorfromintp1(save,right,/*to*/right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) Sgl_xorfromintp1(save,left,/*to*/left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) result_exponent = Sgl_exponent(left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) Sgl_invert_sign(left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* Invariant: left is not smaller than right. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if((right_exponent = Sgl_exponent(right)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* Denormalized operands. First look for zeroes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if(Sgl_iszero_mantissa(right))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* right is zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if(Sgl_iszero_exponentmantissa(left))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* Both operands are zeros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) Sgl_invert_sign(right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if(Is_rounding_mode(ROUNDMINUS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) Sgl_or_signs(left,/*with*/right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) Sgl_and_signs(left,/*with*/right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* Left is not a zero and must be the result. Trapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * underflows are signaled if left is denormalized. Result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * is always exact. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if( (result_exponent == 0) && Is_underflowtrap_enabled() )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* need to normalize results mantissa */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) sign_save = Sgl_signextendedsign(left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) Sgl_leftshiftby1(left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) Sgl_normalize(left,result_exponent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) Sgl_set_sign(left,/*using*/sign_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) Sgl_setwrapped_exponent(left,result_exponent,unfl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) *dstptr = left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* inexact = FALSE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return(UNDERFLOWEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) *dstptr = left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* Neither are zeroes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) Sgl_clear_sign(right); /* Exponent is already cleared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if(result_exponent == 0 )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* Both operands are denormalized. The result must be exact
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * and is simply calculated. A sum could become normalized and a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * difference could cancel to a true zero. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if( (/*signed*/int) save >= 0 )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) Sgl_subtract(left,/*minus*/right,/*into*/result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if(Sgl_iszero_mantissa(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if(Is_rounding_mode(ROUNDMINUS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) Sgl_setone_sign(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) Sgl_setzero_sign(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) *dstptr = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) Sgl_addition(left,right,/*into*/result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if(Sgl_isone_hidden(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) *dstptr = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if(Is_underflowtrap_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* need to normalize result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) sign_save = Sgl_signextendedsign(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) Sgl_leftshiftby1(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) Sgl_normalize(result,result_exponent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) Sgl_set_sign(result,/*using*/sign_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) Sgl_setwrapped_exponent(result,result_exponent,unfl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) *dstptr = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* inexact = FALSE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return(UNDERFLOWEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) *dstptr = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) right_exponent = 1; /* Set exponent to reflect different bias
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * with denomalized numbers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) Sgl_clear_signexponent_set_hidden(right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) Sgl_clear_exponent_set_hidden(left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) diff_exponent = result_exponent - right_exponent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * Special case alignment of operands that would force alignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * beyond the extent of the extension. A further optimization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * could special case this but only reduces the path length for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * infrequent case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if(diff_exponent > SGL_THRESHOLD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) diff_exponent = SGL_THRESHOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /* Align right operand by shifting to right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) Sgl_right_align(/*operand*/right,/*shifted by*/diff_exponent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /*and lower to*/extent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* Treat sum and difference of the operands separately. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if( (/*signed*/int) save >= 0 )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * Difference of the two operands. Their can be no overflow. A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * borrow can occur out of the hidden bit and force a post
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * normalization phase.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) Sgl_subtract_withextension(left,/*minus*/right,/*with*/extent,/*into*/result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if(Sgl_iszero_hidden(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* Handle normalization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* A straightforward algorithm would now shift the result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * and extension left until the hidden bit becomes one. Not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * all of the extension bits need participate in the shift.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * Only the two most significant bits (round and guard) are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * needed. If only a single shift is needed then the guard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * bit becomes a significant low order bit and the extension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * must participate in the rounding. If more than a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * shift is needed, then all bits to the right of the guard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * bit are zeros, and the guard bit may or may not be zero. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) sign_save = Sgl_signextendedsign(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) Sgl_leftshiftby1_withextent(result,extent,result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /* Need to check for a zero result. The sign and exponent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * fields have already been zeroed. The more efficient test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * of the full object can be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if(Sgl_iszero(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /* Must have been "x-x" or "x+(-x)". */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if(Is_rounding_mode(ROUNDMINUS)) Sgl_setone_sign(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) *dstptr = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) result_exponent--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /* Look to see if normalization is finished. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if(Sgl_isone_hidden(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if(result_exponent==0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /* Denormalized, exponent should be zero. Left operand *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * was normalized, so extent (guard, round) was zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) goto underflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /* No further normalization is needed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) Sgl_set_sign(result,/*using*/sign_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) Ext_leftshiftby1(extent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) goto round;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /* Check for denormalized, exponent should be zero. Left *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * operand was normalized, so extent (guard, round) was zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if(!(underflowtrap = Is_underflowtrap_enabled()) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) result_exponent==0) goto underflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /* Shift extension to complete one bit of normalization and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * update exponent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) Ext_leftshiftby1(extent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* Discover first one bit to determine shift amount. Use a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * modified binary search. We have already shifted the result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * one position right and still not found a one so the remainder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * of the extension must be zero and simplifies rounding. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* Scan bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) while(Sgl_iszero_hiddenhigh7mantissa(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) Sgl_leftshiftby8(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if((result_exponent -= 8) <= 0 && !underflowtrap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) goto underflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /* Now narrow it down to the nibble */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if(Sgl_iszero_hiddenhigh3mantissa(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /* The lower nibble contains the normalizing one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) Sgl_leftshiftby4(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if((result_exponent -= 4) <= 0 && !underflowtrap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) goto underflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* Select case were first bit is set (already normalized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * otherwise select the proper shift. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if((jumpsize = Sgl_hiddenhigh3mantissa(result)) > 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* Already normalized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if(result_exponent <= 0) goto underflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) Sgl_set_sign(result,/*using*/sign_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) Sgl_set_exponent(result,/*using*/result_exponent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) *dstptr = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) Sgl_sethigh4bits(result,/*using*/sign_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) switch(jumpsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) Sgl_leftshiftby3(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) result_exponent -= 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) Sgl_leftshiftby2(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) result_exponent -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) Sgl_leftshiftby1(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) result_exponent -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if(result_exponent > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) Sgl_set_exponent(result,/*using*/result_exponent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) *dstptr = result; /* Sign bit is already set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* Fixup potential underflows */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) underflow:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if(Is_underflowtrap_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) Sgl_set_sign(result,sign_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) Sgl_setwrapped_exponent(result,result_exponent,unfl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) *dstptr = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /* inexact = FALSE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return(UNDERFLOWEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * Since we cannot get an inexact denormalized result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * we can now return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) Sgl_right_align(result,/*by*/(1-result_exponent),extent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) Sgl_clear_signexponent(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) Sgl_set_sign(result,sign_save);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) *dstptr = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) } /* end if(hidden...)... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* Fall through and round */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) } /* end if(save >= 0)... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /* Add magnitudes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) Sgl_addition(left,right,/*to*/result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if(Sgl_isone_hiddenoverflow(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /* Prenormalization required. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) Sgl_rightshiftby1_withextent(result,extent,extent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) Sgl_arithrightshiftby1(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) result_exponent++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) } /* end if hiddenoverflow... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) } /* end else ...sub magnitudes... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) /* Round the result. If the extension is all zeros,then the result is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * exact. Otherwise round in the correct direction. No underflow is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * possible. If a postnormalization is necessary, then the mantissa is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * all zeros so no shift is needed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) round:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if(Ext_isnotzero(extent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) inexact = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) switch(Rounding_mode())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) case ROUNDNEAREST: /* The default. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if(Ext_isone_sign(extent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* at least 1/2 ulp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if(Ext_isnotzero_lower(extent) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) Sgl_isone_lowmantissa(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /* either exactly half way and odd or more than 1/2ulp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) Sgl_increment(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) case ROUNDPLUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if(Sgl_iszero_sign(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /* Round up positive results */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) Sgl_increment(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) case ROUNDMINUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if(Sgl_isone_sign(result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /* Round down negative results */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) Sgl_increment(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) case ROUNDZERO:;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* truncate is simple */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) } /* end switch... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if(Sgl_isone_hiddenoverflow(result)) result_exponent++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if(result_exponent == SGL_INFINITY_EXPONENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /* Overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if(Is_overflowtrap_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) Sgl_setwrapped_exponent(result,result_exponent,ovfl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) *dstptr = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (inexact)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (Is_inexacttrap_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return(OVERFLOWEXCEPTION | INEXACTEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) else Set_inexactflag();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return(OVERFLOWEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) Set_overflowflag();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) inexact = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) Sgl_setoverflow(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) else Sgl_set_exponent(result,result_exponent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) *dstptr = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if(inexact)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) if(Is_inexacttrap_enabled()) return(INEXACTEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) else Set_inexactflag();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }