trunc

koadrobot/math/trunc

Truncate integer part of number.
trunc
@/trunc
Truncate integer part of number.
INnumber
trunc
IN
OUT
OUTnumber
2.5 = 2 -2.5 = -2
To use the node in your project you should have the koadrobot/math library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD dirtieness disable

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    auto x = getValue<input_IN>(ctx);
    emitValue<output_OUT>(ctx, trunc(x));
    // emitValue<output_OUT>(ctx, (x < 0) ? ceil(x): floor(x));
}

Tabular tests

INOUT
00
-1-1
11
-2.4-2
-2.5-2
2.42
2.52
NaNNaN
InfInf
-Inf-Inf