From: Derek Greene Newsgroups: comp.os.msdos.djgpp Subject: Re: Round function? Date: Wed, 28 Oct 1998 17:38:02 -0500 Organization: MindSpring Enterprises Lines: 36 Message-ID: <36379CC9.ED6121A9@mindspring.com> References: <36374585 DOT CADABD29 AT mindspring DOT com> <87vhl4k1ec DOT fsf AT hasn DOT dera DOT gov DOT uk> NNTP-Posting-Host: user-37kbbl6.dialup.mindspring.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 28 Oct 1998 22:34:20 GMT X-Mailer: Mozilla 4.5 [en] (Win95; I) X-Accept-Language: en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I chose this newsgroup, because I dont have a C specific one I read. I've been programming C for around 3 years now, but, I've honestly never done a whole lot with floating-point numbers. I knew in assembly you had to round before bringing the number from the FPU to the CPU, so i figured there would be a functionf or this in C (not to mention I had always done this with pascal :-) Derek Greene out. Ian Miller wrote: > Derek Greene writes: > > > Is there a functionf or rounding off real numbers when casting to > > integers or will a normal type cast do the trick? TIA > > Depending on what you want to do one of > (int) realnumber > (int) (realnumber + 0.5) > might be suitable. Of course, you might want to consider whether or not > realnumber is positive or negative as well. And if you wanted to stay > in floating point, floor() and ceil() in the standard C library are > probably useful. > > Anyway, ask this sort of question in a C programming newsgroup next time. > This is rather off topic in these parts. > > Also you might want to consider getting a basic C book. Unless one is > learning C by trial and error there is no realistic alternative ;) > > Ian > -- > Ian Miller, Dorset, UK > The views expressed above are those of the writer and do not represent the > views, policy, or understanding of any other person or official body.