mp-units icon indicating copy to clipboard operation
mp-units copied to clipboard

feat: negative constants

Open JohelEGP opened this issue 8 months ago • 18 comments

ISO 80000-1 §A.4 "Constants" references CODATA: https://physics.nist.gov/cuu/Constants/. It lists fundamental constants, including some negative ones. Browse to "All values (ascii)", search for -, and see some under the column "Value" being highlighted as negative. One such constant is helion g factor, which is rejected for being negative (https://godbolt.org/z/vao9PKv3s):

inline constexpr struct helion_g_factor :
  named_unit<basic_symbol_text{"𝘨ₕ", "g_h"}, mag<-ratio{4'255'250'615, 1'000'000'000}> * one> {} helion_g_factor;
<source>:7:46: error: use of invalid variable template 'mag<mp_units::ratio{-851050123, 200000000}>'
    7 |   named_unit<basic_symbol_text{"𝘨ₕ", "g_h"}, mag<-ratio{4'255'250'615, 1'000'000'000}> * one> {} helion_g_factor;
      |                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:7:46: note: constraints not satisfied
In file included from /opt/compiler-explorer/libs/mp-units/trunk/src/core/include/mp-units/bits/expression_template.h:25,
                 from /opt/compiler-explorer/libs/mp-units/trunk/src/core/include/mp-units/bits/dimension_concepts.h:25,
                 from /opt/compiler-explorer/libs/mp-units/trunk/src/core/include/mp-units/quantity.h:26,
                 from /opt/compiler-explorer/libs/mp-units/trunk/src/systems/si/include/mp-units/systems/si/constants.h:25,
                 from /opt/compiler-explorer/libs/mp-units/trunk/src/systems/si/include/mp-units/systems/si/si.h:25,
                 from <source>:1:
/opt/compiler-explorer/libs/mp-units/trunk/src/core/include/mp-units/bits/external/math_concepts.h: In substitution of 'template<mp_units::ratio R>  requires  gt_zero<(long int)((const mp_units::ratio)R).num> constexpr const auto [requires mp_units::Magnitude<<placeholder>, >] mp_units::mag<R> [with mp_units::ratio R = mp_units::ratio{-851050123, 200000000}]':
<source>:7:51:   required from here
/opt/compiler-explorer/libs/mp-units/trunk/src/core/include/mp-units/bits/external/math_concepts.h:30:9:   required for the satisfaction of 'gt_zero<((const mp_units::ratio)R).num>' [with R = _ZTAXtlN8mp_units5ratioELln851050123ELl200000000EEE]
/opt/compiler-explorer/libs/mp-units/trunk/src/core/include/mp-units/bits/external/math_concepts.h:30:22: note: the expression 'N > 0 [with N = (long int)_ZTAXtlN8mp_units5ratioELln851050123ELl200000000EEE.mp_units::ratio::num]' evaluated to 'false'
   30 | concept gt_zero = (N > 0);
      |                   ~~~^~~~
<source>:7:93: error: template argument 2 is invalid
    7 |   named_unit<basic_symbol_text{"𝘨ₕ", "g_h"}, mag<-ratio{4'255'250'615, 1'000'000'000}> * one> {} helion_g_factor;
      |                                                                                             ^
Compiler returned: 1

JohelEGP avatar Oct 24 '23 21:10 JohelEGP