Mail Archives: djgpp/1998/10/28/17:40:08
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 <notsotopcoder AT mindspring DOT com> 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.
- Raw text -