Round function which actually work.

I'm so stupid x(
Thanks Lephé.
This commit is contained in:
KikooDX 2021-03-04 17:39:08 +01:00
parent d40d6a5fb4
commit 7f72ba9dad
1 changed files with 3 additions and 7 deletions

View File

@ -186,12 +186,8 @@ f32 signf(f32 value) {
}
i8 round(f32 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;
if (value > 0)
return (i8)(value + 0.5);
else
return value_as_int;
return (i8)(value - 0.5);
}