|
@@ -1522,3 +1522,172 @@ flag float32_eq( float32 a, float32 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 is
|
|
|
performed according to the IEC/IEEE Standard for Binary Floating-point
|
|
|
+Arithmetic.
|
|
|
+-------------------------------------------------------------------------------
|
|
|
+*/
|
|
|
+flag float32_le( float32 a, float32 b )
|
|
|
+{
|
|
|
+ flag aSign, bSign;
|
|
|
+
|
|
|
+ if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|
|
|
+ || ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
|
|
|
+ ) {
|
|
|
+ float_raise( float_flag_invalid );
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ aSign = extractFloat32Sign( a );
|
|
|
+ bSign = extractFloat32Sign( b );
|
|
|
+ if ( aSign != bSign ) return aSign || ( (bits32) ( ( a | b )<<1 ) == 0 );
|
|
|
+ return ( a == b ) || ( aSign ^ ( a < 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
|
|
|
+according to the IEC/IEEE Standard for Binary Floating-point Arithmetic.
|
|
|
+-------------------------------------------------------------------------------
|
|
|
+*/
|
|
|
+flag float32_lt( float32 a, float32 b )
|
|
|
+{
|
|
|
+ flag aSign, bSign;
|
|
|
+
|
|
|
+ if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|
|
|
+ || ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
|
|
|
+ ) {
|
|
|
+ float_raise( float_flag_invalid );
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ aSign = extractFloat32Sign( a );
|
|
|
+ bSign = extractFloat32Sign( b );
|
|
|
+ if ( aSign != bSign ) return aSign && ( (bits32) ( ( a | b )<<1 ) != 0 );
|
|
|
+ return ( a != b ) && ( aSign ^ ( a < 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
|
|
|
+according to the IEC/IEEE Standard for Binary Floating-point Arithmetic.
|
|
|
+-------------------------------------------------------------------------------
|
|
|
+*/
|
|
|
+flag float32_eq_signaling( float32 a, float32 b )
|
|
|
+{
|
|
|
+
|
|
|
+ if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|
|
|
+ || ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
|
|
|
+ ) {
|
|
|
+ float_raise( float_flag_invalid );
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return ( a == b ) || ( (bits32) ( ( a | b )<<1 ) == 0 );
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+-------------------------------------------------------------------------------
|
|
|
+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
|
|
|
+IEC/IEEE Standard for Binary Floating-point Arithmetic.
|
|
|
+-------------------------------------------------------------------------------
|
|
|
+*/
|
|
|
+flag float32_le_quiet( float32 a, float32 b )
|
|
|
+{
|
|
|
+ flag aSign, bSign;
|
|
|
+ //int16 aExp, bExp;
|
|
|
+
|
|
|
+ if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|
|
|
+ || ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
|
|
|
+ ) {
|
|
|
+ /* Do nothing, even if NaN as we're quiet */
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ aSign = extractFloat32Sign( a );
|
|
|
+ bSign = extractFloat32Sign( b );
|
|
|
+ if ( aSign != bSign ) return aSign || ( (bits32) ( ( a | b )<<1 ) == 0 );
|
|
|
+ return ( a == b ) || ( aSign ^ ( a < 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
|
|
|
+exception. Otherwise, the comparison is performed according to the IEC/IEEE
|
|
|
+Standard for Binary Floating-point Arithmetic.
|
|
|
+-------------------------------------------------------------------------------
|
|
|
+*/
|
|
|
+flag float32_lt_quiet( float32 a, float32 b )
|
|
|
+{
|
|
|
+ flag aSign, bSign;
|
|
|
+
|
|
|
+ if ( ( ( extractFloat32Exp( a ) == 0xFF ) && extractFloat32Frac( a ) )
|
|
|
+ || ( ( extractFloat32Exp( b ) == 0xFF ) && extractFloat32Frac( b ) )
|
|
|
+ ) {
|
|
|
+ /* Do nothing, even if NaN as we're quiet */
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ aSign = extractFloat32Sign( a );
|
|
|
+ bSign = extractFloat32Sign( b );
|
|
|
+ if ( aSign != bSign ) return aSign && ( (bits32) ( ( a | b )<<1 ) != 0 );
|
|
|
+ return ( a != b ) && ( aSign ^ ( a < 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
|
|
|
+performed according to the IEC/IEEE Standard for Binary 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.
|
|
|
+-------------------------------------------------------------------------------
|
|
|
+*/
|
|
|
+int32 float64_to_int32( struct roundingData *roundData, float64 a )
|
|
|
+{
|
|
|
+ flag aSign;
|
|
|
+ int16 aExp, shiftCount;
|
|
|
+ bits64 aSig;
|
|
|
+
|
|
|
+ aSig = extractFloat64Frac( a );
|
|
|
+ aExp = extractFloat64Exp( a );
|
|
|
+ aSign = extractFloat64Sign( a );
|
|
|
+ if ( ( aExp == 0x7FF ) && aSig ) aSign = 0;
|
|
|
+ if ( aExp ) aSig |= LIT64( 0x0010000000000000 );
|
|
|
+ shiftCount = 0x42C - aExp;
|
|
|
+ if ( 0 < shiftCount ) shift64RightJamming( aSig, shiftCount, &aSig );
|
|
|
+ return roundAndPackInt32( roundData, aSign, aSig );
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+-------------------------------------------------------------------------------
|
|
|
+Returns the result of converting the double-precision floating-point value
|
|
|
+`a' to the 32-bit two's complement integer format. The conversion is
|
|
|
+performed according to the IEC/IEEE Standard for Binary 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 float64_to_int32_round_to_zero( float64 a )
|
|
|
+{
|
|
|
+ flag aSign;
|
|
|
+ int16 aExp, shiftCount;
|
|
|
+ bits64 aSig, savedASig;
|
|
|
+ int32 z;
|
|
|
+
|
|
|
+ aSig = extractFloat64Frac( a );
|
|
|
+ aExp = extractFloat64Exp( a );
|
|
|
+ aSign = extractFloat64Sign( a );
|
|
|
+ shiftCount = 0x433 - aExp;
|
|
|
+ if ( shiftCount < 21 ) {
|
|
|
+ if ( ( aExp == 0x7FF ) && aSig ) aSign = 0;
|
|
|
+ goto invalid;
|