On Sat, 30 Mar 2019, Tejas Joshi wrote: > Hello. > I have developed a fairly working patch for roundeven, attaching herewith. > The testcase function as follows : > > double f() > { > double x = 4.5; > double ret = __builtin_roundeven (x); > return ret; > }
Tests need to be added to the testsuite, covering a range of inputs and automatically verifying that the test is optimized correctly. "Round X to nearest even integer towards zero." is not correct. The roundeven function does not round to an even integer. It rounds to the nearest integer, whether even or odd - but, if two integers are equally close, the result is even (and for any input that is not halfway between two integers, it produces the same result as round (which rounds halfway cases away from zero) - so 2.501, 3 and 3.499 round to 3, but 2.5 rounds to 2 not 3, unlike round, and 3.5 rounds to 4, as with round). The function can't rely on arguments being in the range of HOST_WIDE_INT, so it needs to examine the REAL_VALUE_TYPE representation directly to determine whether it's half way between two integers and which way to round in that case. -- Joseph S. Myers jos...@codesourcery.com