mirror of
https://github.com/abakh/nbsdgames.git
synced 2025-01-03 14:56:23 -05:00
simplify round()
This commit is contained in:
parent
1a97f58c09
commit
1e3bcb176c
@ -25,19 +25,12 @@ NOTE: This program is only made for entertainment porpuses. The puzzles are gene
|
|||||||
/* I hope this is approximately right */
|
/* I hope this is approximately right */
|
||||||
int round(float x)
|
int round(float x)
|
||||||
{
|
{
|
||||||
int y=(int) x;
|
int y;
|
||||||
int z;
|
|
||||||
if(x > 0)
|
if(x > 0)
|
||||||
if(x-y > 0.5)
|
y = (int)(x + 0.5); //int will round down, so if the decimal of x is .5 or higher this will round up.
|
||||||
z = (int)(x + 0.5);
|
else if(x < 0)
|
||||||
else
|
y = (int)(x - 0.5); // the same but opposite
|
||||||
z = y;
|
return y;
|
||||||
if(x<0)
|
|
||||||
if(x-y < -0.5)
|
|
||||||
z = (int)(x -0.5);
|
|
||||||
else
|
|
||||||
z = y;
|
|
||||||
return z;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user