number-to-f32

xod/bits/number-to-f32

Converts a number to 32-bit IEEE-754 encoded floating point number presented as four bytes. An input for the the conversion should be between -3.4E+38 to 3.4E+38 with an accuracy of 7 digits. It means, a float number greater than seven digits in length will be inaccurate and lose a fractional part.
number-to-f32
@/number-to-f32
Converts a number to 32-bit IEEE-754 encoded floating point number presented as four bytes. An input for the the conversion should be between -3.4E+38 to 3.4E+38 with an accuracy of 7 digits. It means, a float number greater than seven digits in length will be inaccurate and lose a fractional part.
INnumber
number-to-f32
IN
B3
B2
B1
B0
B0byte
Most significant byte
B1byte
B2byte
B3byte
Least significant byte

C++ implementation

node {
    void evaluate(Context ctx) {
        Number val = getValue<input_IN>(ctx);
        uint8_t* bytes = (uint8_t*)&val;

        emitValue<output_B3>(ctx, bytes[3]);
        emitValue<output_B2>(ctx, bytes[2]);
        emitValue<output_B1>(ctx, bytes[1]);
        emitValue<output_B0>(ctx, bytes[0]);
    }
}

Tabular tests

INB3B2B1B0
-150000.125C8h12h7Ch08h
150000.12548h12h7Ch08h
0.0000h00h00h00h
1.003Fh80h00h00h
-1.00BFh80h00h00h