nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
938 stars 134 forks source link

Not a Number - values #282

Open wouterz opened 2 years ago

wouterz commented 2 years ago

Is a pull request extending the library with better NaN (numeric_limts::quiet/signaling)_NaN / :::infinity ) support considered, or are they omitted with reason? Additionally, if possible an extension of std::isnan might also be desirable.

nholthaus commented 2 years ago

They're not omitted for any reason. I'd certainly consider such a PR.

On Mon, Nov 15, 2021, 5:00 AM Wouter @.***> wrote:

Is a pull request extending the library with better NaN (numeric_limts::quiet/signaling)_NaN / :::infinity ) support considered, or are they omitted with reason? Additionally, an extension of std::isnan might be desirable.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nholthaus/units/issues/282, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACOYOH6DM24IYSRVLZYBNQTUMDK2XANCNFSM5IBILRQA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

wouterz commented 2 years ago

Adding the numeric_limit functions it quite easy, spent quite some time trying to extend std::isnan, but im quite new to SFINAE / meta.

I feel like it should be something like:

template<typename UnitType, typename = std::enable_if_t<units::traits::is_unit_t<UnitType>::value && std::is_floating_point_v<UnitType::underlying_type>::value> >
    inline bool isnan(const UnitType& x)
    {
        return std::isnan(x.value());
    }

any ideas?

nholthaus commented 1 year ago

added NAN support in 3.0. Consider backporting to 2.3