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

Go to the source code of this file.

Functions

uint_fast32_t softfloat_roundToUI32 (bool sign, uint_fast64_t sig, uint_fast8_t roundingMode, bool exact)
 

Function Documentation

◆ softfloat_roundToUI32()

uint_fast32_t softfloat_roundToUI32 ( bool sign,
uint_fast64_t sig,
uint_fast8_t roundingMode,
bool exact )

Definition at line 45 of file s_roundToUI32.c.

47{
48 uint_fast16_t roundIncrement, roundBits;
50
51 /*------------------------------------------------------------------------
52 *------------------------------------------------------------------------*/
53 roundIncrement = 0x800;
54 if (
55 (roundingMode != softfloat_round_near_maxMag)
56 && (roundingMode != softfloat_round_near_even)
57 ) {
58 roundIncrement = 0;
59 if ( sign ) {
60 if ( !sig ) return 0;
61 if ( roundingMode == softfloat_round_min ) goto invalid;
62#ifdef SOFTFLOAT_ROUND_ODD
63 if ( roundingMode == softfloat_round_odd ) goto invalid;
64#endif
65 } else {
66 if ( roundingMode == softfloat_round_max ) roundIncrement = 0xFFF;
67 }
68 }
69 roundBits = sig & 0xFFF;
70 sig += roundIncrement;
71 if ( sig & UINT64_C( 0xFFFFF00000000000 ) ) goto invalid;
72 z = sig>>12;
73 if (
74 (roundBits == 0x800) && (roundingMode == softfloat_round_near_even)
75 ) {
76 z &= ~(uint_fast32_t) 1;
77 }
78 if ( sign && z ) goto invalid;
79 if ( roundBits ) {
80#ifdef SOFTFLOAT_ROUND_ODD
81 if ( roundingMode == softfloat_round_odd ) z |= 1;
82#endif
84 }
85 return z;
86 /*------------------------------------------------------------------------
87 *------------------------------------------------------------------------*/
88 invalid:
91
92}
void softfloat_raiseFlags(uint_fast8_t flags)
#define ui32_fromNegOverflow
Definition specialize.h:55
#define ui32_fromPosOverflow
Definition specialize.h:54
@ softfloat_flag_invalid
Definition softfloat.h:89
@ 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
uint16_t uint_fast16_t
Definition stdint.h:155
#define UINT64_C(val)
Definition stdint.h:284
uint32_t uint_fast32_t
Definition stdint.h:156