|
Boost : |
Subject: Re: [boost] [safe_numerics] review
From: Robert Ramey (ramey_at_[hidden])
Date: 2017-03-11 17:25:41
On 3/10/17 11:10 AM, Peter Dimov via Boost wrote:
> John McFarlane wrote:
>
>> Conversion from integers to real numbers is not so much *unsafe* as
>> *lossy*. Users intuitively understand that `int n = 0.5;` will not
>> define a variable with value 0.5 and this is often exactly what they
>> intend, e.g.: [...]
>
> Converting to int a floating-point value that (absent the fractional
> part) cannot be represented in int is undefined behavior, so it is, in
> fact, unsafe, in addition to lossy.
Actually I missed that as well. I was permitting conversion of an int
to a float forgetting that this will change values for large integers.
So I should trap this as well.
Robert Ramey
BTW - when are we going to a comments form Peter Dimov?
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk