Hi, This is a full patch for the roundeven variants along with documentation and additional testcases. The following code also conforms to GNU's coding standards. Thanks, Tejas 2019-08-22 Tejas Joshi Martin Jambor * builtins.c (mathfn_built_in_2): Added CASE_MATHFN for ROUNDEVEN. * builtins.def: Added function definitions for roundeven function variants. * fold-const-call.c (fold_const_call_ss): Added case for roundeven function call. * fold-const.c (negate_mathfn_p): Added case for roundeven function. (tree_call_nonnegative_warnv_p): Added case for roundeven function. (integer_valued_real_call_p): Added case for roundeven function. * real.c (is_even): New function. Returns true if real number is even, otherwise returns false. (is_halfway_below): New function. Returns true if real number is halfway between two integers, else return false. (real_roundeven): New function. Round real number to nearest integer, rounding halfway cases towards even. * real.h (real_value): Added descriptive comments. Added function declaration for roundeven function. * doc/extend.texi (Other Builtins): List roundeven variants among functions which can be handled as builtins. gcc/testsuite/ChangeLog: 2019-08-21 Tejas Joshi * gcc.dg/torture/builtin-round-roundeven.c: New test. * gcc.dg/torture/builtin-round-roundevenf128.c: New test. On Thu, 22 Aug 2019 at 20:03, Joseph Myers wrote: > > On Thu, 22 Aug 2019, Martin Jambor wrote: > > > +/* Round X to nearest integer, rounding halfway cases towards even. */ > > + > > +void > > +real_roundeven (REAL_VALUE_TYPE *r, format_helper fmt, > > + const REAL_VALUE_TYPE *x) > > +{ > > + if (is_halfway_below (x)) > > + { > > + do_add (r, x, &dconsthalf, x->sign); > > + if (!is_even (r)) > > + do_add (r, r, &dconstm1, x->sign); > > I'm concerned that this would produce +0.0 for an argument of -0.5 (via > -0.5 - 0.5 - -1.0 producing +0.0) when it needs to produce -0.0. > > Note that testcases for the sign of zero results need to check e.g. > !!__builtin_signbit on the result, or the result of calling > __builtin_copysign* to extract the sign of the result, since 0.0 == -0.0 > so checking with ==, while necessary, is not sufficient in that case. > > -- > Joseph S. Myers > joseph@codesourcery.com