6 #include "specialize.h"
9 float32_t
f32_roundToInt( float32_t a
, int_fast8_t roundingMode
, bool exact
)
16 uint_fast32_t lastBitMask
, roundBitsMask
;
21 expA
= expF32UI( uiA
);
23 if ( ( expA
== 0xFF ) && fracF32UI( uiA
) ) {
24 uiZ
= softfloat_propagateNaNF32UI( uiA
, 0 );
30 if ( ! (uint32_t) ( uiA
<<1 ) ) return a
;
31 if ( exact
) softfloat_exceptionFlags
|= softfloat_flag_inexact
;
32 signA
= signF32UI( uiA
);
33 switch ( roundingMode
) {
34 case softfloat_round_nearest_even
:
35 if ( ( expA
== 0x7E ) && fracF32UI( uiA
) ) {
36 uiZ
= packToF32UI( signA
, 0x7F, 0 );
40 case softfloat_round_min
:
41 uiZ
= signA
? 0xBF800000 : 0;
43 case softfloat_round_max
:
44 uiZ
= signA
? 0x80000000 : 0x3F800000;
46 case softfloat_round_nearest_maxMag
:
48 uiZ
= packToF32UI( signA
, 0x7F, 0 );
53 uiZ
= packToF32UI( signA
, 0, 0 );
56 lastBitMask
= (uint_fast32_t) 1<<( 0x96 - expA
);
57 roundBitsMask
= lastBitMask
- 1;
59 if ( roundingMode
== softfloat_round_nearest_maxMag
) {
60 uiZ
+= lastBitMask
>>1;
61 } else if ( roundingMode
== softfloat_round_nearest_even
) {
62 uiZ
+= lastBitMask
>>1;
63 if ( ! ( uiZ
& roundBitsMask
) ) uiZ
&= ~ lastBitMask
;
64 } else if ( roundingMode
!= softfloat_round_minMag
) {
65 if ( signF32UI( uiZ
) ^ ( roundingMode
== softfloat_round_max
) ) {
69 uiZ
&= ~ roundBitsMask
;
70 if ( exact
&& ( uiZ
!= uiA
) ) {
71 softfloat_exceptionFlags
|= softfloat_flag_inexact
;