Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Units initialize quantity with signaling NaN
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2016-08-13 12:56:41


AMDG

On 08/10/2016 08:55 PM, Belcourt, Kenneth wrote:
>
> I’m trying to find a way to initialize a Boost Unit with a signaling NaN, not just a NaN with the signal cleared. It seems that the only way to initialize a quantity is by multiplying by the unit, and that multiplication clears the signal on the NaN. I know I can just modify the quantity.hpp header and initialize the default constructor val_ member with the signaling NaN, but I was hoping for a cleaner solution.
>
> Here’s an example (typed in by hand, not tested):
>
> const double s_nan = std::numeric_limits<double>::signaling_NaN();
>
> typedef quantity<si::acceleration, double> acceleration_t;
> BOOST_UNITS_STATIC_CONSTANT(acceleration_u, acceleration);
>
> acceleration_t a(s_nan * acceleration_u); // <— this clears the signal on the NaN
>
> Has anyone encountered this or know of a more elegant solution than modifying the quantity.hpp header?
>

I can't reproduce the problem with VS 2015.

#include <boost/units/quantity.hpp>
#include <limits>
#include <boost/units/systems/si.hpp>
#include <iostream>

using boost::units::quantity;
namespace si = boost::units::si;

int main() {
    quantity<si::length> x(std::numeric_limits<double>::signaling_NaN()
* si::meter);
    std::cout << std::hex << *(unsigned long long*)&x << std::endl;
    return 0;
}

prints 7ff8000000000001

  Multiplication by a unit (as opposed to
a quantity) does not require a floating
point multiplication. It only copies the
value around. I have no idea why you're
seeing the signal bit being cleared.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net