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:
parent
8307944517
commit
2d4afbd1e9
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue