aboutsummaryrefslogtreecommitdiff
path: root/softfloat/i32_to_f64.c
blob: c8b081193cad8eed1cbdd0fee1f0ec8b7e3c43f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// See LICENSE.SoftFloat for license details.


#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "primitives.h"
#include "internals.h"
#include "softfloat.h"

float64_t i32_to_f64( int_fast32_t a )
{
    uint_fast64_t uiZ;
    bool sign;
    uint_fast32_t absA;
    int shiftCount;
    union ui64_f64 uZ;

    if ( ! a ) {
        uiZ = 0;
    } else {
        sign = ( a < 0 );
        absA = sign ? - a : a;
        shiftCount = softfloat_countLeadingZeros32( absA ) + 21;
        uiZ =
            packToF64UI(
                sign, 0x432 - shiftCount, (uint_fast64_t) absA<<shiftCount );
    }
    uZ.ui = uiZ;
    return uZ.f;

}