1
0
mirror of https://github.com/abakh/nbsdgames.git synced 2024-12-04 14:46:22 -05:00

simplify round()

This commit is contained in:
Jens Staal 2020-06-15 06:27:45 +02:00
parent 1a97f58c09
commit 1e3bcb176c

View File

@ -25,19 +25,12 @@ NOTE: This program is only made for entertainment porpuses. The puzzles are gene
/* I hope this is approximately right */
int round(float x)
{
int y=(int) x;
int z;
int y;
if(x > 0)
if(x-y > 0.5)
z = (int)(x + 0.5);
else
z = y;
if(x<0)
if(x-y < -0.5)
z = (int)(x -0.5);
else
z = y;
return z;
y = (int)(x + 0.5); //int will round down, so if the decimal of x is .5 or higher this will round up.
else if(x < 0)
y = (int)(x - 0.5); // the same but opposite
return y;
}
#endif