Giter Site home page Giter Site logo

Comments (8)

mpusz avatar mpusz commented on June 3, 2024 1

This is why we use:

using std::isfinite;
return isfinite(a.numerical_value_ref_in(a.unit));

This allows the user to provide isfinite for the uncertainty type and use it as a representation type with quantity. In my talks, I already said that all math functions should become CPOs to simplify interoperability between various numeric libraries.

from mp-units.

RalphSteinhagen avatar RalphSteinhagen commented on June 3, 2024 1

Thanks, @JohelEGP and @mpusz, for the info and the confirmation. Keep up the good work! 👍

from mp-units.

JohelEGP avatar JohelEGP commented on June 3, 2024

The link doesn't look right.

from mp-units.

NAThompson avatar NAThompson commented on June 3, 2024

@JohelEGP : Just checked it, but nonetheless here's the full code:

#include <mp-units/systems/si/si.h>
#include <cmath>
#include <limits>

using namespace mp_units;
using namespace mp_units::si::unit_symbols;

namespace mp_units {

template<auto R, typename Rep>
[[nodiscard]] constexpr bool isfinite(const quantity<R, Rep>& a) noexcept
  requires 
  (requires {
    isfinite(a.numerical_value_ref_in(a.unit));
  } || requires {
    std::isfinite(a.numerical_value_ref_in(a.unit));
  })
{
  using std::isfinite;
  return isfinite(a.numerical_value_ref_in(a.unit));
}

}

#include <cassert>

int main() {
  constexpr auto t = 3.0*m;
  assert(isfinite(t));
  assert(!isfinite(std::numeric_limits<double>::quiet_NaN()*s));
  assert(!isfinite(std::numeric_limits<decltype(t)>::quiet_NaN()));
}

from mp-units.

JohelEGP avatar JohelEGP commented on June 3, 2024

Sorry, I just looked at the wrong tab.

from mp-units.

mpusz avatar mpusz commented on June 3, 2024

Looks good to me 😃

from mp-units.

RalphSteinhagen avatar RalphSteinhagen commented on June 3, 2024

The above code is perfectly fine.

Just a question for my education/curiosity about where C++ is heading to: I know overloading std:: templates with user-defined specialisations is frowned upon ...

Having said this ... does this mean that one will have to define all possible math operations and combinations in -- for example -- the namespace mp_units? That's going to be a lot of wrapper-style boilerplate code if one adds e.g. uncertainties, linear algebra, covariance matrices, w/ & w/o the std::complex<...> data types, etc... just to be able to write consistent formulas regardless of whether they are simple/unconstraint fundamental types (e.g. scalars/gain)), unit-constraint types, etc. 🤔

The beauty of the operator*(...) is that one can define and call upon them in and from any namespace as long as the specialisation knows about the user type.

There must be a better solution hiding somewhere...

from mp-units.

JohelEGP avatar JohelEGP commented on June 3, 2024

There must be a better solution hiding somewhere...

Not in C++23.

from mp-units.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.