Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
f32_roundToInt.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "internals.h"
#include "specialize.h"
#include "softfloat.h"
Include dependency graph for f32_roundToInt.c:

Go to the source code of this file.

Functions

float32_t f32_roundToInt (float32_t a, uint_fast8_t roundingMode, bool exact)
 

Function Documentation

◆ f32_roundToInt()

float32_t f32_roundToInt ( float32_t a,
uint_fast8_t roundingMode,
bool exact )

Definition at line 44 of file f32_roundToInt.c.

45{
46 union ui32_f32 uA;
47 uint_fast32_t uiA;
48 int_fast16_t exp;
49 uint_fast32_t uiZ, lastBitMask, roundBitsMask;
50 union ui32_f32 uZ;
51
52 /*------------------------------------------------------------------------
53 *------------------------------------------------------------------------*/
54 uA.f = a;
55 uiA = uA.ui;
56 exp = expF32UI( uiA );
57 /*------------------------------------------------------------------------
58 *------------------------------------------------------------------------*/
59 if ( exp <= 0x7E ) {
60 if ( !(uint32_t) (uiA<<1) ) return a;
62 uiZ = uiA & packToF32UI( 1, 0, 0 );
63 switch ( roundingMode ) {
65 if ( !fracF32UI( uiA ) ) break;
67 if ( exp == 0x7E ) uiZ |= packToF32UI( 0, 0x7F, 0 );
68 break;
70 if ( uiZ ) uiZ = packToF32UI( 1, 0x7F, 0 );
71 break;
73 if ( !uiZ ) uiZ = packToF32UI( 0, 0x7F, 0 );
74 break;
75#ifdef SOFTFLOAT_ROUND_ODD
77 uiZ |= packToF32UI( 0, 0x7F, 0 );
78 break;
79#endif
80 }
81 goto uiZ;
82 }
83 /*------------------------------------------------------------------------
84 *------------------------------------------------------------------------*/
85 if ( 0x96 <= exp ) {
86 if ( (exp == 0xFF) && fracF32UI( uiA ) ) {
87 uiZ = softfloat_propagateNaNF32UI( uiA, 0 );
88 goto uiZ;
89 }
90 return a;
91 }
92 /*------------------------------------------------------------------------
93 *------------------------------------------------------------------------*/
94 uiZ = uiA;
95 lastBitMask = (uint_fast32_t) 1<<(0x96 - exp);
96 roundBitsMask = lastBitMask - 1;
97 if ( roundingMode == softfloat_round_near_maxMag ) {
98 uiZ += lastBitMask>>1;
99 } else if ( roundingMode == softfloat_round_near_even ) {
100 uiZ += lastBitMask>>1;
101 if ( !(uiZ & roundBitsMask) ) uiZ &= ~lastBitMask;
102 } else if (
103 roundingMode
105 ) {
106 uiZ += roundBitsMask;
107 }
108 uiZ &= ~roundBitsMask;
109 if ( uiZ != uiA ) {
110#ifdef SOFTFLOAT_ROUND_ODD
111 if ( roundingMode == softfloat_round_odd ) uiZ |= lastBitMask;
112#endif
114 }
115 uiZ:
116 uZ.ui = uiZ;
117 return uZ.f;
118
119}
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
uint_fast32_t softfloat_propagateNaNF32UI(uint_fast32_t uiA, uint_fast32_t uiB)
#define expF32UI(a)
Definition internals.h:105
#define fracF32UI(a)
Definition internals.h:106
#define signF32UI(a)
Definition internals.h:104
#define packToF32UI(sign, exp, sig)
Definition internals.h:107
@ softfloat_flag_inexact
Definition softfloat.h:85
THREAD_LOCAL uint_fast8_t softfloat_exceptionFlags
@ softfloat_round_odd
Definition softfloat.h:77
@ softfloat_round_max
Definition softfloat.h:75
@ softfloat_round_min
Definition softfloat.h:74
@ softfloat_round_near_even
Definition softfloat.h:72
@ softfloat_round_near_maxMag
Definition softfloat.h:76
unsigned int uint32_t
Definition stdint.h:126
uint32_t uint_fast32_t
Definition stdint.h:156
int16_t int_fast16_t
Definition stdint.h:151
float32_t f
Definition internals.h:46
Here is the call graph for this function: