Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
f32_to_i32.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_to_i32.c:

Go to the source code of this file.

Functions

int_fast32_t f32_to_i32 (float32_t a, uint_fast8_t roundingMode, bool exact)
 

Function Documentation

◆ f32_to_i32()

int_fast32_t f32_to_i32 ( float32_t a,
uint_fast8_t roundingMode,
bool exact )

Definition at line 44 of file f32_to_i32.c.

45{
46 union ui32_f32 uA;
47 uint_fast32_t uiA;
48 bool sign;
49 int_fast16_t exp;
50 uint_fast32_t sig;
51 uint_fast64_t sig64;
52 int_fast16_t shiftDist;
53
54 /*------------------------------------------------------------------------
55 *------------------------------------------------------------------------*/
56 uA.f = a;
57 uiA = uA.ui;
58 sign = signF32UI( uiA );
59 exp = expF32UI( uiA );
60 sig = fracF32UI( uiA );
61 /*------------------------------------------------------------------------
62 *------------------------------------------------------------------------*/
63#if (i32_fromNaN != i32_fromPosOverflow) || (i32_fromNaN != i32_fromNegOverflow)
64 if ( (exp == 0xFF) && sig ) {
65#if (i32_fromNaN == i32_fromPosOverflow)
66 sign = 0;
67#elif (i32_fromNaN == i32_fromNegOverflow)
68 sign = 1;
69#else
71 return i32_fromNaN;
72#endif
73 }
74#endif
75 /*------------------------------------------------------------------------
76 *------------------------------------------------------------------------*/
77 if ( exp ) sig |= 0x00800000;
78 sig64 = (uint_fast64_t) sig<<32;
79 shiftDist = 0xAA - exp;
80 if ( 0 < shiftDist ) sig64 = softfloat_shiftRightJam64( sig64, shiftDist );
81 return softfloat_roundToI32( sign, sig64, roundingMode, exact );
82
83}
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
void softfloat_raiseFlags(uint_fast8_t flags)
#define i32_fromNaN
Definition specialize.h:59
#define expF32UI(a)
Definition internals.h:105
#define fracF32UI(a)
Definition internals.h:106
#define signF32UI(a)
Definition internals.h:104
int_fast32_t softfloat_roundToI32(bool, uint_fast64_t, uint_fast8_t, bool)
uint64_t softfloat_shiftRightJam64(uint64_t a, uint_fast32_t dist)
@ softfloat_flag_invalid
Definition softfloat.h:89
uint64_t uint_fast64_t
Definition stdint.h:157
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: