home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 1
/
FishNMoreVol1.bin
/
more
/
code_examples
/
librar
/
round.c
< prev
next >
Wrap
Text File
|
1989-02-08
|
1KB
|
47 lines
/*--------------------------------------*/
/* */
/* ROUND(X) */
/* */
/* Takes floating point numbers and */
/* returns the rounded integer. */
/* */
/*--------------------------------------*/
round(a)
float a;
{
int x,negflag;
float ff;
if (!a)
return(0);
negflag=0;
if (a<0.0){
negflag=1;
a*=-1.0;
}
x=a;
if (x==a){
if (negflag==1)
return(-1*x);
return(x);
}
ff=a-x;
if (ff<.5){
if (negflag==1)
return(-1*x);
return(x);
}
if (ff>.5){
if (negflag==1)
return(-1*(x+1));
return(x+1);
}
if (!efactor(x,2)){
if (negflag==1)
return(-1*x);
return(x);
}
if (negflag==1)
return(-1*(x+1));
return(x+1);
}