{Geek} Spot the error
Mar. 12th, 2003 02:28 pmSpot the error, win a pint/drink thereof... and no, I didn't write this
int SimpleRound ( double high )
{
int low = (int) high;
double diff;
int result;
diff = high - low;
if (diff>=0)
result = ( diff >= (double)0.5000000 ) ? (low + 1) : low;
else
result = ( diff >= (double)-0.5000000 ) ? (low - 1) : low;
return (result);
}
int SimpleRound ( double high )
{
int low = (int) high;
double diff;
int result;
diff = high - low;
if (diff>=0)
result = ( diff >= (double)0.5000000 ) ? (low + 1) : low;
else
result = ( diff >= (double)-0.5000000 ) ? (low - 1) : low;
return (result);
}
no subject
Date: 2003-03-12 06:36 am (UTC)isn't right
Should be
result = ( diff < (double)-0.5000000 ) ? (low - 1) : low;
That right?
no subject
Date: 2003-03-12 06:54 am (UTC)no subject
Date: 2003-03-12 07:25 am (UTC)int SimpleRound ( double high )
{
double temphigh;
temphigh += (double)0.5;
return (int)temphigh;
}
is so much more elegant.
And even that is poor, really, as it relies on the cast working as you expect. There's almost certainly a library function to do this anyway, and that should be used.
no subject
Date: 2003-03-12 07:25 am (UTC)double temphigh=high;
Stupid non-edity comments
no subject
Date: 2003-03-12 07:36 am (UTC)Huzah.
While I'm not a programmer...
Date: 2003-03-12 06:41 am (UTC)a) is that a multiplication
b) should it be?
Re: While I'm not a programmer...
Date: 2003-03-12 06:55 am (UTC)RBS got the correct answer :)
no subject
Date: 2003-03-12 06:54 am (UTC)no subject
Date: 2003-03-12 06:56 am (UTC)no subject
Date: 2003-03-12 06:57 am (UTC)no subject
Date: 2003-03-12 07:37 am (UTC)no subject
Date: 2003-03-12 07:55 am (UTC)no subject
Date: 2003-03-12 07:57 am (UTC)no subject
Date: 2003-03-12 07:27 am (UTC)Runs of to hide
no subject
Date: 2003-03-12 07:36 am (UTC)no subject
Date: 2003-03-12 02:41 pm (UTC)O'grade project before final submission due to him having written it in BASIC and no teacher decided to tell me before then - damn them - still first successful oevr-nighter of code writing'ness how its stood me in good stead since then :O)
no subject
Date: 2003-03-12 07:56 am (UTC)Hold competitions that I can't win booze from you in, I see :p
no subject