RE: round not in math.h?

"[email protected]" <[email protected]> Sun, 18 Sep 2005 08:49:40 +0200
Newsgroups gmane.comp.lang.eiffel.smalleiffel
Message-ID <[email protected]>
Hi Brian,

my message was a little too short, sorry. Yes, I use GCC.
The round function is defined in lib math (-lm) but seems to
be defined in the header only for C99 mode. The definition
is as follow in bits/mathcalls.h:
#ifdef __USE_ISOC99
__MATHCALLX (round,, (_Mdouble_ __x), (__const__));
...

In math.h, we can find the following:
/* The file <bits/mathcalls.h> contains the prototypes for
all the
   actual math functions.  These macros are used for those
prototypes,
   so we can easily declare each function as both `name' and
`__name',
   and can declare the float versions `namef' and `__namef'.  */

#define __MATHCALL(function,suffix, args)       \
  __MATHDECL (_Mdouble_,function,suffix, args)
#define __MATHDECL(type, function,suffix, args) \
  __MATHDECL_1(type, function,suffix, args); \
  __MATHDECL_1(type, __CONCAT(__,function),suffix, args)
#define __MATHCALLX(function,suffix, args, attrib)      \
  __MATHDECLX (_Mdouble_,function,suffix, args, attrib)
#define __MATHDECLX(type, function,suffix, args, attrib) \
  __MATHDECL_1(type, function,suffix, args) __attribute__
(attrib); \
  __MATHDECL_1(type, __CONCAT(__,function),suffix, args)
__attribute__ (attrib)
#define __MATHDECL_1(type, function,suffix, args) \
  extern type __MATH_PRECNAME(function,suffix) args __THROW

#define _Mdouble_               double
#define __MATH_PRECNAME(name,r) __CONCAT(name,r)
# define _Mdouble_BEGIN_NAMESPACE __BEGIN_NAMESPACE_STD
# define _Mdouble_END_NAMESPACE   __END_NAMESPACE_STD
#include <bits/mathcalls.h>

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

-----------------
Message from Brian Heilig:

Are you using GCC? I don't think it is implemented yet. This
is a workaround:

double round(double x)
{
  return (floor (x+0.5));
  // or
  // return (ceil (x-0.5));
}

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Saturday, September 17, 2005 4:40 PM
To: smarteiffel
Subject: round not in math.h?


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


------------ ALICE HAUT DEBIT A 29,95 EUR/MOIS ------------
ALICEBOX, l'offre Internet tout en 1 : ADSL, téléphonie,
modem Wi-Fi et en exclusivité la hotline gratuite 24h/24 !
Soumis à conditions. Pour en profiter cliquez ici
http://abonnement.aliceadsl.fr



************************************
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.
************************************


------------ ALICE HAUT DEBIT A 29,95 EUR/MOIS ------------
ALICEBOX, l'offre Internet tout en 1 : ADSL, téléphonie, modem Wi-Fi et en exclusivité
la hotline gratuite 24h/24 ! Soumis à conditions. Pour en profiter cliquez ici http://abonnement.aliceadsl.fr