aboutsummaryrefslogtreecommitdiff
path: root/softfloat/f64_to_f32.c
diff options
context:
space:
mode:
Diffstat (limited to 'softfloat/f64_to_f32.c')
-rwxr-xr-xsoftfloat/f64_to_f32.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/softfloat/f64_to_f32.c b/softfloat/f64_to_f32.c
new file mode 100755
index 0000000..395d6c6
--- /dev/null
+++ b/softfloat/f64_to_f32.c
@@ -0,0 +1,43 @@
+
+#include <stdbool.h>
+#include <stdint.h>
+#include "platform.h"
+#include "primitives.h"
+#include "internals.h"
+#include "specialize.h"
+#include "softfloat.h"
+
+float32_t f64_to_f32( float64_t a )
+{
+ union ui64_f64 uA;
+ uint_fast64_t uiA;
+ bool sign;
+ int_fast16_t exp;
+ uint_fast64_t sig;
+ uint_fast32_t uiZ, sig32;
+ union ui32_f32 uZ;
+
+ uA.f = a;
+ uiA = uA.ui;
+ sign = signF64UI( uiA );
+ exp = expF64UI( uiA );
+ sig = fracF64UI( uiA );
+ if ( exp == 0x7FF ) {
+ uiZ =
+ sig ? softfloat_commonNaNToF32UI(
+ softfloat_f64UIToCommonNaN( uiA ) )
+ : packToF32UI( sign, 0xFF, 0 );
+ goto uiZ;
+ }
+ sig32 = softfloat_shortShift64RightJam( sig, 22 );
+ if ( ! ( exp | sig32 ) ) {
+ uiZ = packToF32UI( sign, 0, 0 );
+ goto uiZ;
+ }
+ return softfloat_roundPackToF32( sign, exp - 0x381, sig32 | 0x40000000 );
+ uiZ:
+ uZ.ui = uiZ;
+ return uZ.f;
+
+}
+