www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.math: FloatingPointControl option to round to nearest + tie away from zero

reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
https://en.wikipedia.org/wiki/IEEE_floating_point#Roundings_to_nearest says 
that IEEE 754 provides two options for rounding to nearest: ties to even and 
ties away from zero. 

However, under https://github.com/D-Programming-Language/phobos/blob/mas
er/std/math.d#L4539 we have only one roundToNearest 
which, I presume, ties to even.

Is there a difficulty in providing the option for tieing away from zero?

Thanks.

-- 

Dec 10 2015
parent Matthias Bentrup <matthias.bentrup googlemail.com> writes:
On Friday, 11 December 2015 at 05:25:03 UTC, Shriramana Sharma 
wrote:
 https://en.wikipedia.org/wiki/IEEE_floating_point#Roundings_to_nearest says
that IEEE 754 provides two options for rounding to nearest: ties to even and
ties away from zero.

 However, under 
 https://github.com/D-Programming-Language/phobos/blob/master/std/math.d#L4539
we have only one roundToNearest which, I presume, ties to even.

 Is there a difficulty in providing the option for tieing away 
 from zero?

 Thanks.
Those are basically the rounding modes supported by the FPUs in hardware. Any other rounding modes would have to be emulated in software, which would require the compiler to generate completely different code instead of just changing a few bits in an FPU control register.
Dec 11 2015