----- Carlos R. Mafra <[email protected]> a écrit :
> On Sun, 16 Jun 2013 at 21:50:59 +0200, Christophe wrote:
> > From: Christophe CURIS <[email protected]>
> > 
> > The current code in WINGs makes use of the 'rint' function at a few
> > places to round a double when the result is to be stored into an
> > int typed variable.
> > 
> > The right function to do this is actually 'lrint', but as both functions
> > suffer from portability issues we check for a few ones and pick the
> > first that is available.
> > 
> > The function then becomes available as a macro 'wm_rint()' from 'config.h'.
> 
> I don't quite like the random element introduced by this patch, as
> wm_rint() can be many different things now -- wm_rint() becomes round()
> for me instead of rint() and they have different rounding behavior.
> 
> And you've made the whole thing more complex by coding all this in
> the .m4 file and making wm_rint() a macro.


Actually, the m4 file is the price for compatibility, because 'rint' is not 
universally available (it has only been normalised as part of POSIX as you can 
see in its man page), and the simplest way to keep the code simple is to use a 
macro instead of a complex #ifdef mechanism.

But we may wait until someone has a problem with that before considering the 
change.

As a funny side note, if you are really concerned by non random behaviour, I 
invite you to have a second look at the 'rint' man page and point me where you 
see a consistent behaviour in the function...


> > Signed-off-by: Christophe CURIS <[email protected]>
> > ---
> >  m4/wm_libmath.m4 |   31 +++++++++++++++++++++++++++++++
> >  1 file changed, 31 insertions(+)
> > 
> > diff --git a/m4/wm_libmath.m4 b/m4/wm_libmath.m4
> > index 49bd677..acca5d7 100644
> > --- a/m4/wm_libmath.m4
> > +++ b/m4/wm_libmath.m4
> > @@ -21,12 +21,20 @@
> >  #
> >  # Checks the needed library link flags needed to have math lib
> >  # Sets variable LIBM with the appropriates flags
> > +#
> > +# Checks for an appropriate rounding function as needed by WINGs
> > +# and defines a macro 'wm_rint' for it in 'config.h'
> >  AC_DEFUN_ONCE([WM_CHECK_LIBM],
> >  [AC_CHECK_HEADER([math.h], [],
> >                   [AC_MSG_ERROR([header for math library not found])])
> >  _WM_SEARCH_MATHLIB([atan], [],
> >      [AC_MSG_FAILURE([could not link with math library])] )
> >  AC_SUBST(LIBM) dnl
> > +_WM_FIND_MATHFUNC([for math rounding function],
> > +    [roundfct], [lrint rint round floor],
> > +    [AC_DEFINE_UNQUOTED([wm_rint(x)], [${wm_cv_mathlib_roundfct}[( x )]],
> > +        [Macro to round a double-float to be converted to integer])],
> > +    [AC_MSG_ERROR([no known rounding function found in math library])]) dnl
> >  ])
> >  
> >  # _WM_SHELLFN_MATHLINK
> > @@ -94,3 +102,26 @@ AC_CACHE_CHECK([for math library using $1], 
> > [wm_cv_mathlib_lflags],
> >          [LIBM="$wm_cv_mathlib_lflags"
> >           $2]) dnl
> >  ])
> > +
> > +# _WM_FIND_MATHFUNC(description, name, function_list, [action-if-ok], 
> > [action-if-nok])
> > +# 
> > ------------------------------------------------------------------------------------
> > +# (internal macro only!)
> > +#
> > +# Search for the first function in the list that can be linked to, using 
> > $LIBM
> > +# for the linker options (typically math library detected from previous 
> > macro)
> > +#
> > +# the description is used for the message displayed
> > +#
> > +# on success, the name is stored in 'wm_cv_mathlib_$name' before executing
> > +# the action-if-ok
> > +AC_DEFUN([_WM_FIND_MATHFUNC],
> > +[AC_REQUIRE([_WM_SHELLFN_MATHLINK])
> > +AC_CACHE_CHECK([$1], [wm_cv_mathlib_$2],
> > +    [for FCT in $3
> > +     do
> > +       AS_IF([wm_fn_c_try_link_mathfunc $FCT "$LIBM"],
> > +           [wm_cv_mathlib_$2=$FCT
> > +            break])
> > +     done])
> > +AS_VAR_SET_IF([wm_cv_mathlib_$2], [$4], [$5]) dnl
> > +])
> > -- 
> > 1.7.10.4


--
To unsubscribe, send mail to [email protected].

Reply via email to