A round function that does it's job.

Looks good but codewise but probably has terrible performance, we'll
see how this goes.
This commit is contained in:
KikooDX 2021-03-04 15:31:00 +01:00
parent 8307944517
commit 2d4afbd1e9
1 changed files with 8 additions and 1 deletions

View File

@ -177,5 +177,12 @@ f32 signf(f32 value) {
}
i8 round(f32 value) {
return (i8)value;
const i8 value_as_int = (i8)value;
const f32 rest = value - (f32)(value_as_int * sign(value_as_int));
if (rest >= 0.5)
return value_as_int + 1;
else if (rest <= -0.5)
return value_as_int - 1;
else
return value_as_int;
}