Article View: comp.text
Article #170Re: Rounding function in c
From: Bill Reid
Date: Thu, 06 Aug 1992 18:48
Date: Thu, 06 Aug 1992 18:48
38 lines
1853 bytes
1853 bytes
In article <smr.712481385@hitkw14> smr@iti.org (Stephen Riehm) writes:
>theo@rascal.UUCP (1472) writes:
>
>>In article <1992Jul16.232926.4740@rossinc.com> ciaranst@rossinc.com (ciaran storan) writes:
[various rounding functions deleted]
Hey, this isn't comp.lang.c, and ANSI C isn't COBOL, guys! Seriously, I
immediately ran into the same problem trying to use C for financial
apps - no library functions to round to nearest integer. So I did the
following initially (later I came up with a compact version which is
not available here, but based on this):
#include <math.h>
int roundit(float);
int roundit(notround)
float notround;
{
int itround;
itround = (int)notround;
if ( ( notround - itround ) >= 0.5 )
itround = ++itround;
else if ( ( notround - itround ) < 0.5 )
itround = itround;
return itround;
}
This looks like it is ANSI C compatible (I think I have it compiled using
K&R). I have this in a utilities file which I include in any financial
apps; you call the function and pass notround to it, and it returns
itround. It has always worked for me on several machines, but the caveat
is that I am not a professional programmer by any wild stretch of
imagination.
Just my $0.02 of code.
Technical Details
Message-ID:
<182974@pyramid.pyramid.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!zephyr.ens.tek.com!uw-beaver!ubc-cs!destroyer!sol.ctr.columbia.edu!usc!cs.utexas.edu!sun-barr!news2me.ebay.sun.com!exodus.Eng.Sun.COM!sun!amdcad!weitek!pyramid!pyrhard2.eng.pyramid.com!breidReferences:
<1992Jul16.232926.4740@rossinc.com> <451@rascal.UUCP> <smr.712481385@hitkw14>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zephyr.ens.tek.com!uw-beaver!ubc-cs!destroyer!sol.ctr.columbia.edu!usc!cs.utexas.edu!sun-barr!news2me.ebay.sun.com!exodus.Eng.Sun.COM!sun!amdcad!weitek!pyramid!pyrhard2.eng.pyramid.com!breid From: breid@pyrhard2.eng.pyramid.com (Bill Reid) Newsgroups: comp.text Subject: Re: Rounding function in c Message-ID: <182974@pyramid.pyramid.com> Date: 6 Aug 92 18:48:10 GMT References: <1992Jul16.232926.4740@rossinc.com> <451@rascal.UUCP> <smr.712481385@hitkw14> Sender: news@pyramid.pyramid.com Organization: Pyramid Technology Corporation, Mountain View Lines: 38