Physical constants refactored

This commit is contained in:
Mateusz Pusz
2020-02-21 10:57:57 +01:00
parent 834d1fa09d
commit d51a9eac28
2 changed files with 8 additions and 55 deletions

View File

@ -1,46 +0,0 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include <units/quantity.h>
namespace units {
namespace detail {
template<Ratio R, Exponent... Es>
struct constant_helper {
using dim = downcast_dimension<typename detail::make_dimension<Es...>>;
using ratio = ratio_multiply<R, typename dimension_unit<dim>::ratio>;
using unit = downcast_unit<dim, R>;
static constexpr quantity<dim, unit> value{1};
};
}
template<Ratio R, Exponent E, Exponent... Rest>
inline constexpr auto constant = detail::constant_helper<R, E, Rest...>::value;
} // namespace units

View File

@ -22,7 +22,6 @@
#pragma once
#include <units/constant.h>
#include <units/physical/si/electric_charge.h>
#include <units/physical/si/frequency.h>
#include <units/physical/si/energy.h>
@ -33,13 +32,13 @@
namespace units::si {
inline constexpr auto planck_constant = constant<ratio<662607015, 1, -42>, exp<dim_energy, 1>, exp<dim_time, 1>>;
inline constexpr auto elementary_charge = constant<ratio<1602176634, 1, -51>, exp<dim_electric_charge, 1>>;
inline constexpr auto boltzmann_constant =
constant<ratio<1380649, 1, -29>, exp<dim_energy, 1>, exp<dim_thermodynamic_temperature, -1>>;
inline constexpr auto avogadro_constant = constant<ratio<602214076, 1, 15>, exp<dim_substance, -1>>;
inline constexpr auto speed_of_light = constant<ratio<299792458, 1, 15>, exp<dim_velocity, 1>>;
inline constexpr auto hyperfine_structure_transition_frequency = constant<ratio<9192631770>, exp<dim_frequency, 1>>;
// inline constexpr auto luminous_efficacy = constant<ratio<683>, exp<luminous_flux, 1>, exp<power, -1>>;
inline constexpr auto planck_constant = 6.62607015e-34q_J * 1q_s;
inline constexpr auto reduced_planck_constant = 6.582119569e-10q_GeV * 1q_s;
inline constexpr auto elementary_charge = 1.602176634e-19q_C;
inline constexpr auto boltzmann_constant = 1.380649e-23q_J / 1q_K;
inline constexpr auto avogadro_constant = 6.02214076e23 / 1q_mol;
inline constexpr auto speed_of_light = 299792458q_mps;
inline constexpr auto hyperfine_structure_transition_frequency = 9192631770q_Hz;
// inline constexpr auto luminous_efficacy = 683q_lm / 1q_W;
} // namespace units::si