在softfolat中双精度浮点、单精度浮点对异常值的处理,代码是什么
时间: 2024-02-23 22:59:59 浏览: 19
在softfloat中,双精度浮点数和单精度浮点数对异常值的处理方式是一致的,都是根据IEEE 754标准中定义的规则进行处理的。以下是softfloat中处理浮点异常值的部分代码示例:
```c
/*----------------------------------------------------------------------------
| Handle invalid operation exception.
*----------------------------------------------------------------------------*/
void softfloat_raiseFlags( int32_t flags )
{
float_exception_flags |= flags;
}
/*----------------------------------------------------------------------------
| Raise the invalid operation exception for a NaN operand.
*----------------------------------------------------------------------------*/
void softfloat_raiseNaNFlags( uint_fast64_t uiA )
{
if ( softfloat_isSigNaNF64UI( uiA ) || softfloat_isSigNaNF32UI( uiA ) ) {
softfloat_raiseFlags( float_flag_invalid );
}
}
/*----------------------------------------------------------------------------
| Determine whether the result of a float addition is NaN.
*----------------------------------------------------------------------------*/
bool softfloat_isNaNF32UI( uint_fast32_t uiA )
{
return
( ( uiA & 0x7F800000 ) == 0x7F800000 )
&& ( uiA & 0x007FFFFF );
}
/*----------------------------------------------------------------------------
| Perform a float-to-int conversion, rounding to nearest, with double rounding
| to even in the presence of a tie.
*----------------------------------------------------------------------------*/
int32_t softfloat_roundPackToF32( bool sign, int_fast16_t exp, uint_fast32_t sig )
{
int_fast8_t roundingMode;
bool roundNearEven;
int32_t absZ;
roundingMode = float_rounding_mode;
roundNearEven = ( roundingMode == float_round_nearest_even );
if ( 0x96 <= (uint16_t) exp ) {
if ( ( exp < 0 ) || ( sig | (uint32_t) ( exp << 13 ) ) ) {
softfloat_raiseFlags( float_flag_invalid );
return sign ? (int32_t) ui32_to_i64( 0x80000000 ) : 0x7FFFFFFF;
}
return sign ? (int32_t) ui32_to_i64( 0x80000000 ) : 0x7FFFFFFF;
}
if ( exp <= -0x6F ) {
if ( exp < -0x96 ) {
softfloat_roundPackFloatToExtF80M(
sign, exp + 0x7F, sig | 0x00800000, 0, &absZ );
return absZ;
}
return 0;
}
return
softfloat_roundPackMToF32(
sign, 0x7F + exp, sig | 0x00800000, roundingMode, roundNearEven
);
}
```
这里只是部分代码示例,softfloat中对不同类型浮点数的异常值处理代码比较复杂,需要对整个库进行详细的分析和理解。