Right, calling one particular rounding style round_ieee would be very odd –
the IEEE 754 spec lists various functions for rounding floats to integers
and doesn't favor any of them over the others. This is unlike rounding
modes where it does indicate that the default mode should be ties to even.


On Thu, Jun 5, 2014 at 8:42 AM, Simon Byrne <simonby...@gmail.com> wrote:

> On Thursday, 5 June 2014 09:47:21 UTC+1, Hans W Borchers wrote:
>>
>> What I would like to have is a function round_ieee(x,n) such that
>>
>>     julia> round_ieee(0.025, 2)
>>     0.02
>>
>> Can I do this somehow with with_rounding() do ... end ?
>>
>
> Not generally: the IEEE notions of even and odd only pertain to binary
> arithmetic (as determined by the last bit of the mantissa), trying to force
> this notion into approximate decimal representations is going to cause all
> sorts of confusion: technically the Float64 represented by 0.025 is
> actually 1.39e-18 larger than the exact 0.025, so should it be rounded to
> 0.03 instead?
>
> The IEEE754 spec itself only defines explicit rounding (as opposed to
> rounding after calculations) to integers (section 5.9 for those following
> along at home). According to the standard, IEEE754 compatible languages are
> required to provide methods for the following:
> a) round to nearest integral: ties to even
> b) round to nearest integral: ties to away (round)
> c) round to integral toward zero (trunc)
> d) round to integral toward positive (ceil)
> e) round to integral toward negative (floor)
> f) round to integral using rounding mode
>
> At the moment, I don't think we implement (a) or (f).
>

Reply via email to