Comments (8)
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.
Thanks, @JohelEGP and @mpusz, for the info and the confirmation. Keep up the good work! 👍
from mp-units.
The link doesn't look right.
from mp-units.
@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.
Sorry, I just looked at the wrong tab.
from mp-units.
Looks good to me 😃
from mp-units.
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.
There must be a better solution hiding somewhere...
Not in C++23.
from mp-units.
Related Issues (20)
- Should `quantity_point_like_traits` work on raw values?
- Consider using two types instead of values for the template parameters of the `reference` type HOT 1
- Bikeshedding `force_in(Unit)` HOT 10
- Change `mp-units/2.1.0` to `mp-units/2.0.0` in Conan installation steps? HOT 2
- Add support for easier math expressions in `mp-units/math.h` HOT 17
- Should we allow deriving from system entities? HOT 1
- No 2.1.0 in Conan center HOT 3
- ice_point definition is (very very slightly) incorrect
- Do we really need ASCII-only text output? HOT 13
- Text input support
- formatting/printing vector of quantities results in compile time error HOT 3
- Bazel build system support HOT 3
- Should conversions from the raw numerical value to a dimensionless quantity with a unit one be allowed? HOT 26
- Is mp-units targeting freestanding implementations HOT 6
- Provide `wchar_t` support for text output
- Effectively global unit names like 'm' are problematic HOT 35
- compilation time and how to improve it HOT 17
- Can't compile with localization disabled HOT 1
- Can't compile with exceptions disabled HOT 1
- Linker error with base units for "numerical_value_in()" HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mp-units.