5 #include "primitives.h"
10 softfloat_roundPackToF32( bool sign
, int_fast16_t exp
, uint_fast32_t sig
)
13 bool roundNearestEven
;
14 int roundIncrement
, roundBits
;
19 roundingMode
= softfloat_roundingMode
;
20 roundNearestEven
= ( roundingMode
== softfloat_round_nearest_even
);
21 roundIncrement
= 0x40;
24 && ( roundingMode
!= softfloat_round_nearest_maxMag
)
27 ( roundingMode
== softfloat_round_minMag
)
29 == ( sign
? softfloat_round_max
: softfloat_round_min
) )
33 roundBits
= sig
& 0x7F;
34 if ( 0xFD <= (uint16_t) exp
) {
37 ( softfloat_detectTininess
38 == softfloat_tininess_beforeRounding
)
40 || ( sig
+ roundIncrement
< 0x80000000 );
41 sig
= softfloat_shift32RightJam( sig
, - exp
);
43 roundBits
= sig
& 0x7F;
44 if ( isTiny
&& roundBits
) {
45 softfloat_raiseFlags( softfloat_flag_underflow
);
48 ( 0xFD < exp
) || ( 0x80000000 <= sig
+ roundIncrement
)
51 softfloat_flag_overflow
| softfloat_flag_inexact
);
52 uiZ
= packToF32UI( sign
, 0xFF, 0 ) - ! roundIncrement
;
56 if ( roundBits
) softfloat_exceptionFlags
|= softfloat_flag_inexact
;
57 sig
= ( sig
+ roundIncrement
)>>7;
58 sig
&= ~ ( ! ( roundBits
^ 0x40 ) & roundNearestEven
);
59 uiZ
= packToF32UI( sign
, sig
? exp
: 0, sig
);