RE: round not in math.h?

"Heilig, Brian - ACD " <[email protected]> Mon, 19 Sep 2005 10:14:52 -0400
Newsgroups gmane.comp.lang.eiffel.smalleiffel
Message-ID <56D2E48D28DC3B4EA5F2E4B7679D72F7049E2F@ACDNJMAILSRV03.acd.de.ittind.com>
No, this is similar to floor but dangerous. It only truncates the
fractional part and there is a risk that the float will not fit into the
integer:

"An rvalue of a floating point type can be converted to an rvalue of an
integer type. The conversion truncates; that is, the fractional part is
discarded. The behavior is undefined if the truncated value cannot be
represented in the destination type."

Brian

-----Original Message-----
From: Wolfgang Jansen [mailto:[email protected]]
Sent: Monday, September 19, 2005 4:13 AM
To: [email protected]
Cc: Heilig, Brian - ACD ; SmartEiffel
Subject: Re: round not in math.h?


[email protected] wrote:

>
>Now, as it is C99 dependant, it looks a bit hard to write portable code

>using "round". What to do? Use some trick as you proposed? Just
>defining the prototype for round function (as it is in  lib math)? This

>works on some systems but probably not all.
>
>Any other idea?
>
>Philippe Ribet
>
> 
>
Hello,
I think `round' is quite meaningless in C, simply use
double->int conversion instead:
  double d;
  int n;
  n = d;
  /* if you want a double result as for `round': */
  x = n;

Wolfgang Jansen

>Hello,
>
>according to "man round", round function is declared in math.h. But
>while including math.h the C compiler stills complain about undefined
>function. Moreover, I can't find "round" in math.h
>
>Does anyone know something about this problem?
>
>Thanks,
>
>Philippe Ribet
> 
>

************************************
This e-mail and any files transmitted with it are proprietary and intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Industries, Inc. The recipient should check this e-mail and any attachments for the presence of viruses. ITT Industries accepts no liability for any damage caused by any virus transmitted by this e-mail.
************************************