6 #include "specialize.h"
9 float64_t
f64_roundToInt( float64_t a
, int_fast8_t roundingMode
, bool exact
)
16 uint_fast64_t lastBitMask
, roundBitsMask
;
21 expA
= expF64UI( uiA
);
22 if ( 0x433 <= expA
) {
23 if ( ( expA
== 0x7FF ) && fracF64UI( uiA
) ) {
24 uiZ
= softfloat_propagateNaNF64UI( uiA
, 0 );
29 if ( expA
<= 0x3FE ) {
30 if ( ! ( uiA
& UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) ) return a
;
31 if ( exact
) softfloat_exceptionFlags
|= softfloat_flag_inexact
;
32 signA
= signF64UI( uiA
);
33 switch ( roundingMode
) {
34 case softfloat_round_nearest_even
:
35 if ( ( expA
== 0x3FE ) && fracF64UI( uiA
) ) {
36 uiZ
= packToF64UI( signA
, 0x3FF, 0 );
40 case softfloat_round_min
:
41 uiZ
= signA
? UINT64_C( 0xBFF0000000000000 ) : 0;
43 case softfloat_round_max
:
45 signA
? UINT64_C( 0x8000000000000000 )
46 : UINT64_C( 0x3FF0000000000000 );
48 case softfloat_round_nearest_maxMag
:
49 if ( expA
== 0x3FE ) {
50 uiZ
= packToF64UI( signA
, 0x3FF, 0 );
55 uiZ
= packToF64UI( signA
, 0, 0 );
58 lastBitMask
= (uint_fast64_t) 1<<( 0x433 - expA
);
59 roundBitsMask
= lastBitMask
- 1;
61 if ( roundingMode
== softfloat_round_nearest_maxMag
) {
62 uiZ
+= lastBitMask
>>1;
63 } else if ( roundingMode
== softfloat_round_nearest_even
) {
64 uiZ
+= lastBitMask
>>1;
65 if ( ! ( uiZ
& roundBitsMask
) ) uiZ
&= ~ lastBitMask
;
66 } else if ( roundingMode
!= softfloat_round_minMag
) {
67 if ( signF64UI( uiZ
) ^ ( roundingMode
== softfloat_round_max
) ) {
71 uiZ
&= ~ roundBitsMask
;
72 if ( exact
&& ( uiZ
!= uiA
) ) {
73 softfloat_exceptionFlags
|= softfloat_flag_inexact
;