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