softfloat.c revision 178d85b8274f9ac82fb553c80760bbbb4044401c
/*============================================================================
Package, Release 2b.
Written by John R. Hauser. This work was made possible in part by the
International Computer Science Institute, located at Suite 600, 1947 Center
Street, Berkeley, California 94704. Funding was partially provided by the
National Science Foundation under grant MIP-9311980. The original version
of this code was written as part of a project to build a fixed-point vector
processor in collaboration with the University of California at Berkeley,
overseen by Profs. Nelson Morgan and John Wawrzynek. More information
is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
Derivative works are acceptable, even for commercial purposes, so long as
(1) the source code for the derivative work includes prominent notice that
the work is derivative, and (2) the source code includes prominent notice with
these four paragraphs for those parts of this code that are retained.
=============================================================================*/
#include "softfloat.h"
/*----------------------------------------------------------------------------
| Primitive arithmetic functions, including multi-word arithmetic, and
| division and square root approximations. (Can be specialized to target if
| desired.)
*----------------------------------------------------------------------------*/
#include "softfloat-macros.h"
/*----------------------------------------------------------------------------
| Functions and definitions to determine: (1) whether tininess for underflow
| is detected before or after rounding by default, (2) what (if anything)
| happens when exceptions are raised, (3) how signaling NaNs are distinguished
| from quiet NaNs, (4) the default generated quiet NaNs, and (5) how NaNs
| are propagated from function inputs to output. These details are target-
| specific.
*----------------------------------------------------------------------------*/
#include "softfloat-specialize.h"
{
}
{
}
#ifdef FLOATX80
{
}
#endif
/*----------------------------------------------------------------------------
| Takes a 64-bit fixed-point value `absZ' with binary point between bits 6
| and 7, and returns the properly rounded 32-bit integer corresponding to the
| input. If `zSign' is 1, the input is negated before being converted to an
| integer. Bit 63 of `absZ' must be zero. Ordinarily, the fixed-point input
| is simply rounded to an integer, with the inexact exception raised if the
| input cannot be represented exactly as an integer. However, if the fixed-
| point input is too large, the invalid exception is raised and the largest
| positive or negative integer is returned.
*----------------------------------------------------------------------------*/
{
int32 z;
roundIncrement = 0x40;
if ( ! roundNearestEven ) {
if ( roundingMode == float_round_to_zero ) {
roundIncrement = 0;
}
else {
roundIncrement = 0x7F;
if ( zSign ) {
}
else {
}
}
}
z = absZ;
if ( zSign ) z = - z;
}
return z;
}
/*----------------------------------------------------------------------------
| Takes the 128-bit fixed-point value formed by concatenating `absZ0' and
| `absZ1', with binary point between bits 63 and 64 (between the input words),
| and returns the properly rounded 64-bit integer corresponding to the input.
| If `zSign' is 1, the input is negated before being converted to an integer.
| Ordinarily, the fixed-point input is simply rounded to an integer, with
| the inexact exception raised if the input cannot be represented exactly as
| an integer. However, if the fixed-point input is too large, the invalid
| exception is raised and the largest positive or negative integer is
| returned.
*----------------------------------------------------------------------------*/
{
int64 z;
if ( ! roundNearestEven ) {
if ( roundingMode == float_round_to_zero ) {
increment = 0;
}
else {
if ( zSign ) {
}
else {
}
}
}
if ( increment ) {
++absZ0;
}
z = absZ0;
if ( zSign ) z = - z;
if ( z && ( ( z < 0 ) ^ zSign ) ) {
return
: LIT64( 0x7FFFFFFFFFFFFFFF );
}
return z;
}
/*----------------------------------------------------------------------------
| Returns the fraction bits of the single-precision floating-point value `a'.
*----------------------------------------------------------------------------*/
{
return float32_val(a) & 0x007FFFFF;
}
/*----------------------------------------------------------------------------
| Returns the exponent bits of the single-precision floating-point value `a'.
*----------------------------------------------------------------------------*/
{
}
/*----------------------------------------------------------------------------
| Returns the sign bit of the single-precision floating-point value `a'.
*----------------------------------------------------------------------------*/
{
return float32_val(a)>>31;
}
/*----------------------------------------------------------------------------
| Normalizes the subnormal single-precision floating-point value represented
| by the denormalized significand `aSig'. The normalized exponent and
| significand are stored at the locations pointed to by `zExpPtr' and
| `zSigPtr', respectively.
*----------------------------------------------------------------------------*/
static void
{
}
/*----------------------------------------------------------------------------
| Packs the sign `zSign', exponent `zExp', and significand `zSig' into a
| single-precision floating-point value, returning the result. After being
| shifted into the proper positions, the three fields are simply added
| together to form the result. This means that any integer portion of `zSig'
| will be added into the exponent. Since a properly normalized significand
| will have an integer portion equal to 1, the `zExp' input should be 1 less
| than the desired result exponent whenever `zSig' is a complete, normalized
| significand.
*----------------------------------------------------------------------------*/
{
return make_float32(
}
/*----------------------------------------------------------------------------
| Takes an abstract floating-point value having sign `zSign', exponent `zExp',
| and significand `zSig', and returns the proper single-precision floating-
| point value corresponding to the abstract input. Ordinarily, the abstract
| value is simply rounded and packed into the single-precision format, with
| the inexact exception raised if the abstract input cannot be represented
| exactly. However, if the abstract value is too large, the overflow and
| inexact exceptions are raised and an infinity or maximal finite value is
| returned. If the abstract value is too small, the input value is rounded to
| a subnormal number, and the underflow and inexact exceptions are raised if
| the abstract input cannot be represented exactly as a subnormal single-
| precision floating-point number.
| The input significand `zSig' has its binary point between bits 30
| and 29, which is 7 bits to the left of the usual location. This shifted
| significand must be normalized or smaller. If `zSig' is not normalized,
| `zExp' must be 0; in that case, the result returned is a subnormal number,
| and it must not require rounding. In the usual case that `zSig' is
| normalized, `zExp' must be 1 less than the ``true'' floating-point exponent.
| Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
roundIncrement = 0x40;
if ( ! roundNearestEven ) {
if ( roundingMode == float_round_to_zero ) {
roundIncrement = 0;
}
else {
roundIncrement = 0x7F;
if ( zSign ) {
}
else {
}
}
}
if ( ( 0xFD < zExp )
|| ( ( zExp == 0xFD )
) {
}
if ( zExp < 0 ) {
isTiny =
|| ( zExp < -1 )
zExp = 0;
}
}
}
/*----------------------------------------------------------------------------
| Takes an abstract floating-point value having sign `zSign', exponent `zExp',
| and significand `zSig', and returns the proper single-precision floating-
| point value corresponding to the abstract input. This routine is just like
| `roundAndPackFloat32' except that `zSig' does not have to be normalized.
| Bit 31 of `zSig' must be zero, and `zExp' must be 1 less than the ``true''
| floating-point exponent.
*----------------------------------------------------------------------------*/
static float32
{
}
/*----------------------------------------------------------------------------
| Returns the fraction bits of the double-precision floating-point value `a'.
*----------------------------------------------------------------------------*/
{
}
/*----------------------------------------------------------------------------
| Returns the exponent bits of the double-precision floating-point value `a'.
*----------------------------------------------------------------------------*/
{
}
/*----------------------------------------------------------------------------
| Returns the sign bit of the double-precision floating-point value `a'.
*----------------------------------------------------------------------------*/
{
return float64_val(a)>>63;
}
/*----------------------------------------------------------------------------
| Normalizes the subnormal double-precision floating-point value represented
| by the denormalized significand `aSig'. The normalized exponent and
| significand are stored at the locations pointed to by `zExpPtr' and
| `zSigPtr', respectively.
*----------------------------------------------------------------------------*/
static void
{
}
/*----------------------------------------------------------------------------
| Packs the sign `zSign', exponent `zExp', and significand `zSig' into a
| double-precision floating-point value, returning the result. After being
| shifted into the proper positions, the three fields are simply added
| together to form the result. This means that any integer portion of `zSig'
| will be added into the exponent. Since a properly normalized significand
| will have an integer portion equal to 1, the `zExp' input should be 1 less
| than the desired result exponent whenever `zSig' is a complete, normalized
| significand.
*----------------------------------------------------------------------------*/
{
return make_float64(
}
/*----------------------------------------------------------------------------
| Takes an abstract floating-point value having sign `zSign', exponent `zExp',
| and significand `zSig', and returns the proper double-precision floating-
| point value corresponding to the abstract input. Ordinarily, the abstract
| value is simply rounded and packed into the double-precision format, with
| the inexact exception raised if the abstract input cannot be represented
| exactly. However, if the abstract value is too large, the overflow and
| inexact exceptions are raised and an infinity or maximal finite value is
| returned. If the abstract value is too small, the input value is rounded
| to a subnormal number, and the underflow and inexact exceptions are raised
| if the abstract input cannot be represented exactly as a subnormal double-
| precision floating-point number.
| The input significand `zSig' has its binary point between bits 62
| and 61, which is 10 bits to the left of the usual location. This shifted
| significand must be normalized or smaller. If `zSig' is not normalized,
| `zExp' must be 0; in that case, the result returned is a subnormal number,
| and it must not require rounding. In the usual case that `zSig' is
| normalized, `zExp' must be 1 less than the ``true'' floating-point exponent.
| Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
roundIncrement = 0x200;
if ( ! roundNearestEven ) {
if ( roundingMode == float_round_to_zero ) {
roundIncrement = 0;
}
else {
roundIncrement = 0x3FF;
if ( zSign ) {
}
else {
}
}
}
if ( ( 0x7FD < zExp )
|| ( ( zExp == 0x7FD )
) {
}
if ( zExp < 0 ) {
isTiny =
|| ( zExp < -1 )
zExp = 0;
}
}
}
/*----------------------------------------------------------------------------
| Takes an abstract floating-point value having sign `zSign', exponent `zExp',
| and significand `zSig', and returns the proper double-precision floating-
| point value corresponding to the abstract input. This routine is just like
| `roundAndPackFloat64' except that `zSig' does not have to be normalized.
| Bit 63 of `zSig' must be zero, and `zExp' must be 1 less than the ``true''
| floating-point exponent.
*----------------------------------------------------------------------------*/
static float64
{
}
#ifdef FLOATX80
/*----------------------------------------------------------------------------
| Returns the fraction bits of the extended double-precision floating-point
| value `a'.
*----------------------------------------------------------------------------*/
{
return a.low;
}
/*----------------------------------------------------------------------------
| Returns the exponent bits of the extended double-precision floating-point
| value `a'.
*----------------------------------------------------------------------------*/
{
return a.high & 0x7FFF;
}
/*----------------------------------------------------------------------------
| Returns the sign bit of the extended double-precision floating-point value
| `a'.
*----------------------------------------------------------------------------*/
{
return a.high>>15;
}
/*----------------------------------------------------------------------------
| Normalizes the subnormal extended double-precision floating-point value
| represented by the denormalized significand `aSig'. The normalized exponent
| and significand are stored at the locations pointed to by `zExpPtr' and
| `zSigPtr', respectively.
*----------------------------------------------------------------------------*/
static void
{
}
/*----------------------------------------------------------------------------
| Packs the sign `zSign', exponent `zExp', and significand `zSig' into an
| extended double-precision floating-point value, returning the result.
*----------------------------------------------------------------------------*/
{
floatx80 z;
return z;
}
/*----------------------------------------------------------------------------
| Takes an abstract floating-point value having sign `zSign', exponent `zExp',
| and extended significand formed by the concatenation of `zSig0' and `zSig1',
| and returns the proper extended double-precision floating-point value
| corresponding to the abstract input. Ordinarily, the abstract value is
| rounded and packed into the extended double-precision format, with the
| inexact exception raised if the abstract input cannot be represented
| exactly. However, if the abstract value is too large, the overflow and
| inexact exceptions are raised and an infinity or maximal finite value is
| returned. If the abstract value is too small, the input value is rounded to
| a subnormal number, and the underflow and inexact exceptions are raised if
| the abstract input cannot be represented exactly as a subnormal extended
| double-precision floating-point number.
| If `roundingPrecision' is 32 or 64, the result is rounded to the same
| number of bits as single or double precision, respectively. Otherwise, the
| result is rounded to the full precision of the extended double-precision
| format.
| The input significand must be normalized or smaller. If the input
| significand is not normalized, `zExp' must be 0; in that case, the result
| returned is a subnormal number, and it must not require rounding. The
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
static floatx80
{
if ( roundingPrecision == 64 ) {
}
else if ( roundingPrecision == 32 ) {
}
else {
goto precision80;
}
if ( ! roundNearestEven ) {
if ( roundingMode == float_round_to_zero ) {
roundIncrement = 0;
}
else {
if ( zSign ) {
}
else {
}
}
}
if ( ( 0x7FFE < zExp )
) {
goto overflow;
}
if ( zExp <= 0 ) {
isTiny =
|| ( zExp < 0 )
zExp = 0;
zSig0 += roundIncrement;
}
}
}
zSig0 += roundIncrement;
if ( zSig0 < roundIncrement ) {
++zExp;
}
}
if ( ! roundNearestEven ) {
if ( roundingMode == float_round_to_zero ) {
increment = 0;
}
else {
if ( zSign ) {
}
else {
}
}
}
if ( ( 0x7FFE < zExp )
|| ( ( zExp == 0x7FFE )
&& increment
)
) {
roundMask = 0;
if ( ( roundingMode == float_round_to_zero )
) {
}
}
if ( zExp <= 0 ) {
isTiny =
|| ( zExp < 0 )
|| ! increment
zExp = 0;
if ( roundNearestEven ) {
}
else {
if ( zSign ) {
}
else {
}
}
if ( increment ) {
++zSig0;
zSig0 &=
}
}
}
if ( increment ) {
++zSig0;
if ( zSig0 == 0 ) {
++zExp;
}
else {
}
}
else {
}
}
/*----------------------------------------------------------------------------
| Takes an abstract floating-point value having sign `zSign', exponent
| `zExp', and significand formed by the concatenation of `zSig0' and `zSig1',
| and returns the proper extended double-precision floating-point value
| corresponding to the abstract input. This routine is just like
| `roundAndPackFloatx80' except that the input significand does not have to be
| normalized.
*----------------------------------------------------------------------------*/
static floatx80
{
if ( zSig0 == 0 ) {
zSig1 = 0;
zExp -= 64;
}
zExp -= shiftCount;
return
}
#endif
#ifdef FLOAT128
/*----------------------------------------------------------------------------
| Returns the least-significant 64 fraction bits of the quadruple-precision
| floating-point value `a'.
*----------------------------------------------------------------------------*/
{
return a.low;
}
/*----------------------------------------------------------------------------
| Returns the most-significant 48 fraction bits of the quadruple-precision
| floating-point value `a'.
*----------------------------------------------------------------------------*/
{
}
/*----------------------------------------------------------------------------
| Returns the exponent bits of the quadruple-precision floating-point value
| `a'.
*----------------------------------------------------------------------------*/
{
}
/*----------------------------------------------------------------------------
| Returns the sign bit of the quadruple-precision floating-point value `a'.
*----------------------------------------------------------------------------*/
{
return a.high>>63;
}
/*----------------------------------------------------------------------------
| Normalizes the subnormal quadruple-precision floating-point value
| represented by the denormalized significand formed by the concatenation of
| `aSig0' and `aSig1'. The normalized exponent is stored at the location
| pointed to by `zExpPtr'. The most significant 49 bits of the normalized
| significand are stored at the location pointed to by `zSig0Ptr', and the
| least significant 64 bits of the normalized significand are stored at the
| location pointed to by `zSig1Ptr'.
*----------------------------------------------------------------------------*/
static void
)
{
if ( aSig0 == 0 ) {
if ( shiftCount < 0 ) {
}
else {
*zSig1Ptr = 0;
}
}
else {
}
}
/*----------------------------------------------------------------------------
| Packs the sign `zSign', the exponent `zExp', and the significand formed
| by the concatenation of `zSig0' and `zSig1' into a quadruple-precision
| floating-point value, returning the result. After being shifted into the
| proper positions, the three fields `zSign', `zExp', and `zSig0' are simply
| added together to form the most significant 32 bits of the result. This
| means that any integer portion of `zSig0' will be added into the exponent.
| Since a properly normalized significand will have an integer portion equal
| to 1, the `zExp' input should be 1 less than the desired result exponent
| whenever `zSig0' and `zSig1' concatenated form a complete, normalized
| significand.
*----------------------------------------------------------------------------*/
{
float128 z;
return z;
}
/*----------------------------------------------------------------------------
| Takes an abstract floating-point value having sign `zSign', exponent `zExp',
| and extended significand formed by the concatenation of `zSig0', `zSig1',
| and `zSig2', and returns the proper quadruple-precision floating-point value
| corresponding to the abstract input. Ordinarily, the abstract value is
| simply rounded and packed into the quadruple-precision format, with the
| inexact exception raised if the abstract input cannot be represented
| exactly. However, if the abstract value is too large, the overflow and
| inexact exceptions are raised and an infinity or maximal finite value is
| returned. If the abstract value is too small, the input value is rounded to
| a subnormal number, and the underflow and inexact exceptions are raised if
| the abstract input cannot be represented exactly as a subnormal quadruple-
| precision floating-point number.
| The input significand must be normalized or smaller. If the input
| significand is not normalized, `zExp' must be 0; in that case, the result
| returned is a subnormal number, and it must not require rounding. In the
| usual case that the input significand is normalized, `zExp' must be 1 less
| than the ``true'' floating-point exponent. The handling of underflow and
*----------------------------------------------------------------------------*/
static float128
{
if ( ! roundNearestEven ) {
if ( roundingMode == float_round_to_zero ) {
increment = 0;
}
else {
if ( zSign ) {
}
else {
}
}
}
if ( ( 0x7FFD < zExp )
|| ( ( zExp == 0x7FFD )
&& eq128(
LIT64( 0x0001FFFFFFFFFFFF ),
LIT64( 0xFFFFFFFFFFFFFFFF ),
)
&& increment
)
) {
if ( ( roundingMode == float_round_to_zero )
) {
return
0x7FFE,
LIT64( 0x0000FFFFFFFFFFFF ),
LIT64( 0xFFFFFFFFFFFFFFFF )
);
}
}
if ( zExp < 0 ) {
isTiny =
|| ( zExp < -1 )
|| ! increment
|| lt128(
LIT64( 0x0001FFFFFFFFFFFF ),
LIT64( 0xFFFFFFFFFFFFFFFF )
);
zExp = 0;
if ( roundNearestEven ) {
}
else {
if ( zSign ) {
}
else {
}
}
}
}
if ( increment ) {
}
else {
}
}
/*----------------------------------------------------------------------------
| Takes an abstract floating-point value having sign `zSign', exponent `zExp',
| and significand formed by the concatenation of `zSig0' and `zSig1', and
| returns the proper quadruple-precision floating-point value corresponding
| to the abstract input. This routine is just like `roundAndPackFloat128'
| except that the input significand has fewer bits and does not have to be
| normalized. In all cases, `zExp' must be 1 less than the ``true'' floating-
| point exponent.
*----------------------------------------------------------------------------*/
static float128
{
if ( zSig0 == 0 ) {
zSig1 = 0;
zExp -= 64;
}
if ( 0 <= shiftCount ) {
zSig2 = 0;
}
else {
}
zExp -= shiftCount;
}
#endif
/*----------------------------------------------------------------------------
| Returns the result of converting the 32-bit two's complement integer `a'
| to the single-precision floating-point format. The conversion is performed
*----------------------------------------------------------------------------*/
{
if ( a == 0 ) return float32_zero;
zSign = ( a < 0 );
}
/*----------------------------------------------------------------------------
| Returns the result of converting the 32-bit two's complement integer `a'
| to the double-precision floating-point format. The conversion is performed
*----------------------------------------------------------------------------*/
{
if ( a == 0 ) return float64_zero;
zSign = ( a < 0 );
}
#ifdef FLOATX80
/*----------------------------------------------------------------------------
| Returns the result of converting the 32-bit two's complement integer `a'
| to the extended double-precision floating-point format. The conversion
| Arithmetic.
*----------------------------------------------------------------------------*/
{
if ( a == 0 ) return packFloatx80( 0, 0, 0 );
zSign = ( a < 0 );
}
#endif
#ifdef FLOAT128
/*----------------------------------------------------------------------------
| Returns the result of converting the 32-bit two's complement integer `a' to
| the quadruple-precision floating-point format. The conversion is performed
*----------------------------------------------------------------------------*/
{
if ( a == 0 ) return packFloat128( 0, 0, 0, 0 );
zSign = ( a < 0 );
}
#endif
/*----------------------------------------------------------------------------
| Returns the result of converting the 64-bit two's complement integer `a'
| to the single-precision floating-point format. The conversion is performed
*----------------------------------------------------------------------------*/
{
if ( a == 0 ) return float32_zero;
zSign = ( a < 0 );
if ( 0 <= shiftCount ) {
}
else {
shiftCount += 7;
if ( shiftCount < 0 ) {
}
else {
absA <<= shiftCount;
}
}
}
{
if ( a == 0 ) return float32_zero;
if ( 0 <= shiftCount ) {
}
else {
shiftCount += 7;
if ( shiftCount < 0 ) {
shift64RightJamming( a, - shiftCount, &a );
}
else {
a <<= shiftCount;
}
}
}
/*----------------------------------------------------------------------------
| Returns the result of converting the 64-bit two's complement integer `a'
| to the double-precision floating-point format. The conversion is performed
*----------------------------------------------------------------------------*/
{
if ( a == 0 ) return float64_zero;
}
zSign = ( a < 0 );
}
{
if ( a == 0 ) return float64_zero;
}
#ifdef FLOATX80
/*----------------------------------------------------------------------------
| Returns the result of converting the 64-bit two's complement integer `a'
| to the extended double-precision floating-point format. The conversion
| Arithmetic.
*----------------------------------------------------------------------------*/
{
if ( a == 0 ) return packFloatx80( 0, 0, 0 );
zSign = ( a < 0 );
}
#endif
#ifdef FLOAT128
/*----------------------------------------------------------------------------
| Returns the result of converting the 64-bit two's complement integer `a' to
| the quadruple-precision floating-point format. The conversion is performed
*----------------------------------------------------------------------------*/
{
if ( a == 0 ) return packFloat128( 0, 0, 0, 0 );
zSign = ( a < 0 );
if ( 64 <= shiftCount ) {
zSig1 = 0;
shiftCount -= 64;
}
else {
zSig0 = 0;
}
}
#endif
/*----------------------------------------------------------------------------
| Returns the result of converting the single-precision floating-point value
| `a' to the 32-bit two's complement integer format. The conversion is
| Arithmetic---which means in particular that the conversion is rounded
| according to the current rounding mode. If `a' is a NaN, the largest
| positive integer is returned. Otherwise, if the conversion overflows, the
| largest integer with the same sign as `a' is returned.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
aSig64 <<= 32;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the single-precision floating-point value
| `a' to the 32-bit two's complement integer format. The conversion is
| Arithmetic, except that the conversion is always rounded toward zero.
| If `a' is a NaN, the largest positive integer is returned. Otherwise, if
| the conversion overflows, the largest integer with the same sign as `a' is
| returned.
*----------------------------------------------------------------------------*/
{
int32 z;
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
if ( 0 <= shiftCount ) {
if ( float32_val(a) != 0xCF000000 ) {
}
return (sbits32) 0x80000000;
}
else if ( aExp <= 0x7E ) {
return 0;
}
z = aSig>>( - shiftCount );
}
if ( aSign ) z = - z;
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the single-precision floating-point value
| `a' to the 64-bit two's complement integer format. The conversion is
| Arithmetic---which means in particular that the conversion is rounded
| according to the current rounding mode. If `a' is a NaN, the largest
| positive integer is returned. Otherwise, if the conversion overflows, the
| largest integer with the same sign as `a' is returned.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
if ( shiftCount < 0 ) {
return LIT64( 0x7FFFFFFFFFFFFFFF );
}
}
aSig64 <<= 40;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the single-precision floating-point value
| `a' to the 64-bit two's complement integer format. The conversion is
| Arithmetic, except that the conversion is always rounded toward zero. If
| `a' is a NaN, the largest positive integer is returned. Otherwise, if the
| conversion overflows, the largest integer with the same sign as `a' is
| returned.
*----------------------------------------------------------------------------*/
{
int64 z;
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
if ( 0 <= shiftCount ) {
if ( float32_val(a) != 0xDF000000 ) {
return LIT64( 0x7FFFFFFFFFFFFFFF );
}
}
}
else if ( aExp <= 0x7E ) {
return 0;
}
aSig64 <<= 40;
z = aSig64>>( - shiftCount );
}
if ( aSign ) z = - z;
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the single-precision floating-point value
| `a' to the double-precision floating-point format. The conversion is
| Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
if ( aExp == 0xFF ) {
}
if ( aExp == 0 ) {
--aExp;
}
}
#ifdef FLOATX80
/*----------------------------------------------------------------------------
| Returns the result of converting the single-precision floating-point value
| `a' to the extended double-precision floating-point format. The conversion
| Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
if ( aExp == 0xFF ) {
}
if ( aExp == 0 ) {
}
aSig |= 0x00800000;
}
#endif
#ifdef FLOAT128
/*----------------------------------------------------------------------------
| Returns the result of converting the single-precision floating-point value
| `a' to the double-precision floating-point format. The conversion is
| Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
if ( aExp == 0xFF ) {
}
if ( aExp == 0 ) {
--aExp;
}
}
#endif
/*----------------------------------------------------------------------------
| Rounds the single-precision floating-point value `a' to an integer, and
| returns the result as a single-precision floating-point value. The
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
bits32 z;
aExp = extractFloat32Exp( a );
if ( 0x96 <= aExp ) {
return propagateFloat32NaN( a, a STATUS_VAR );
}
return a;
}
if ( aExp <= 0x7E ) {
aSign = extractFloat32Sign( a );
switch ( STATUS(float_rounding_mode) ) {
case float_round_nearest_even:
}
break;
case float_round_down:
case float_round_up:
}
return packFloat32( aSign, 0, 0 );
}
lastBitMask = 1;
z = float32_val(a);
if ( roundingMode == float_round_nearest_even ) {
z += lastBitMask>>1;
if ( ( z & roundBitsMask ) == 0 ) z &= ~ lastBitMask;
}
else if ( roundingMode != float_round_to_zero ) {
z += roundBitsMask;
}
}
z &= ~ roundBitsMask;
return make_float32(z);
}
/*----------------------------------------------------------------------------
| Returns the result of adding the absolute values of the single-precision
| floating-point values `a' and `b'. If `zSign' is 1, the sum is negated
| before being returned. `zSign' is ignored if the result is a NaN.
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
bSig = extractFloat32Frac( b );
bExp = extractFloat32Exp( b );
aSig <<= 6;
bSig <<= 6;
if ( 0 < expDiff ) {
if ( aExp == 0xFF ) {
return a;
}
if ( bExp == 0 ) {
--expDiff;
}
else {
bSig |= 0x20000000;
}
}
else if ( expDiff < 0 ) {
if ( bExp == 0xFF ) {
}
if ( aExp == 0 ) {
++expDiff;
}
else {
aSig |= 0x20000000;
}
}
else {
if ( aExp == 0xFF ) {
return a;
}
goto roundAndPack;
}
aSig |= 0x20000000;
--zExp;
++zExp;
}
}
/*----------------------------------------------------------------------------
| Returns the result of subtracting the absolute values of the single-
| precision floating-point values `a' and `b'. If `zSign' is 1, the
| difference is negated before being returned. `zSign' is ignored if the
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
bSig = extractFloat32Frac( b );
bExp = extractFloat32Exp( b );
aSig <<= 7;
bSig <<= 7;
if ( 0 < expDiff ) goto aExpBigger;
if ( expDiff < 0 ) goto bExpBigger;
if ( aExp == 0xFF ) {
return float32_default_nan;
}
if ( aExp == 0 ) {
aExp = 1;
bExp = 1;
}
if ( bExp == 0xFF ) {
}
if ( aExp == 0 ) {
++expDiff;
}
else {
aSig |= 0x40000000;
}
bSig |= 0x40000000;
zSign ^= 1;
goto normalizeRoundAndPack;
if ( aExp == 0xFF ) {
return a;
}
if ( bExp == 0 ) {
--expDiff;
}
else {
bSig |= 0x40000000;
}
aSig |= 0x40000000;
--zExp;
}
/*----------------------------------------------------------------------------
| Returns the result of adding the single-precision floating-point values `a'
| Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSign = extractFloat32Sign( a );
bSign = extractFloat32Sign( b );
}
else {
}
}
/*----------------------------------------------------------------------------
| Returns the result of subtracting the single-precision floating-point values
| for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSign = extractFloat32Sign( a );
bSign = extractFloat32Sign( b );
}
else {
}
}
/*----------------------------------------------------------------------------
| Returns the result of multiplying the single-precision floating-point values
| for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
bSig = extractFloat32Frac( b );
bExp = extractFloat32Exp( b );
bSign = extractFloat32Sign( b );
if ( aExp == 0xFF ) {
return propagateFloat32NaN( a, b STATUS_VAR );
}
return float32_default_nan;
}
}
if ( bExp == 0xFF ) {
return float32_default_nan;
}
}
if ( aExp == 0 ) {
}
if ( bExp == 0 ) {
}
zSig <<= 1;
--zExp;
}
}
/*----------------------------------------------------------------------------
| Returns the result of dividing the single-precision floating-point value `a'
| by the corresponding value `b'. The operation is performed according to the
*----------------------------------------------------------------------------*/
{
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
bSig = extractFloat32Frac( b );
bExp = extractFloat32Exp( b );
bSign = extractFloat32Sign( b );
if ( aExp == 0xFF ) {
if ( bExp == 0xFF ) {
return float32_default_nan;
}
}
if ( bExp == 0xFF ) {
return packFloat32( zSign, 0, 0 );
}
if ( bExp == 0 ) {
if ( bSig == 0 ) {
return float32_default_nan;
}
}
}
if ( aExp == 0 ) {
}
aSig >>= 1;
++zExp;
}
if ( ( zSig & 0x3F ) == 0 ) {
}
}
/*----------------------------------------------------------------------------
| Returns the remainder of the single-precision floating-point value `a'
| with respect to the corresponding value `b'. The operation is performed
*----------------------------------------------------------------------------*/
{
bits32 q;
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
bSig = extractFloat32Frac( b );
bExp = extractFloat32Exp( b );
bSign = extractFloat32Sign( b );
if ( aExp == 0xFF ) {
return propagateFloat32NaN( a, b STATUS_VAR );
}
return float32_default_nan;
}
if ( bExp == 0xFF ) {
return a;
}
if ( bExp == 0 ) {
if ( bSig == 0 ) {
return float32_default_nan;
}
}
if ( aExp == 0 ) {
if ( aSig == 0 ) return a;
}
aSig |= 0x00800000;
bSig |= 0x00800000;
if ( expDiff < 32 ) {
aSig <<= 8;
bSig <<= 8;
if ( expDiff < 0 ) {
if ( expDiff < -1 ) return a;
aSig >>= 1;
}
if ( 0 < expDiff ) {
q >>= 32 - expDiff;
bSig >>= 2;
}
else {
aSig >>= 2;
bSig >>= 2;
}
}
else {
expDiff -= 64;
while ( 0 < expDiff ) {
expDiff -= 62;
}
expDiff += 64;
bSig <<= 6;
}
do {
++q;
}
}
/*----------------------------------------------------------------------------
| Returns the square root of the single-precision floating-point value `a'.
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
if ( aExp == 0xFF ) {
if ( ! aSign ) return a;
return float32_default_nan;
}
if ( aSign ) {
return float32_default_nan;
}
if ( aExp == 0 ) {
if ( aSig == 0 ) return float32_zero;
}
if ( zSig < 2 ) {
zSig = 0x7FFFFFFF;
goto roundAndPack;
}
--zSig;
}
}
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is equal to
| the corresponding value `b', and 0 otherwise. The comparison is performed
*----------------------------------------------------------------------------*/
{
) {
if ( float32_is_signaling_nan( a ) || float32_is_signaling_nan( b ) ) {
}
return 0;
}
return ( float32_val(a) == float32_val(b) ) ||
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is less than
| or equal to the corresponding value `b', and 0 otherwise. The comparison
| Arithmetic.
*----------------------------------------------------------------------------*/
{
) {
return 0;
}
aSign = extractFloat32Sign( a );
bSign = extractFloat32Sign( b );
av = float32_val(a);
bv = float32_val(b);
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is less than
| the corresponding value `b', and 0 otherwise. The comparison is performed
*----------------------------------------------------------------------------*/
{
) {
return 0;
}
aSign = extractFloat32Sign( a );
bSign = extractFloat32Sign( b );
av = float32_val(a);
bv = float32_val(b);
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is equal to
| the corresponding value `b', and 0 otherwise. The invalid exception is
| raised if either operand is a NaN. Otherwise, the comparison is performed
*----------------------------------------------------------------------------*/
{
) {
return 0;
}
av = float32_val(a);
bv = float32_val(b);
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is less than or
| equal to the corresponding value `b', and 0 otherwise. Quiet NaNs do not
| cause an exception. Otherwise, the comparison is performed according to the
*----------------------------------------------------------------------------*/
{
) {
if ( float32_is_signaling_nan( a ) || float32_is_signaling_nan( b ) ) {
}
return 0;
}
aSign = extractFloat32Sign( a );
bSign = extractFloat32Sign( b );
av = float32_val(a);
bv = float32_val(b);
}
/*----------------------------------------------------------------------------
| Returns 1 if the single-precision floating-point value `a' is less than
| the corresponding value `b', and 0 otherwise. Quiet NaNs do not cause an
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
) {
if ( float32_is_signaling_nan( a ) || float32_is_signaling_nan( b ) ) {
}
return 0;
}
aSign = extractFloat32Sign( a );
bSign = extractFloat32Sign( b );
av = float32_val(a);
bv = float32_val(b);
}
/*----------------------------------------------------------------------------
| Returns the result of converting the double-precision floating-point value
| `a' to the 32-bit two's complement integer format. The conversion is
| Arithmetic---which means in particular that the conversion is rounded
| according to the current rounding mode. If `a' is a NaN, the largest
| positive integer is returned. Otherwise, if the conversion overflows, the
| largest integer with the same sign as `a' is returned.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
}
/*----------------------------------------------------------------------------
| Returns the result of converting the double-precision floating-point value
| `a' to the 32-bit two's complement integer format. The conversion is
| Arithmetic, except that the conversion is always rounded toward zero.
| If `a' is a NaN, the largest positive integer is returned. Otherwise, if
| the conversion overflows, the largest integer with the same sign as `a' is
| returned.
*----------------------------------------------------------------------------*/
{
int32 z;
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
if ( 0x41E < aExp ) {
goto invalid;
}
else if ( aExp < 0x3FF ) {
return 0;
}
aSig >>= shiftCount;
z = aSig;
if ( aSign ) z = - z;
if ( ( z < 0 ) ^ aSign ) {
}
}
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the double-precision floating-point value
| `a' to the 64-bit two's complement integer format. The conversion is
| Arithmetic---which means in particular that the conversion is rounded
| according to the current rounding mode. If `a' is a NaN, the largest
| positive integer is returned. Otherwise, if the conversion overflows, the
| largest integer with the same sign as `a' is returned.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
if ( shiftCount <= 0 ) {
if ( 0x43E < aExp ) {
if ( ! aSign
|| ( ( aExp == 0x7FF )
) {
return LIT64( 0x7FFFFFFFFFFFFFFF );
}
}
aSigExtra = 0;
aSig <<= - shiftCount;
}
else {
}
}
/*----------------------------------------------------------------------------
| Returns the result of converting the double-precision floating-point value
| `a' to the 64-bit two's complement integer format. The conversion is
| Arithmetic, except that the conversion is always rounded toward zero.
| If `a' is a NaN, the largest positive integer is returned. Otherwise, if
| the conversion overflows, the largest integer with the same sign as `a' is
| returned.
*----------------------------------------------------------------------------*/
{
int64 z;
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
if ( 0 <= shiftCount ) {
if ( 0x43E <= aExp ) {
if ( ! aSign
|| ( ( aExp == 0x7FF )
) {
return LIT64( 0x7FFFFFFFFFFFFFFF );
}
}
}
z = aSig<<shiftCount;
}
else {
if ( aExp < 0x3FE ) {
return 0;
}
z = aSig>>( - shiftCount );
}
}
if ( aSign ) z = - z;
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the double-precision floating-point value
| `a' to the single-precision floating-point format. The conversion is
| Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
if ( aExp == 0x7FF ) {
}
zSig |= 0x40000000;
aExp -= 0x381;
}
}
#ifdef FLOATX80
/*----------------------------------------------------------------------------
| Returns the result of converting the double-precision floating-point value
| `a' to the extended double-precision floating-point format. The conversion
| Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
if ( aExp == 0x7FF ) {
}
if ( aExp == 0 ) {
}
return
}
#endif
#ifdef FLOAT128
/*----------------------------------------------------------------------------
| Returns the result of converting the double-precision floating-point value
| `a' to the quadruple-precision floating-point format. The conversion is
| Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
if ( aExp == 0x7FF ) {
}
if ( aExp == 0 ) {
--aExp;
}
}
#endif
/*----------------------------------------------------------------------------
| Rounds the double-precision floating-point value `a' to an integer, and
| returns the result as a double-precision floating-point value. The
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
bits64 z;
aExp = extractFloat64Exp( a );
if ( 0x433 <= aExp ) {
return propagateFloat64NaN( a, a STATUS_VAR );
}
return a;
}
if ( aExp < 0x3FF ) {
aSign = extractFloat64Sign( a );
switch ( STATUS(float_rounding_mode) ) {
case float_round_nearest_even:
}
break;
case float_round_down:
case float_round_up:
return make_float64(
}
return packFloat64( aSign, 0, 0 );
}
lastBitMask = 1;
z = float64_val(a);
if ( roundingMode == float_round_nearest_even ) {
z += lastBitMask>>1;
if ( ( z & roundBitsMask ) == 0 ) z &= ~ lastBitMask;
}
else if ( roundingMode != float_round_to_zero ) {
z += roundBitsMask;
}
}
z &= ~ roundBitsMask;
if ( z != float64_val(a) )
return make_float64(z);
}
{
int oldmode;
return res;
}
/*----------------------------------------------------------------------------
| Returns the result of adding the absolute values of the double-precision
| floating-point values `a' and `b'. If `zSign' is 1, the sum is negated
| before being returned. `zSign' is ignored if the result is a NaN.
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
bSig = extractFloat64Frac( b );
bExp = extractFloat64Exp( b );
aSig <<= 9;
bSig <<= 9;
if ( 0 < expDiff ) {
if ( aExp == 0x7FF ) {
return a;
}
if ( bExp == 0 ) {
--expDiff;
}
else {
}
}
else if ( expDiff < 0 ) {
if ( bExp == 0x7FF ) {
}
if ( aExp == 0 ) {
++expDiff;
}
else {
}
}
else {
if ( aExp == 0x7FF ) {
return a;
}
goto roundAndPack;
}
--zExp;
++zExp;
}
}
/*----------------------------------------------------------------------------
| Returns the result of subtracting the absolute values of the double-
| precision floating-point values `a' and `b'. If `zSign' is 1, the
| difference is negated before being returned. `zSign' is ignored if the
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
bSig = extractFloat64Frac( b );
bExp = extractFloat64Exp( b );
aSig <<= 10;
bSig <<= 10;
if ( 0 < expDiff ) goto aExpBigger;
if ( expDiff < 0 ) goto bExpBigger;
if ( aExp == 0x7FF ) {
return float64_default_nan;
}
if ( aExp == 0 ) {
aExp = 1;
bExp = 1;
}
if ( bExp == 0x7FF ) {
}
if ( aExp == 0 ) {
++expDiff;
}
else {
}
zSign ^= 1;
goto normalizeRoundAndPack;
if ( aExp == 0x7FF ) {
return a;
}
if ( bExp == 0 ) {
--expDiff;
}
else {
}
--zExp;
}
/*----------------------------------------------------------------------------
| Returns the result of adding the double-precision floating-point values `a'
| Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSign = extractFloat64Sign( a );
bSign = extractFloat64Sign( b );
}
else {
}
}
/*----------------------------------------------------------------------------
| Returns the result of subtracting the double-precision floating-point values
| for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSign = extractFloat64Sign( a );
bSign = extractFloat64Sign( b );
}
else {
}
}
/*----------------------------------------------------------------------------
| Returns the result of multiplying the double-precision floating-point values
| for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
bSig = extractFloat64Frac( b );
bExp = extractFloat64Exp( b );
bSign = extractFloat64Sign( b );
if ( aExp == 0x7FF ) {
return propagateFloat64NaN( a, b STATUS_VAR );
}
return float64_default_nan;
}
}
if ( bExp == 0x7FF ) {
return float64_default_nan;
}
}
if ( aExp == 0 ) {
}
if ( bExp == 0 ) {
}
zSig0 <<= 1;
--zExp;
}
}
/*----------------------------------------------------------------------------
| Returns the result of dividing the double-precision floating-point value `a'
| by the corresponding value `b'. The operation is performed according to
*----------------------------------------------------------------------------*/
{
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
bSig = extractFloat64Frac( b );
bExp = extractFloat64Exp( b );
bSign = extractFloat64Sign( b );
if ( aExp == 0x7FF ) {
if ( bExp == 0x7FF ) {
return float64_default_nan;
}
}
if ( bExp == 0x7FF ) {
return packFloat64( zSign, 0, 0 );
}
if ( bExp == 0 ) {
if ( bSig == 0 ) {
return float64_default_nan;
}
}
}
if ( aExp == 0 ) {
}
aSig >>= 1;
++zExp;
}
--zSig;
}
}
}
/*----------------------------------------------------------------------------
| Returns the remainder of the double-precision floating-point value `a'
| with respect to the corresponding value `b'. The operation is performed
*----------------------------------------------------------------------------*/
{
bits64 q, alternateASig;
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
bSig = extractFloat64Frac( b );
bExp = extractFloat64Exp( b );
bSign = extractFloat64Sign( b );
if ( aExp == 0x7FF ) {
return propagateFloat64NaN( a, b STATUS_VAR );
}
return float64_default_nan;
}
if ( bExp == 0x7FF ) {
return a;
}
if ( bExp == 0 ) {
if ( bSig == 0 ) {
return float64_default_nan;
}
}
if ( aExp == 0 ) {
if ( aSig == 0 ) return a;
}
if ( expDiff < 0 ) {
if ( expDiff < -1 ) return a;
aSig >>= 1;
}
expDiff -= 64;
while ( 0 < expDiff ) {
q = ( 2 < q ) ? q - 2 : 0;
expDiff -= 62;
}
expDiff += 64;
if ( 0 < expDiff ) {
q = ( 2 < q ) ? q - 2 : 0;
q >>= 64 - expDiff;
bSig >>= 2;
}
else {
aSig >>= 2;
bSig >>= 2;
}
do {
++q;
}
}
/*----------------------------------------------------------------------------
| Returns the square root of the double-precision floating-point value `a'.
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
if ( aExp == 0x7FF ) {
if ( ! aSign ) return a;
return float64_default_nan;
}
if ( aSign ) {
return float64_default_nan;
}
if ( aExp == 0 ) {
if ( aSig == 0 ) return float64_zero;
}
--zSig;
doubleZSig -= 2;
}
}
}
/*----------------------------------------------------------------------------
| Returns 1 if the double-precision floating-point value `a' is equal to the
| corresponding value `b', and 0 otherwise. The comparison is performed
*----------------------------------------------------------------------------*/
{
) {
if ( float64_is_signaling_nan( a ) || float64_is_signaling_nan( b ) ) {
}
return 0;
}
av = float64_val(a);
bv = float64_val(b);
}
/*----------------------------------------------------------------------------
| Returns 1 if the double-precision floating-point value `a' is less than or
| equal to the corresponding value `b', and 0 otherwise. The comparison is
| Arithmetic.
*----------------------------------------------------------------------------*/
{
) {
return 0;
}
aSign = extractFloat64Sign( a );
bSign = extractFloat64Sign( b );
av = float64_val(a);
bv = float64_val(b);
}
/*----------------------------------------------------------------------------
| Returns 1 if the double-precision floating-point value `a' is less than
| the corresponding value `b', and 0 otherwise. The comparison is performed
*----------------------------------------------------------------------------*/
{
) {
return 0;
}
aSign = extractFloat64Sign( a );
bSign = extractFloat64Sign( b );
av = float64_val(a);
bv = float64_val(b);
}
/*----------------------------------------------------------------------------
| Returns 1 if the double-precision floating-point value `a' is equal to the
| corresponding value `b', and 0 otherwise. The invalid exception is raised
| if either operand is a NaN. Otherwise, the comparison is performed
*----------------------------------------------------------------------------*/
{
) {
return 0;
}
av = float64_val(a);
bv = float64_val(b);
}
/*----------------------------------------------------------------------------
| Returns 1 if the double-precision floating-point value `a' is less than or
| equal to the corresponding value `b', and 0 otherwise. Quiet NaNs do not
| cause an exception. Otherwise, the comparison is performed according to the
*----------------------------------------------------------------------------*/
{
) {
if ( float64_is_signaling_nan( a ) || float64_is_signaling_nan( b ) ) {
}
return 0;
}
aSign = extractFloat64Sign( a );
bSign = extractFloat64Sign( b );
av = float64_val(a);
bv = float64_val(b);
}
/*----------------------------------------------------------------------------
| Returns 1 if the double-precision floating-point value `a' is less than
| the corresponding value `b', and 0 otherwise. Quiet NaNs do not cause an
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
) {
if ( float64_is_signaling_nan( a ) || float64_is_signaling_nan( b ) ) {
}
return 0;
}
aSign = extractFloat64Sign( a );
bSign = extractFloat64Sign( b );
av = float64_val(a);
bv = float64_val(b);
}
#ifdef FLOATX80
/*----------------------------------------------------------------------------
| Returns the result of converting the extended double-precision floating-
| point value `a' to the 32-bit two's complement integer format. The
| Floating-Point Arithmetic---which means in particular that the conversion
| is rounded according to the current rounding mode. If `a' is a NaN, the
| largest positive integer is returned. Otherwise, if the conversion
| overflows, the largest integer with the same sign as `a' is returned.
*----------------------------------------------------------------------------*/
{
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
}
/*----------------------------------------------------------------------------
| Returns the result of converting the extended double-precision floating-
| point value `a' to the 32-bit two's complement integer format. The
| Floating-Point Arithmetic, except that the conversion is always rounded
| toward zero. If `a' is a NaN, the largest positive integer is returned.
| Otherwise, if the conversion overflows, the largest integer with the same
| sign as `a' is returned.
*----------------------------------------------------------------------------*/
{
int32 z;
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
if ( 0x401E < aExp ) {
goto invalid;
}
else if ( aExp < 0x3FFF ) {
return 0;
}
aSig >>= shiftCount;
z = aSig;
if ( aSign ) z = - z;
if ( ( z < 0 ) ^ aSign ) {
}
}
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the extended double-precision floating-
| point value `a' to the 64-bit two's complement integer format. The
| Floating-Point Arithmetic---which means in particular that the conversion
| is rounded according to the current rounding mode. If `a' is a NaN,
| the largest positive integer is returned. Otherwise, if the conversion
| overflows, the largest integer with the same sign as `a' is returned.
*----------------------------------------------------------------------------*/
{
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
if ( shiftCount <= 0 ) {
if ( shiftCount ) {
if ( ! aSign
|| ( ( aExp == 0x7FFF )
) {
return LIT64( 0x7FFFFFFFFFFFFFFF );
}
}
aSigExtra = 0;
}
else {
}
}
/*----------------------------------------------------------------------------
| Returns the result of converting the extended double-precision floating-
| point value `a' to the 64-bit two's complement integer format. The
| Floating-Point Arithmetic, except that the conversion is always rounded
| toward zero. If `a' is a NaN, the largest positive integer is returned.
| Otherwise, if the conversion overflows, the largest integer with the same
| sign as `a' is returned.
*----------------------------------------------------------------------------*/
{
int64 z;
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
if ( 0 <= shiftCount ) {
return LIT64( 0x7FFFFFFFFFFFFFFF );
}
}
}
else if ( aExp < 0x3FFF ) {
return 0;
}
z = aSig>>( - shiftCount );
}
if ( aSign ) z = - z;
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the extended double-precision floating-
| point value `a' to the single-precision floating-point format. The
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
if ( aExp == 0x7FFF ) {
}
}
}
/*----------------------------------------------------------------------------
| Returns the result of converting the extended double-precision floating-
| point value `a' to the double-precision floating-point format. The
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
if ( aExp == 0x7FFF ) {
}
}
}
#ifdef FLOAT128
/*----------------------------------------------------------------------------
| Returns the result of converting the extended double-precision floating-
| point value `a' to the quadruple-precision floating-point format. The
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
}
}
#endif
/*----------------------------------------------------------------------------
| Rounds the extended double-precision floating-point value `a' to an integer,
| and returns the result as an extended quadruple-precision floating-point
| Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
floatx80 z;
aExp = extractFloatx80Exp( a );
if ( 0x403E <= aExp ) {
return propagateFloatx80NaN( a, a STATUS_VAR );
}
return a;
}
if ( aExp < 0x3FFF ) {
if ( ( aExp == 0 )
return a;
}
aSign = extractFloatx80Sign( a );
switch ( STATUS(float_rounding_mode) ) {
case float_round_nearest_even:
) {
return
}
break;
case float_round_down:
return
aSign ?
: packFloatx80( 0, 0, 0 );
case float_round_up:
return
}
return packFloatx80( aSign, 0, 0 );
}
lastBitMask = 1;
z = a;
if ( roundingMode == float_round_nearest_even ) {
}
else if ( roundingMode != float_round_to_zero ) {
z.low += roundBitsMask;
}
}
z.low &= ~ roundBitsMask;
if ( z.low == 0 ) {
++z.high;
}
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of adding the absolute values of the extended double-
| precision floating-point values `a' and `b'. If `zSign' is 1, the sum is
| negated before being returned. `zSign' is ignored if the result is a NaN.
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
bSig = extractFloatx80Frac( b );
bExp = extractFloatx80Exp( b );
if ( 0 < expDiff ) {
if ( aExp == 0x7FFF ) {
return a;
}
}
else if ( expDiff < 0 ) {
if ( bExp == 0x7FFF ) {
}
}
else {
if ( aExp == 0x7FFF ) {
return propagateFloatx80NaN( a, b STATUS_VAR );
}
return a;
}
zSig1 = 0;
if ( aExp == 0 ) {
goto roundAndPack;
}
goto shiftRight1;
}
++zExp;
return
}
/*----------------------------------------------------------------------------
| Returns the result of subtracting the absolute values of the extended
| double-precision floating-point values `a' and `b'. If `zSign' is 1, the
| difference is negated before being returned. `zSign' is ignored if the
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
floatx80 z;
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
bSig = extractFloatx80Frac( b );
bExp = extractFloatx80Exp( b );
if ( 0 < expDiff ) goto aExpBigger;
if ( expDiff < 0 ) goto bExpBigger;
if ( aExp == 0x7FFF ) {
return propagateFloatx80NaN( a, b STATUS_VAR );
}
return z;
}
if ( aExp == 0 ) {
aExp = 1;
bExp = 1;
}
zSig1 = 0;
if ( bExp == 0x7FFF ) {
}
zSign ^= 1;
goto normalizeRoundAndPack;
if ( aExp == 0x7FFF ) {
return a;
}
return
}
/*----------------------------------------------------------------------------
| Returns the result of adding the extended double-precision floating-point
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSign = extractFloatx80Sign( a );
bSign = extractFloatx80Sign( b );
}
else {
}
}
/*----------------------------------------------------------------------------
| Returns the result of subtracting the extended double-precision floating-
| point values `a' and `b'. The operation is performed according to the
*----------------------------------------------------------------------------*/
{
aSign = extractFloatx80Sign( a );
bSign = extractFloatx80Sign( b );
}
else {
}
}
/*----------------------------------------------------------------------------
| Returns the result of multiplying the extended double-precision floating-
| point values `a' and `b'. The operation is performed according to the
*----------------------------------------------------------------------------*/
{
floatx80 z;
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
bSig = extractFloatx80Frac( b );
bExp = extractFloatx80Exp( b );
bSign = extractFloatx80Sign( b );
if ( aExp == 0x7FFF ) {
return propagateFloatx80NaN( a, b STATUS_VAR );
}
}
if ( bExp == 0x7FFF ) {
return z;
}
}
if ( aExp == 0 ) {
}
if ( bExp == 0 ) {
}
--zExp;
}
return
}
/*----------------------------------------------------------------------------
| Returns the result of dividing the extended double-precision floating-point
| value `a' by the corresponding value `b'. The operation is performed
*----------------------------------------------------------------------------*/
{
floatx80 z;
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
bSig = extractFloatx80Frac( b );
bExp = extractFloatx80Exp( b );
bSign = extractFloatx80Sign( b );
if ( aExp == 0x7FFF ) {
if ( bExp == 0x7FFF ) {
goto invalid;
}
}
if ( bExp == 0x7FFF ) {
return packFloatx80( zSign, 0, 0 );
}
if ( bExp == 0 ) {
if ( bSig == 0 ) {
return z;
}
}
}
if ( aExp == 0 ) {
}
rem1 = 0;
++zExp;
}
--zSig0;
}
--zSig1;
}
}
return
}
/*----------------------------------------------------------------------------
| Returns the remainder of the extended double-precision floating-point value
| `a' with respect to the corresponding value `b'. The operation is performed
*----------------------------------------------------------------------------*/
{
floatx80 z;
aSig0 = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
bSig = extractFloatx80Frac( b );
bExp = extractFloatx80Exp( b );
bSign = extractFloatx80Sign( b );
if ( aExp == 0x7FFF ) {
return propagateFloatx80NaN( a, b STATUS_VAR );
}
goto invalid;
}
if ( bExp == 0x7FFF ) {
return a;
}
if ( bExp == 0 ) {
if ( bSig == 0 ) {
return z;
}
}
if ( aExp == 0 ) {
}
aSig1 = 0;
if ( expDiff < 0 ) {
if ( expDiff < -1 ) return a;
expDiff = 0;
}
expDiff -= 64;
while ( 0 < expDiff ) {
q = ( 2 < q ) ? q - 2 : 0;
expDiff -= 62;
}
expDiff += 64;
if ( 0 < expDiff ) {
q = ( 2 < q ) ? q - 2 : 0;
q >>= 64 - expDiff;
++q;
}
}
else {
term1 = 0;
}
&& ( q & 1 ) )
) {
}
return
}
/*----------------------------------------------------------------------------
| Returns the square root of the extended double-precision floating-point
| for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
floatx80 z;
aSig0 = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
if ( aExp == 0x7FFF ) {
if ( ! aSign ) return a;
goto invalid;
}
if ( aSign ) {
return z;
}
if ( aExp == 0 ) {
if ( aSig0 == 0 ) return packFloatx80( 0, 0, 0 );
}
--zSig0;
doubleZSig0 -= 2;
}
--zSig1;
term3 |= 1;
term2 |= doubleZSig0;
}
}
zSig0 |= doubleZSig0;
return
}
/*----------------------------------------------------------------------------
| Returns 1 if the extended double-precision floating-point value `a' is
| equal to the corresponding value `b', and 0 otherwise. The comparison is
| Arithmetic.
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloatx80Exp( a ) == 0x7FFF )
|| ( ( extractFloatx80Exp( b ) == 0x7FFF )
) {
if ( floatx80_is_signaling_nan( a )
|| floatx80_is_signaling_nan( b ) ) {
}
return 0;
}
return
|| ( ( a.low == 0 )
);
}
/*----------------------------------------------------------------------------
| Returns 1 if the extended double-precision floating-point value `a' is
| less than or equal to the corresponding value `b', and 0 otherwise. The
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloatx80Exp( a ) == 0x7FFF )
|| ( ( extractFloatx80Exp( b ) == 0x7FFF )
) {
return 0;
}
aSign = extractFloatx80Sign( a );
bSign = extractFloatx80Sign( b );
return
== 0 );
}
return
}
/*----------------------------------------------------------------------------
| Returns 1 if the extended double-precision floating-point value `a' is
| less than the corresponding value `b', and 0 otherwise. The comparison
| Arithmetic.
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloatx80Exp( a ) == 0x7FFF )
|| ( ( extractFloatx80Exp( b ) == 0x7FFF )
) {
return 0;
}
aSign = extractFloatx80Sign( a );
bSign = extractFloatx80Sign( b );
return
!= 0 );
}
return
}
/*----------------------------------------------------------------------------
| Returns 1 if the extended double-precision floating-point value `a' is equal
| to the corresponding value `b', and 0 otherwise. The invalid exception is
| raised if either operand is a NaN. Otherwise, the comparison is performed
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloatx80Exp( a ) == 0x7FFF )
|| ( ( extractFloatx80Exp( b ) == 0x7FFF )
) {
return 0;
}
return
|| ( ( a.low == 0 )
);
}
/*----------------------------------------------------------------------------
| Returns 1 if the extended double-precision floating-point value `a' is less
| than or equal to the corresponding value `b', and 0 otherwise. Quiet NaNs
| do not cause an exception. Otherwise, the comparison is performed according
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloatx80Exp( a ) == 0x7FFF )
|| ( ( extractFloatx80Exp( b ) == 0x7FFF )
) {
if ( floatx80_is_signaling_nan( a )
|| floatx80_is_signaling_nan( b ) ) {
}
return 0;
}
aSign = extractFloatx80Sign( a );
bSign = extractFloatx80Sign( b );
return
== 0 );
}
return
}
/*----------------------------------------------------------------------------
| Returns 1 if the extended double-precision floating-point value `a' is less
| than the corresponding value `b', and 0 otherwise. Quiet NaNs do not cause
| an exception. Otherwise, the comparison is performed according to the
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloatx80Exp( a ) == 0x7FFF )
|| ( ( extractFloatx80Exp( b ) == 0x7FFF )
) {
if ( floatx80_is_signaling_nan( a )
|| floatx80_is_signaling_nan( b ) ) {
}
return 0;
}
aSign = extractFloatx80Sign( a );
bSign = extractFloatx80Sign( b );
return
!= 0 );
}
return
}
#endif
#ifdef FLOAT128
/*----------------------------------------------------------------------------
| Returns the result of converting the quadruple-precision floating-point
| value `a' to the 32-bit two's complement integer format. The conversion
| Arithmetic---which means in particular that the conversion is rounded
| according to the current rounding mode. If `a' is a NaN, the largest
| positive integer is returned. Otherwise, if the conversion overflows, the
| largest integer with the same sign as `a' is returned.
*----------------------------------------------------------------------------*/
{
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
}
/*----------------------------------------------------------------------------
| Returns the result of converting the quadruple-precision floating-point
| value `a' to the 32-bit two's complement integer format. The conversion
| Arithmetic, except that the conversion is always rounded toward zero. If
| `a' is a NaN, the largest positive integer is returned. Otherwise, if the
| conversion overflows, the largest integer with the same sign as `a' is
| returned.
*----------------------------------------------------------------------------*/
{
int32 z;
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
if ( 0x401E < aExp ) {
goto invalid;
}
else if ( aExp < 0x3FFF ) {
return 0;
}
aSig0 >>= shiftCount;
z = aSig0;
if ( aSign ) z = - z;
if ( ( z < 0 ) ^ aSign ) {
}
}
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the quadruple-precision floating-point
| value `a' to the 64-bit two's complement integer format. The conversion
| Arithmetic---which means in particular that the conversion is rounded
| according to the current rounding mode. If `a' is a NaN, the largest
| positive integer is returned. Otherwise, if the conversion overflows, the
| largest integer with the same sign as `a' is returned.
*----------------------------------------------------------------------------*/
{
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
if ( shiftCount <= 0 ) {
if ( 0x403E < aExp ) {
if ( ! aSign
|| ( ( aExp == 0x7FFF )
)
) {
return LIT64( 0x7FFFFFFFFFFFFFFF );
}
}
}
else {
}
}
/*----------------------------------------------------------------------------
| Returns the result of converting the quadruple-precision floating-point
| value `a' to the 64-bit two's complement integer format. The conversion
| Arithmetic, except that the conversion is always rounded toward zero.
| If `a' is a NaN, the largest positive integer is returned. Otherwise, if
| the conversion overflows, the largest integer with the same sign as `a' is
| returned.
*----------------------------------------------------------------------------*/
{
int64 z;
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
if ( 0 < shiftCount ) {
if ( 0x403E <= aExp ) {
}
else {
return LIT64( 0x7FFFFFFFFFFFFFFF );
}
}
}
}
}
else {
if ( aExp < 0x3FFF ) {
}
return 0;
}
z = aSig0>>( - shiftCount );
if ( aSig1
}
}
if ( aSign ) z = - z;
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of converting the quadruple-precision floating-point
| value `a' to the single-precision floating-point format. The conversion
| Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
if ( aExp == 0x7FFF ) {
}
}
zSig |= 0x40000000;
aExp -= 0x3F81;
}
}
/*----------------------------------------------------------------------------
| Returns the result of converting the quadruple-precision floating-point
| value `a' to the double-precision floating-point format. The conversion
| Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
if ( aExp == 0x7FFF ) {
}
}
aExp -= 0x3C01;
}
}
#ifdef FLOATX80
/*----------------------------------------------------------------------------
| Returns the result of converting the quadruple-precision floating-point
| value `a' to the extended double-precision floating-point format. The
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
if ( aExp == 0x7FFF ) {
}
}
if ( aExp == 0 ) {
}
else {
}
}
#endif
/*----------------------------------------------------------------------------
| Rounds the quadruple-precision floating-point value `a' to an integer, and
| returns the result as a quadruple-precision floating-point value. The
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
float128 z;
aExp = extractFloat128Exp( a );
if ( 0x402F <= aExp ) {
if ( 0x406F <= aExp ) {
if ( ( aExp == 0x7FFF )
&& ( extractFloat128Frac0( a ) | extractFloat128Frac1( a ) )
) {
return propagateFloat128NaN( a, a STATUS_VAR );
}
return a;
}
lastBitMask = 1;
z = a;
if ( roundingMode == float_round_nearest_even ) {
if ( lastBitMask ) {
}
else {
++z.high;
}
}
}
else if ( roundingMode != float_round_to_zero ) {
if ( extractFloat128Sign( z )
^ ( roundingMode == float_round_up ) ) {
}
}
z.low &= ~ roundBitsMask;
}
else {
if ( aExp < 0x3FFF ) {
aSign = extractFloat128Sign( a );
switch ( STATUS(float_rounding_mode) ) {
case float_round_nearest_even:
if ( ( aExp == 0x3FFE )
&& ( extractFloat128Frac0( a )
| extractFloat128Frac1( a ) )
) {
}
break;
case float_round_down:
return
: packFloat128( 0, 0, 0, 0 );
case float_round_up:
return
: packFloat128( 0, 0x3FFF, 0, 0 );
}
return packFloat128( aSign, 0, 0, 0 );
}
lastBitMask = 1;
z.low = 0;
if ( roundingMode == float_round_nearest_even ) {
z.high &= ~ lastBitMask;
}
}
else if ( roundingMode != float_round_to_zero ) {
if ( extractFloat128Sign( z )
^ ( roundingMode == float_round_up ) ) {
z.high += roundBitsMask;
}
}
z.high &= ~ roundBitsMask;
}
}
return z;
}
/*----------------------------------------------------------------------------
| Returns the result of adding the absolute values of the quadruple-precision
| floating-point values `a' and `b'. If `zSign' is 1, the sum is negated
| before being returned. `zSign' is ignored if the result is a NaN.
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
bSig1 = extractFloat128Frac1( b );
bSig0 = extractFloat128Frac0( b );
bExp = extractFloat128Exp( b );
if ( 0 < expDiff ) {
if ( aExp == 0x7FFF ) {
return a;
}
if ( bExp == 0 ) {
--expDiff;
}
else {
}
}
else if ( expDiff < 0 ) {
if ( bExp == 0x7FFF ) {
}
if ( aExp == 0 ) {
++expDiff;
}
else {
}
}
else {
if ( aExp == 0x7FFF ) {
return propagateFloat128NaN( a, b STATUS_VAR );
}
return a;
}
zSig2 = 0;
goto shiftRight1;
}
--zExp;
++zExp;
}
/*----------------------------------------------------------------------------
| Returns the result of subtracting the absolute values of the quadruple-
| precision floating-point values `a' and `b'. If `zSign' is 1, the
| difference is negated before being returned. `zSign' is ignored if the
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
float128 z;
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
bSig1 = extractFloat128Frac1( b );
bSig0 = extractFloat128Frac0( b );
bExp = extractFloat128Exp( b );
if ( 0 < expDiff ) goto aExpBigger;
if ( expDiff < 0 ) goto bExpBigger;
if ( aExp == 0x7FFF ) {
return propagateFloat128NaN( a, b STATUS_VAR );
}
return z;
}
if ( aExp == 0 ) {
aExp = 1;
bExp = 1;
}
if ( bExp == 0x7FFF ) {
}
if ( aExp == 0 ) {
++expDiff;
}
else {
}
zSign ^= 1;
goto normalizeRoundAndPack;
if ( aExp == 0x7FFF ) {
return a;
}
if ( bExp == 0 ) {
--expDiff;
}
else {
}
--zExp;
}
/*----------------------------------------------------------------------------
| Returns the result of adding the quadruple-precision floating-point values
| for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSign = extractFloat128Sign( a );
bSign = extractFloat128Sign( b );
}
else {
}
}
/*----------------------------------------------------------------------------
| Returns the result of subtracting the quadruple-precision floating-point
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
aSign = extractFloat128Sign( a );
bSign = extractFloat128Sign( b );
}
else {
}
}
/*----------------------------------------------------------------------------
| Returns the result of multiplying the quadruple-precision floating-point
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
float128 z;
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
bSig1 = extractFloat128Frac1( b );
bSig0 = extractFloat128Frac0( b );
bExp = extractFloat128Exp( b );
bSign = extractFloat128Sign( b );
if ( aExp == 0x7FFF ) {
return propagateFloat128NaN( a, b STATUS_VAR );
}
}
if ( bExp == 0x7FFF ) {
return z;
}
}
if ( aExp == 0 ) {
}
if ( bExp == 0 ) {
}
++zExp;
}
}
/*----------------------------------------------------------------------------
| Returns the result of dividing the quadruple-precision floating-point value
| `a' by the corresponding value `b'. The operation is performed according to
*----------------------------------------------------------------------------*/
{
float128 z;
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
bSig1 = extractFloat128Frac1( b );
bSig0 = extractFloat128Frac0( b );
bExp = extractFloat128Exp( b );
bSign = extractFloat128Sign( b );
if ( aExp == 0x7FFF ) {
if ( bExp == 0x7FFF ) {
goto invalid;
}
}
if ( bExp == 0x7FFF ) {
return packFloat128( zSign, 0, 0, 0 );
}
if ( bExp == 0 ) {
return z;
}
}
}
if ( aExp == 0 ) {
}
++zExp;
}
--zSig0;
}
--zSig1;
}
}
}
/*----------------------------------------------------------------------------
| Returns the remainder of the quadruple-precision floating-point value `a'
| with respect to the corresponding value `b'. The operation is performed
*----------------------------------------------------------------------------*/
{
float128 z;
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
bSig1 = extractFloat128Frac1( b );
bSig0 = extractFloat128Frac0( b );
bExp = extractFloat128Exp( b );
bSign = extractFloat128Sign( b );
if ( aExp == 0x7FFF ) {
return propagateFloat128NaN( a, b STATUS_VAR );
}
goto invalid;
}
if ( bExp == 0x7FFF ) {
return a;
}
if ( bExp == 0 ) {
return z;
}
}
if ( aExp == 0 ) {
}
if ( expDiff < -1 ) return a;
15 - ( expDiff < 0 ),
&aSig0,
);
expDiff -= 64;
while ( 0 < expDiff ) {
q = ( 4 < q ) ? q - 4 : 0;
expDiff -= 61;
}
if ( -64 < expDiff ) {
q = ( 4 < q ) ? q - 4 : 0;
q >>= - expDiff;
expDiff += 52;
if ( expDiff < 0 ) {
}
else {
}
}
else {
}
do {
++q;
if ( ( sigMean0 < 0 )
}
return
}
/*----------------------------------------------------------------------------
| Returns the square root of the quadruple-precision floating-point value `a'.
| Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
float128 z;
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
if ( aExp == 0x7FFF ) {
if ( ! aSign ) return a;
goto invalid;
}
if ( aSign ) {
return z;
}
if ( aExp == 0 ) {
}
--zSig0;
doubleZSig0 -= 2;
}
--zSig1;
term3 |= 1;
term2 |= doubleZSig0;
}
}
}
/*----------------------------------------------------------------------------
| Returns 1 if the quadruple-precision floating-point value `a' is equal to
| the corresponding value `b', and 0 otherwise. The comparison is performed
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloat128Exp( a ) == 0x7FFF )
&& ( extractFloat128Frac0( a ) | extractFloat128Frac1( a ) ) )
|| ( ( extractFloat128Exp( b ) == 0x7FFF )
&& ( extractFloat128Frac0( b ) | extractFloat128Frac1( b ) ) )
) {
if ( float128_is_signaling_nan( a )
|| float128_is_signaling_nan( b ) ) {
}
return 0;
}
return
|| ( ( a.low == 0 )
);
}
/*----------------------------------------------------------------------------
| Returns 1 if the quadruple-precision floating-point value `a' is less than
| or equal to the corresponding value `b', and 0 otherwise. The comparison
| Arithmetic.
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloat128Exp( a ) == 0x7FFF )
&& ( extractFloat128Frac0( a ) | extractFloat128Frac1( a ) ) )
|| ( ( extractFloat128Exp( b ) == 0x7FFF )
&& ( extractFloat128Frac0( b ) | extractFloat128Frac1( b ) ) )
) {
return 0;
}
aSign = extractFloat128Sign( a );
bSign = extractFloat128Sign( b );
return
== 0 );
}
return
}
/*----------------------------------------------------------------------------
| Returns 1 if the quadruple-precision floating-point value `a' is less than
| the corresponding value `b', and 0 otherwise. The comparison is performed
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloat128Exp( a ) == 0x7FFF )
&& ( extractFloat128Frac0( a ) | extractFloat128Frac1( a ) ) )
|| ( ( extractFloat128Exp( b ) == 0x7FFF )
&& ( extractFloat128Frac0( b ) | extractFloat128Frac1( b ) ) )
) {
return 0;
}
aSign = extractFloat128Sign( a );
bSign = extractFloat128Sign( b );
return
!= 0 );
}
return
}
/*----------------------------------------------------------------------------
| Returns 1 if the quadruple-precision floating-point value `a' is equal to
| the corresponding value `b', and 0 otherwise. The invalid exception is
| raised if either operand is a NaN. Otherwise, the comparison is performed
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloat128Exp( a ) == 0x7FFF )
&& ( extractFloat128Frac0( a ) | extractFloat128Frac1( a ) ) )
|| ( ( extractFloat128Exp( b ) == 0x7FFF )
&& ( extractFloat128Frac0( b ) | extractFloat128Frac1( b ) ) )
) {
return 0;
}
return
|| ( ( a.low == 0 )
);
}
/*----------------------------------------------------------------------------
| Returns 1 if the quadruple-precision floating-point value `a' is less than
| or equal to the corresponding value `b', and 0 otherwise. Quiet NaNs do not
| cause an exception. Otherwise, the comparison is performed according to the
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloat128Exp( a ) == 0x7FFF )
&& ( extractFloat128Frac0( a ) | extractFloat128Frac1( a ) ) )
|| ( ( extractFloat128Exp( b ) == 0x7FFF )
&& ( extractFloat128Frac0( b ) | extractFloat128Frac1( b ) ) )
) {
if ( float128_is_signaling_nan( a )
|| float128_is_signaling_nan( b ) ) {
}
return 0;
}
aSign = extractFloat128Sign( a );
bSign = extractFloat128Sign( b );
return
== 0 );
}
return
}
/*----------------------------------------------------------------------------
| Returns 1 if the quadruple-precision floating-point value `a' is less than
| the corresponding value `b', and 0 otherwise. Quiet NaNs do not cause an
| Standard for Binary Floating-Point Arithmetic.
*----------------------------------------------------------------------------*/
{
if ( ( ( extractFloat128Exp( a ) == 0x7FFF )
&& ( extractFloat128Frac0( a ) | extractFloat128Frac1( a ) ) )
|| ( ( extractFloat128Exp( b ) == 0x7FFF )
&& ( extractFloat128Frac0( b ) | extractFloat128Frac1( b ) ) )
) {
if ( float128_is_signaling_nan( a )
|| float128_is_signaling_nan( b ) ) {
}
return 0;
}
aSign = extractFloat128Sign( a );
bSign = extractFloat128Sign( b );
return
!= 0 );
}
return
}
#endif
/* misc functions */
{
return int64_to_float32(a STATUS_VAR);
}
{
return int64_to_float64(a STATUS_VAR);
}
{
int64_t v;
unsigned int res;
v = float32_to_int64(a STATUS_VAR);
if (v < 0) {
res = 0;
} else if (v > 0xffffffff) {
res = 0xffffffff;
} else {
res = v;
}
return res;
}
{
int64_t v;
unsigned int res;
if (v < 0) {
res = 0;
} else if (v > 0xffffffff) {
res = 0xffffffff;
} else {
res = v;
}
return res;
}
{
int64_t v;
unsigned int res;
v = float64_to_int64(a STATUS_VAR);
if (v < 0) {
res = 0;
} else if (v > 0xffffffff) {
res = 0xffffffff;
} else {
res = v;
}
return res;
}
{
int64_t v;
unsigned int res;
if (v < 0) {
res = 0;
} else if (v > 0xffffffff) {
res = 0xffffffff;
} else {
res = v;
}
return res;
}
/* FIXME: This looks broken. */
{
int64_t v;
v += float64_val(a);
return v - INT64_MIN;
}
{
int64_t v;
v += float64_val(a);
return v - INT64_MIN;
}
INLINE int float ## s ## _compare_internal( float ## s a, float ## s b, \
int is_quiet STATUS_PARAM ) \
{ \
\
extractFloat ## s ## Frac( a ) ) || \
extractFloat ## s ## Frac( b ) )) { \
if (!is_quiet || \
float ## s ## _is_signaling_nan( a ) || \
float ## s ## _is_signaling_nan( b ) ) { \
} \
return float_relation_unordered; \
} \
/* zero case */ \
return float_relation_equal; \
} else { \
} \
} else { \
return float_relation_equal; \
} else { \
} \
} \
} \
\
int float ## s ## _compare( float ## s a, float ## s b STATUS_PARAM ) \
{ \
return float ## s ## _compare_internal(a, b, 0 STATUS_VAR); \
} \
\
int float ## s ## _compare_quiet( float ## s a, float ## s b STATUS_PARAM ) \
{ \
}
int is_quiet STATUS_PARAM )
{
if (( ( extractFloat128Exp( a ) == 0x7fff ) &&
( extractFloat128Frac0( a ) | extractFloat128Frac1( a ) ) ) ||
( ( extractFloat128Exp( b ) == 0x7fff ) &&
( extractFloat128Frac0( b ) | extractFloat128Frac1( b ) ) )) {
if (!is_quiet ||
float128_is_signaling_nan( a ) ||
float128_is_signaling_nan( b ) ) {
}
return float_relation_unordered;
}
aSign = extractFloat128Sign( a );
bSign = extractFloat128Sign( b );
/* zero case */
return float_relation_equal;
} else {
}
} else {
return float_relation_equal;
} else {
}
}
}
{
return float128_compare_internal(a, b, 0 STATUS_VAR);
}
{
}
/* Multiply A by 2 raised to the power N. */
{
aSig = extractFloat32Frac( a );
aExp = extractFloat32Exp( a );
aSign = extractFloat32Sign( a );
if ( aExp == 0xFF ) {
return a;
}
aExp += n;
}
{
aSig = extractFloat64Frac( a );
aExp = extractFloat64Exp( a );
aSign = extractFloat64Sign( a );
if ( aExp == 0x7FF ) {
return a;
}
aExp += n;
}
#ifdef FLOATX80
{
aSig = extractFloatx80Frac( a );
aExp = extractFloatx80Exp( a );
aSign = extractFloatx80Sign( a );
if ( aExp == 0x7FF ) {
return a;
}
aExp += n;
}
#endif
#ifdef FLOAT128
{
aSig1 = extractFloat128Frac1( a );
aSig0 = extractFloat128Frac0( a );
aExp = extractFloat128Exp( a );
aSign = extractFloat128Sign( a );
if ( aExp == 0x7FFF ) {
return a;
}
aExp += n;
}
#endif