5 #include "primitives.h"
10 softfloat_roundPackToF64( bool sign
, int_fast16_t exp
, uint_fast64_t sig
)
13 bool roundNearestEven
;
14 int roundIncrement
, roundBits
;
19 roundingMode
= softfloat_roundingMode
;
20 roundNearestEven
= ( roundingMode
== softfloat_round_nearest_even
);
21 roundIncrement
= 0x200;
24 && ( roundingMode
!= softfloat_round_nearest_maxMag
)
27 ( roundingMode
== softfloat_round_minMag
)
29 == ( sign
? softfloat_round_max
: softfloat_round_min
) )
33 roundBits
= sig
& 0x3FF;
34 if ( 0x7FD <= (uint16_t) exp
) {
37 ( softfloat_detectTininess
38 == softfloat_tininess_beforeRounding
)
40 || ( sig
+ roundIncrement
< UINT64_C( 0x8000000000000000 ) );
41 sig
= softfloat_shift64RightJam( sig
, - exp
);
43 roundBits
= sig
& 0x3FF;
44 if ( isTiny
&& roundBits
) {
45 softfloat_raiseFlags( softfloat_flag_underflow
);
49 || ( UINT64_C( 0x8000000000000000 ) <= sig
+ roundIncrement
)
52 softfloat_flag_overflow
| softfloat_flag_inexact
);
53 uiZ
= packToF64UI( sign
, 0x7FF, 0 ) - ! roundIncrement
;
57 if ( roundBits
) softfloat_exceptionFlags
|= softfloat_flag_inexact
;
58 sig
= ( sig
+ roundIncrement
)>>10;
59 sig
&= ~ ( ! ( roundBits
^ 0x200 ) & roundNearestEven
);
60 uiZ
= packToF64UI( sign
, sig
? exp
: 0, sig
);