Comments (7)
from mp-units.
Thanks John, this an interesting idea. However, I wouldn't like users to be forced to partially specialize std::numeric_limits
for their types to add this support. Even if they will do that, numeric_limits
does not guarantee us the availability of arithmetic operators so things like:
quantity<metre, MyRep> d1(MyRep{1});
quantity<metre, MyRep> d2(MyRep{2});
auto d = d1 + d2;
may not compile with instantiation errors inside the library implementation rather than by constraints check for template arguments.
This is why I believe that we should try with the above idea for a concept. It does not have to be named Number
. It might be any of:
std::number
std::arithmetic
std::integral
std::floating_point
std::integral_arithmetic
std::floating_point_arithmetic
or whatever SG6 experts will decide to be viable here.
Please also note that Physical Units Library is not the only customer for such a concept. Many other libraries and utilities might benefit from it (i.e. Linear Algebra).
I am really open for feedback and am actively looking for experts' help here.
from mp-units.
BTW, before someone will raise it, please do not discuss here if it is sane for it to be a concept or not as the need for it does not come directly for algorithms. I will provide a dedicated policy paper on this and we will discuss this in Prague.
Please, just scope help to make this concept(s) as good and as good for the generic usage as only possible.
from mp-units.
One more important design point to mention here. The C++ concepts are able to verify syntactic requirements only. They cannot verify semantics by themselves. This is why we should include all possible operations in requires expression constraints. Things like numeric_limits
and other traits are more about semantic requirements and I am not sure if they should be included in concepts. If yes, then only as an addition to a full set of syntactic ones.
from mp-units.
Here are some thoughts on a Number concept for a physical quantity valuetype of type T
In quantity<u,T>
https://en.wikipedia.org/wiki/Magnitude_(mathematics)
Magnitude of the quantity
https://en.wikipedia.org/wiki/Scalar
Scalar<T>
https://en.wikipedia.org/wiki/Vector_(mathematics_and_physics)
not Vector<T>
https://en.wikipedia.org/wiki/Real_number
RealNumber<T>
https://en.wikipedia.org/wiki/Dimensionless_quantity
Dimensionless_Quantity<T>
A related issue is where one might want to use physical quantity as valuetype:
complex<Quantity> or Quantity<unit,complex>
quaternion<Quantity> or Quantity<unit,quaternion>
(Personally prefer complex<Quantity> , quaternion<\Quantity>
https://github.com/kwikius/quan-trunk/blob/master/quan/complex/complex.hpp
https://github.com/kwikius/quan-trunk/blob/master/quan/three_d/quat_def.hpp
https://github.com/kwikius/quan-trunk/blob/master/quan/three_d/quat.hpp
Have also found Quantity<unit, Angle> useful mainly for per_second per_second_squared type quantities
eg
radians per second
degrees per second
revolutions per minute
https://github.com/kwikius/quan-trunk/blob/master/quan_matters/examples/angles2.cpp#L32
from mp-units.
Some thoughts related to ops on Quantities with other types
Want generic as possible binary operations but avoiding ambiguous overloads
Take 2 types Q1, T2 where for example Q1 is a Quantity
Usual issue is multiplicative op { *, /}
Q1 op T2
I think there are specifically 3 cases generally in multiplication/division
-
T2 is in same universe . eg T2 is a Quantity. ( Same universe but maybe different dimension)
-
T2 is in lower universe e.g T2 is a Numeric
-
T2 is in higher universe eg T2 is a 3dvector, matrix etc.
Maybe there is an order that Universe<T1> <= Universe<T2> ?
N.B If there is no ordering between the universes then the operation is not possible
N.B that the result Type is irrelevant for overload resolution ( e.g if result Q/Q is dimensionlesss etc)
from mp-units.
It seems it is impossible to define one number concept. This is why I decided to go with P1813.
Maybe only something like this will be discussed in the SG6 numerics group:
template<typename T, typename U = T>
concept basic_arithmetic =
std::magma<std::ranges::plus, T, U> &&
std::magma<std::ranges::minus, T, U> &&
std::magma<std::ranges::times, T, U> &&
std::magma<std::ranges::divided_by, T, U>;
but time will tell...
from mp-units.
Related Issues (20)
- Remove c'tor from underlying types HOT 4
- Provide relese combo box in the documentation HOT 13
- Failed to follow conan + CMake instructions HOT 10
- Allocator protocol support? HOT 5
- Incorrect result, with surprising unit, when subtracting MPH and KPH HOT 4
- Vector quantities with units HOT 7
- mpunits with conan 2.0 HOT 15
- build(cmake): replace `TestHeaders.cmake` with `CMAKE_VERIFY_INTERFACE_HEADER_SETS` HOT 1
- `base_units<si_system>` HOT 2
- Basic units fmt example fails to compile on MSVC HOT 4
- problems casting (angle) type to itself HOT 7
- Modulo operations HOT 42
- Incorrect result: sqrt(x*x) != x for x of type newton, joule, and watt HOT 1
- gcc13 Internal Compiler Error HOT 3
- Compile error due to concepts HOT 3
- mp-units broken in vcpkg using clang HOT 3
- `mp_units::quantity` or `mp::quantity` HOT 9
- Consider adding expression templates support for `norm`, `dot`, and `cross` products on vector quantities HOT 4
- Measurement in IAU HOT 7
- Provide definition for the remaining quantities of ISQ
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.