diff --git a/docs/users_guide/framework_basics/interface_introduction.md b/docs/users_guide/framework_basics/interface_introduction.md index 017859e6..6776cd29 100644 --- a/docs/users_guide/framework_basics/interface_introduction.md +++ b/docs/users_guide/framework_basics/interface_introduction.md @@ -152,20 +152,22 @@ identities used in the library: | `QuantitySpec` | `dimensionless` | | `Unit` | `one` | -In the equations, a user can refer to an identity object either explicitly: +In the equations, a user can explicitly refer to an identity object: ```cpp constexpr auto my_unit = one / second; ``` -or implicitly: +!!! note -```cpp -constexpr auto my_unit = 1 / second; -``` + Another way to achieve the same result is to call an `inverse()` function: -Both cases with result in the same expression template being generated and put into the wrapper -class template. + ```cpp + constexpr auto my_unit = inverse(second); + ``` + + Both cases will result in the same expression template being generated and put into the wrapper + class template. ### Supported operations and their results diff --git a/docs/users_guide/framework_basics/systems_of_units.md b/docs/users_guide/framework_basics/systems_of_units.md index 50965fe1..9607bd7d 100644 --- a/docs/users_guide/framework_basics/systems_of_units.md +++ b/docs/users_guide/framework_basics/systems_of_units.md @@ -107,8 +107,8 @@ However, it also explicitly states: The library allows constraining such units in the following way: ```cpp -inline constexpr struct hertz : named_unit<"Hz", 1 / second, kind_of> {} hertz; -inline constexpr struct becquerel : named_unit<"Bq", 1 / second, kind_of> {} becquerel; +inline constexpr struct hertz : named_unit<"Hz", one / second, kind_of> {} hertz; +inline constexpr struct becquerel : named_unit<"Bq", one / second, kind_of> {} becquerel; ``` With the above, `hertz` can only be used for frequencies while becquerel should only be used for diff --git a/example/si_constants.cpp b/example/si_constants.cpp index d1a85a4a..255f8054 100644 --- a/example/si_constants.cpp +++ b/example/si_constants.cpp @@ -35,6 +35,7 @@ inline constexpr bool mp_units::is_vector = true; int main() { + using namespace mp_units; using namespace mp_units::si; using namespace mp_units::si::unit_symbols; @@ -52,7 +53,7 @@ int main() std::cout << MP_UNITS_STD_FMT::format("- Boltzmann constant: {} = {:%.6eQ %q}\n", 1. * si2019::boltzmann_constant, (1. * si2019::boltzmann_constant).in(J / K)); std::cout << MP_UNITS_STD_FMT::format("- Avogadro constant: {} = {:%.8eQ %q}\n", - 1. * si2019::avogadro_constant, (1. * si2019::avogadro_constant).in(1 / mol)); + 1. * si2019::avogadro_constant, (1. * si2019::avogadro_constant).in(one / mol)); std::cout << MP_UNITS_STD_FMT::format("- luminous efficacy: {} = {}\n", 1. * si2019::luminous_efficacy, (1. * si2019::luminous_efficacy).in(lm / W)); } diff --git a/example/spectroscopy_units.cpp b/example/spectroscopy_units.cpp index 6cf9e953..363605a1 100644 --- a/example/spectroscopy_units.cpp +++ b/example/spectroscopy_units.cpp @@ -61,7 +61,7 @@ template T1, QuantityOf T2, QuantityOf< void print_line_si(const std::tuple& t) { MP_UNITS_STD_FMT::println("| {:<15} | {:<15} | {:<15} | {:<15} | {:<15} |", std::get<0>(t).in(eV), - std::get<1>(t).in(1 / cm), std::get<2>(t).in(THz), std::get<3>(t).in(K), + std::get<1>(t).in(one / cm), std::get<2>(t).in(THz), std::get<3>(t).in(K), std::get<4>(t).in(um)); } @@ -71,7 +71,7 @@ int main() const auto t1 = std::make_tuple(q1, isq::wavenumber(q1 / (h * c)), isq::frequency(q1 / h), isq::thermodynamic_temperature(q1 / kb), isq::wavelength(h * c / q1)); - const auto q2 = 1. * isq::wavenumber[1 / cm]; + const auto q2 = 1. * isq::wavenumber[one / cm]; const auto t2 = std::make_tuple(isq::energy(q2 * h * c), q2, isq::frequency(q2 * c), isq::thermodynamic_temperature(q2 * h * c / kb), isq::wavelength(1 / q2)); diff --git a/src/core/include/mp-units/dimension.h b/src/core/include/mp-units/dimension.h index 4c9c0796..a0a4dc8b 100644 --- a/src/core/include/mp-units/dimension.h +++ b/src/core/include/mp-units/dimension.h @@ -88,7 +88,7 @@ using type_list_of_base_dimension_less = expr_less; * For example: * * @code{.cpp} - * using frequency = decltype(1 / dim_time); + * using frequency = decltype(inverse(dim_time)); * using speed = decltype(dim_length / dim_time); * using acceleration = decltype(dim_speed / dim_time); * using force = decltype(dim_mass * dim_acceleration); @@ -150,22 +150,14 @@ template Rhs{}); } -template -[[nodiscard]] consteval Dimension auto operator/(int value, D) -{ - gsl_Expects(value == 1); - return detail::expr_invert(D{}); -} - -template -[[nodiscard]] consteval Dimension auto operator/(D, int) = delete; - template [[nodiscard]] consteval bool operator==(Lhs, Rhs) { return is_same_v; } +[[nodiscard]] consteval Dimension auto inverse(Dimension auto d) { return dimension_one / d; } + /** * @brief Computes the value of a dimension raised to the `Num/Den` power * diff --git a/src/core/include/mp-units/quantity_spec.h b/src/core/include/mp-units/quantity_spec.h index b94e476c..d2e29501 100644 --- a/src/core/include/mp-units/quantity_spec.h +++ b/src/core/include/mp-units/quantity_spec.h @@ -395,7 +395,7 @@ struct quantity_spec : quantity_spec { * For example: * * @code{.cpp} - * auto frequency = 1 / period_duration; + * auto frequency = inverse(period_duration); * auto area = pow<2>(length); * auto speed = distance / duration; * auto velocity = position_vector / duration; @@ -496,7 +496,7 @@ template [[nodiscard]] consteval QuantitySpec auto operator*(QuantitySpec auto lhs, QuantitySpec auto rhs) { - return clone_kind_of( + return detail::clone_kind_of( detail::expr_multiply( remove_kind(lhs), remove_kind(rhs))); } @@ -504,19 +504,11 @@ template template [[nodiscard]] consteval QuantitySpec auto operator/(Lhs lhs, Rhs rhs) { - return clone_kind_of( + return detail::clone_kind_of( detail::expr_divide( remove_kind(lhs), remove_kind(rhs))); } -[[nodiscard]] consteval QuantitySpec auto operator/(int value, QuantitySpec auto q) -{ - gsl_Expects(value == 1); - return clone_kind_of(detail::expr_invert(q)); -} - -[[nodiscard]] consteval QuantitySpec auto operator/(QuantitySpec auto, int) = delete; - template [[nodiscard]] consteval bool operator==(Lhs, Rhs) { @@ -535,6 +527,11 @@ template return is_same_v>; } +[[nodiscard]] consteval QuantitySpec auto inverse(QuantitySpec auto q) +{ + return dimensionless / q; +} + /** * @brief Computes the value of a quantity specification raised to the `Num/Den` power diff --git a/src/core/include/mp-units/reference.h b/src/core/include/mp-units/reference.h index 204fee55..2c1ce7d2 100644 --- a/src/core/include/mp-units/reference.h +++ b/src/core/include/mp-units/reference.h @@ -102,6 +102,8 @@ struct reference { return {}; } + [[nodiscard]] friend consteval reference inverse(reference) { return {}; } + /** * @brief Computes the value of a reference raised to the `Num/Den` power * @@ -159,11 +161,27 @@ template Rep> class quantity; template + requires RepresentationOf, get_quantity_spec(R{}).character> [[nodiscard]] constexpr quantity> operator*(Rep&& lhs, R) { return make_quantity(std::forward(lhs)); } +template + requires RepresentationOf, get_quantity_spec(R{}).character> +[[nodiscard]] constexpr quantity> operator/(Rep&& lhs, R) +{ + return make_quantity(std::forward(lhs)); +} + +template + requires RepresentationOf, get_quantity_spec(R{}).character> +constexpr auto operator*(R, Rep&&) = delete; + +template + requires RepresentationOf, get_quantity_spec(R{}).character> +constexpr auto operator/(R, Rep&&) = delete; + template requires Quantity> [[nodiscard]] constexpr Quantity auto operator*(Q&& q, R) @@ -178,6 +196,14 @@ template return make_quantity::reference / R{}>(std::forward(q).numerical_value_); } +template + requires Quantity> +constexpr auto operator*(R, Q&& q) = delete; + +template + requires Quantity> +constexpr auto operator/(R, Q&& q) = delete; + [[nodiscard]] consteval AssociatedUnit auto common_reference(AssociatedUnit auto u1, AssociatedUnit auto u2, AssociatedUnit auto... rest) requires requires { diff --git a/src/core/include/mp-units/unit.h b/src/core/include/mp-units/unit.h index 5810c4a7..760bcfc4 100644 --- a/src/core/include/mp-units/unit.h +++ b/src/core/include/mp-units/unit.h @@ -77,7 +77,7 @@ inline constexpr bool is_specialization_of_scaled_unit> = true * @code{.cpp} * inline constexpr struct second : named_unit<"s", time> {} second; * inline constexpr struct metre : named_unit<"m", length> {} metre; - * inline constexpr struct hertz : named_unit<"Hz", 1 / second> {} hertz; + * inline constexpr struct hertz : named_unit<"Hz", inverse(second)> {} hertz; * inline constexpr struct newton : named_unit<"N", kilogram * metre / square(second)> {} newton; * inline constexpr struct degree_Celsius : named_unit {} degree_Celsius; * inline constexpr struct minute : named_unit<"min", mag<60> * second> {} minute; @@ -212,8 +212,8 @@ struct is_one : std::false_type {}; * For example: * * @code{.cpp} - * static_assert(is_of_type<1 / second, derived_unit>>); - * static_assert(is_of_type<1 / (1 / second), second>); + * static_assert(is_of_type>>); + * static_assert(is_of_type); * static_assert(is_of_type); * static_assert(is_of_type>>); * static_assert(is_of_type>); @@ -436,7 +436,7 @@ template template [[nodiscard]] MP_UNITS_CONSTEVAL Unit auto operator/(M mag, const U u) { - return mag * (1 / u); + return mag * inverse(u); } /** @@ -457,13 +457,8 @@ template return detail::expr_divide(lhs, rhs); } -[[nodiscard]] MP_UNITS_CONSTEVAL Unit auto operator/(int value, Unit auto u) -{ - gsl_Expects(value == 1); - return detail::expr_invert(u); -} +[[nodiscard]] MP_UNITS_CONSTEVAL Unit auto inverse(Unit auto u) { return one / u; } -[[nodiscard]] consteval Unit auto operator/(Unit auto, int) = delete; namespace detail { diff --git a/src/systems/cgs/include/mp-units/systems/cgs/cgs.h b/src/systems/cgs/include/mp-units/systems/cgs/cgs.h index 69f4dcf8..9e91b6da 100644 --- a/src/systems/cgs/include/mp-units/systems/cgs/cgs.h +++ b/src/systems/cgs/include/mp-units/systems/cgs/cgs.h @@ -37,7 +37,7 @@ inline constexpr struct erg : named_unit<"erg", dyne * centimetre> {} erg; inline constexpr struct barye : named_unit<"Ba", gram / (centimetre * square(second))> {} barye; inline constexpr struct poise : named_unit<"P", gram / (centimetre * second)> {} poise; inline constexpr struct stokes : named_unit<"St", square(centimetre) / second> {} stokes; -inline constexpr struct kayser : named_unit<"K", 1 / centimetre> {} kayser; +inline constexpr struct kayser : named_unit<"K", one / centimetre> {} kayser; // clang-format on namespace unit_symbols { diff --git a/src/systems/iec80000/include/mp-units/systems/iec80000/quantities.h b/src/systems/iec80000/include/mp-units/systems/iec80000/quantities.h index c436943a..d28064dd 100644 --- a/src/systems/iec80000/include/mp-units/systems/iec80000/quantities.h +++ b/src/systems/iec80000/include/mp-units/systems/iec80000/quantities.h @@ -42,21 +42,21 @@ inline constexpr auto traffic_load = traffic_carried_intensity; QUANTITY_SPEC(mean_queue_length, dimensionless); QUANTITY_SPEC(loss_probability, dimensionless); QUANTITY_SPEC(waiting_probability, dimensionless); -QUANTITY_SPEC(call_intensity, 1 / isq::duration); +QUANTITY_SPEC(call_intensity, inverse(isq::duration)); inline constexpr auto calling_rate = call_intensity; QUANTITY_SPEC(completed_call_intensity, call_intensity); QUANTITY_SPEC(storage_capacity, dimensionless, is_kind); inline constexpr auto storage_size = storage_capacity; QUANTITY_SPEC(equivalent_binary_storage_capacity, storage_capacity); QUANTITY_SPEC(transfer_rate, storage_capacity / isq::duration); -QUANTITY_SPEC(period_of_data_elements, isq::period, 1 / transfer_rate); +QUANTITY_SPEC(period_of_data_elements, isq::period, inverse(transfer_rate)); QUANTITY_SPEC(binary_digit_rate, transfer_rate); inline constexpr auto bit_rate = binary_digit_rate; -QUANTITY_SPEC(period_of_binary_digits, isq::period, 1 / binary_digit_rate); +QUANTITY_SPEC(period_of_binary_digits, isq::period, inverse(binary_digit_rate)); inline constexpr auto bit_period = period_of_binary_digits; QUANTITY_SPEC(equivalent_binary_digit_rate, binary_digit_rate); inline constexpr auto equivalent_bit_rate = bit_rate; -QUANTITY_SPEC(modulation_rate, 1 / isq::duration); +QUANTITY_SPEC(modulation_rate, inverse(isq::duration)); inline constexpr auto line_digit_rate = modulation_rate; QUANTITY_SPEC(quantizing_distortion_power, isq::power); QUANTITY_SPEC(carrier_power, isq::power); diff --git a/src/systems/iec80000/include/mp-units/systems/iec80000/units.h b/src/systems/iec80000/include/mp-units/systems/iec80000/units.h index 2bbe05cf..2f80e167 100644 --- a/src/systems/iec80000/include/mp-units/systems/iec80000/units.h +++ b/src/systems/iec80000/include/mp-units/systems/iec80000/units.h @@ -33,7 +33,7 @@ inline constexpr struct erlang : named_unit<"E", kind_of> {} inline constexpr struct bit : named_unit<"bit", one, kind_of> {} bit; inline constexpr struct octet : named_unit<"o", mag<8> * bit> {} octet; inline constexpr struct byte : named_unit<"B", mag<8> * bit> {} byte; -inline constexpr struct baud : named_unit<"Bd", 1 / si::second, kind_of> {} baud; +inline constexpr struct baud : named_unit<"Bd", one / si::second, kind_of> {} baud; // clang-format on } // namespace mp_units::iec80000 diff --git a/src/systems/isq/include/mp-units/systems/isq/atomic_and_nuclear_physics.h b/src/systems/isq/include/mp-units/systems/isq/atomic_and_nuclear_physics.h index 7493e0f3..24075900 100644 --- a/src/systems/isq/include/mp-units/systems/isq/atomic_and_nuclear_physics.h +++ b/src/systems/isq/include/mp-units/systems/isq/atomic_and_nuclear_physics.h @@ -30,7 +30,7 @@ namespace mp_units::isq { // TODO Add all the remaining ISQ definitions -QUANTITY_SPEC(activity, 1 / duration); +QUANTITY_SPEC(activity, inverse(duration)); QUANTITY_SPEC(absorbed_dose, energy / mass); QUANTITY_SPEC(ionizing_radiation_quality_factor, dimensionless); QUANTITY_SPEC(dose_equivalent, absorbed_dose* ionizing_radiation_quality_factor); diff --git a/src/systems/isq/include/mp-units/systems/isq/electromagnetism.h b/src/systems/isq/include/mp-units/systems/isq/electromagnetism.h index 03294a36..2ba2aa9f 100644 --- a/src/systems/isq/include/mp-units/systems/isq/electromagnetism.h +++ b/src/systems/isq/include/mp-units/systems/isq/electromagnetism.h @@ -63,7 +63,7 @@ QUANTITY_SPEC(phase_speed_of_electromagnetic_waves, angular_frequency / angular_ QUANTITY_SPEC(speed_of_light_in_vacuum, speed); inline constexpr auto light_speed_in_vacuum = speed_of_light_in_vacuum; inline constexpr auto luminal_speed = speed_of_light_in_vacuum; -QUANTITY_SPEC(electric_constant, 1 / (magnetic_constant * pow<2>(speed_of_light_in_vacuum))); +QUANTITY_SPEC(electric_constant, inverse(magnetic_constant* pow<2>(speed_of_light_in_vacuum))); inline constexpr auto permittivity_of_vacuum = electric_constant; QUANTITY_SPEC(permittivity, electric_flux_density / electric_field_strength, quantity_character::scalar); QUANTITY_SPEC(relative_permittivity, dimensionless, permittivity / electric_constant); @@ -101,18 +101,18 @@ QUANTITY_SPEC(magnetomotive_force, electric_current, magnetic_field_strength* po QUANTITY_SPEC(current_linkage, electric_current); QUANTITY_SPEC(number_of_turns_in_a_winding, dimensionless); QUANTITY_SPEC(reluctance, magnetic_tension / magnetic_flux); -QUANTITY_SPEC(permeance, 1 / reluctance); +QUANTITY_SPEC(permeance, inverse(reluctance)); QUANTITY_SPEC(inductance, linked_flux / electric_current); inline constexpr auto self_inductance = inductance; QUANTITY_SPEC(mutual_inductance, linked_flux / electric_current); QUANTITY_SPEC(coupling_factor, dimensionless, mutual_inductance / pow<1, 2>(pow<2>(self_inductance))); QUANTITY_SPEC(leakage_factor, dimensionless, pow<2>(coupling_factor)); QUANTITY_SPEC(conductivity, electric_current_density / electric_field_strength, quantity_character::scalar); -QUANTITY_SPEC(resistivity, 1 / conductivity); +QUANTITY_SPEC(resistivity, inverse(conductivity)); QUANTITY_SPEC(electromagnetism_power, power, voltage* electric_current); inline constexpr auto instantaneous_power = electromagnetism_power; QUANTITY_SPEC(resistance, voltage / electric_current); -QUANTITY_SPEC(conductance, 1 / resistance); +QUANTITY_SPEC(conductance, inverse(resistance)); QUANTITY_SPEC(phase_difference, phase_angle); QUANTITY_SPEC(electric_current_phasor, electric_current); QUANTITY_SPEC(voltage_phasor, voltage); @@ -121,15 +121,15 @@ inline constexpr auto complex_impedance = impedance; QUANTITY_SPEC(resistance_to_alternating_current, impedance); QUANTITY_SPEC(reactance, impedance); QUANTITY_SPEC(modulus_of_impedance, impedance); -QUANTITY_SPEC(admittance, 1 / impedance); +QUANTITY_SPEC(admittance, inverse(impedance)); inline constexpr auto complex_admittance = admittance; QUANTITY_SPEC(conductance_for_alternating_current, admittance); QUANTITY_SPEC(susceptance, admittance); QUANTITY_SPEC(modulus_of_admittance, admittance); QUANTITY_SPEC(quality_factor, dimensionless, reactance / resistance); -QUANTITY_SPEC(loss_factor, dimensionless, 1 / quality_factor); +QUANTITY_SPEC(loss_factor, dimensionless, inverse(quality_factor)); QUANTITY_SPEC(loss_angle, angular_measure); -QUANTITY_SPEC(active_power, 1 / period * (instantaneous_power * time)); +QUANTITY_SPEC(active_power, inverse(period) * (instantaneous_power * time)); QUANTITY_SPEC(apparent_power, voltage* electric_current); QUANTITY_SPEC(power_factor, dimensionless, active_power / apparent_power); QUANTITY_SPEC(complex_power, voltage_phasor* electric_current_phasor); diff --git a/src/systems/isq/include/mp-units/systems/isq/mechanics.h b/src/systems/isq/include/mp-units/systems/isq/mechanics.h index 4d0a57b8..fd079550 100644 --- a/src/systems/isq/include/mp-units/systems/isq/mechanics.h +++ b/src/systems/isq/include/mp-units/systems/isq/mechanics.h @@ -30,7 +30,7 @@ namespace mp_units::isq { QUANTITY_SPEC(mass_density, mass / volume); inline constexpr auto density = mass_density; -QUANTITY_SPEC(specific_volume, 1 / mass_density); +QUANTITY_SPEC(specific_volume, inverse(mass_density)); QUANTITY_SPEC(relative_mass_density, mass_density / mass_density); inline constexpr auto relative_density = relative_mass_density; QUANTITY_SPEC(surface_mass_density, mass / area); @@ -70,7 +70,7 @@ QUANTITY_SPEC(modulus_of_rigidity, shear_stress / shear_strain); inline constexpr auto shear_modulus = modulus_of_rigidity; QUANTITY_SPEC(modulus_of_compression, pressure / relative_volume_strain); inline constexpr auto bulk_modulus = modulus_of_compression; -QUANTITY_SPEC(compressibility, 1 / volume * (volume / pressure)); +QUANTITY_SPEC(compressibility, inverse(volume) * (volume / pressure)); QUANTITY_SPEC(second_axial_moment_of_area, pow<2>(radial_distance) * area); QUANTITY_SPEC(second_polar_moment_of_area, pow<2>(radial_distance) * area); QUANTITY_SPEC(section_modulus, second_axial_moment_of_area / radial_distance); diff --git a/src/systems/isq/include/mp-units/systems/isq/space_and_time.h b/src/systems/isq/include/mp-units/systems/isq/space_and_time.h index 0c3ef558..e93f152c 100644 --- a/src/systems/isq/include/mp-units/systems/isq/space_and_time.h +++ b/src/systems/isq/include/mp-units/systems/isq/space_and_time.h @@ -42,7 +42,7 @@ QUANTITY_SPEC(radial_distance, distance); QUANTITY_SPEC(position_vector, length, quantity_character::vector); QUANTITY_SPEC(displacement, length, quantity_character::vector); QUANTITY_SPEC(radius_of_curvature, radius); -QUANTITY_SPEC(curvature, 1 / radius_of_curvature); +QUANTITY_SPEC(curvature, inverse(radius_of_curvature)); QUANTITY_SPEC(area, pow<2>(length)); QUANTITY_SPEC(volume, pow<3>(length)); QUANTITY_SPEC(angular_measure, dimensionless, arc_length / radius, is_kind); @@ -61,25 +61,25 @@ QUANTITY_SPEC(period_duration, duration); inline constexpr auto period = period_duration; QUANTITY_SPEC(time_constant, duration); QUANTITY_SPEC(rotation, dimensionless); -QUANTITY_SPEC(frequency, 1 / period_duration); +QUANTITY_SPEC(frequency, inverse(period_duration)); QUANTITY_SPEC(rotational_frequency, rotation / duration); QUANTITY_SPEC(angular_frequency, phase_angle / duration); QUANTITY_SPEC(wavelength, length); -QUANTITY_SPEC(repetency, 1 / wavelength); +QUANTITY_SPEC(repetency, inverse(wavelength)); inline constexpr auto wavenumber = repetency; QUANTITY_SPEC(wave_vector, repetency, quantity_character::vector); -QUANTITY_SPEC(angular_repetency, 1 / wavelength); +QUANTITY_SPEC(angular_repetency, inverse(wavelength)); inline constexpr auto angular_wavenumber = angular_repetency; QUANTITY_SPEC(phase_velocity, angular_frequency / angular_repetency); inline constexpr auto phase_speed = phase_velocity; QUANTITY_SPEC(group_velocity, angular_frequency / angular_repetency); inline constexpr auto group_speed = group_velocity; -QUANTITY_SPEC(damping_coefficient, 1 / time_constant); +QUANTITY_SPEC(damping_coefficient, inverse(time_constant)); QUANTITY_SPEC(logarithmic_decrement, dimensionless, damping_coefficient* period_duration); -QUANTITY_SPEC(attenuation, 1 / distance); +QUANTITY_SPEC(attenuation, inverse(distance)); inline constexpr auto extinction = attenuation; QUANTITY_SPEC(phase_coefficient, phase_angle / path_length); -QUANTITY_SPEC(propagation_coefficient, 1 / length); // γ = α + iβ where α denotes attenuation +QUANTITY_SPEC(propagation_coefficient, inverse(length)); // γ = α + iβ where α denotes attenuation // and β the phase coefficient of a plane wave } // namespace mp_units::isq diff --git a/src/systems/isq/include/mp-units/systems/isq/thermodynamics.h b/src/systems/isq/include/mp-units/systems/isq/thermodynamics.h index 1c59c05e..3a543a6d 100644 --- a/src/systems/isq/include/mp-units/systems/isq/thermodynamics.h +++ b/src/systems/isq/include/mp-units/systems/isq/thermodynamics.h @@ -30,12 +30,12 @@ namespace mp_units::isq { QUANTITY_SPEC(Celsius_temperature, thermodynamic_temperature); // TODO should we account for T0 here? -QUANTITY_SPEC(linear_expansion_coefficient, 1 / length * (length / thermodynamic_temperature)); -QUANTITY_SPEC(cubic_expansion_coefficient, 1 / volume * (volume / thermodynamic_temperature)); -QUANTITY_SPEC(relative_pressure_coefficient, 1 / pressure * (pressure / thermodynamic_temperature)); +QUANTITY_SPEC(linear_expansion_coefficient, inverse(length) * (length / thermodynamic_temperature)); +QUANTITY_SPEC(cubic_expansion_coefficient, inverse(volume) * (volume / thermodynamic_temperature)); +QUANTITY_SPEC(relative_pressure_coefficient, inverse(pressure) * (pressure / thermodynamic_temperature)); QUANTITY_SPEC(pressure_coefficient, pressure / thermodynamic_temperature); -QUANTITY_SPEC(isothermal_compressibility, 1 / volume * (volume / pressure)); // TODO how to handle "negative" part -QUANTITY_SPEC(isentropic_compressibility, 1 / volume * (volume / pressure)); // TODO how to handle "negative" part +QUANTITY_SPEC(isothermal_compressibility, inverse(volume) * (volume / pressure)); // TODO how to handle "negative" part +QUANTITY_SPEC(isentropic_compressibility, inverse(volume) * (volume / pressure)); // TODO how to handle "negative" part // energy definition moved to mechanics QUANTITY_SPEC(heat, energy); inline constexpr auto amount_of_heat = heat; @@ -45,10 +45,10 @@ QUANTITY_SPEC(density_of_heat_flow_rate, heat_flow_rate / area); QUANTITY_SPEC(thermal_conductivity, density_of_heat_flow_rate*(length / thermodynamic_temperature)); QUANTITY_SPEC(coefficient_of_heat_transfer, density_of_heat_flow_rate / thermodynamic_temperature); QUANTITY_SPEC(surface_coefficient_of_heat_transfer, density_of_heat_flow_rate / thermodynamic_temperature); -QUANTITY_SPEC(thermal_insulance, 1 / coefficient_of_heat_transfer); +QUANTITY_SPEC(thermal_insulance, inverse(coefficient_of_heat_transfer)); inline constexpr auto coefficient_of_thermal_insulance = thermal_insulance; QUANTITY_SPEC(thermal_resistance, thermodynamic_temperature / heat_flow_rate); -QUANTITY_SPEC(thermal_conductance, 1 / thermal_resistance); +QUANTITY_SPEC(thermal_conductance, inverse(thermal_resistance)); QUANTITY_SPEC(heat_capacity, heat / thermodynamic_temperature); QUANTITY_SPEC(specific_heat_capacity, heat_capacity / mass); QUANTITY_SPEC(specific_heat_capacity_at_constant_pressure, specific_heat_capacity); diff --git a/src/systems/natural/include/mp-units/systems/natural/natural.h b/src/systems/natural/include/mp-units/systems/natural/natural.h index 3d614336..b0738610 100644 --- a/src/systems/natural/include/mp-units/systems/natural/natural.h +++ b/src/systems/natural/include/mp-units/systems/natural/natural.h @@ -36,8 +36,8 @@ inline constexpr struct electronvolt : named_unit<"eV"> {} electronvolt; inline constexpr struct gigaelectronvolt : decltype(si::giga) {} gigaelectronvolt; // system references -inline constexpr struct time : system_reference {} time; -inline constexpr struct length : system_reference {} length; +inline constexpr struct time : system_reference {} time; +inline constexpr struct length : system_reference {} length; inline constexpr struct mass : system_reference {} mass; inline constexpr struct velocity : system_reference {} velocity; inline constexpr struct speed : system_reference {} speed; diff --git a/src/systems/si/include/mp-units/systems/si/units.h b/src/systems/si/include/mp-units/systems/si/units.h index 543b0cf7..c9f517f0 100644 --- a/src/systems/si/include/mp-units/systems/si/units.h +++ b/src/systems/si/include/mp-units/systems/si/units.h @@ -46,7 +46,7 @@ inline constexpr struct candela : named_unit<"cd", kind_of> {} radian; inline constexpr struct steradian : named_unit<"sr", square(metre) / square(metre), kind_of> {} steradian; -inline constexpr struct hertz : named_unit<"Hz", 1 / second, kind_of> {} hertz; +inline constexpr struct hertz : named_unit<"Hz", one / second, kind_of> {} hertz; inline constexpr struct newton : named_unit<"N", kilogram * metre / square(second)> {} newton; #ifdef pascal #pragma push_macro("pascal") @@ -64,14 +64,14 @@ inline constexpr struct coulomb : named_unit<"C", ampere * second> {} coulomb; inline constexpr struct volt : named_unit<"V", watt / ampere> {} volt; inline constexpr struct farad : named_unit<"F", coulomb / volt> {} farad; inline constexpr struct ohm : named_unit {} ohm; -inline constexpr struct siemens : named_unit<"S", 1 / ohm> {} siemens; +inline constexpr struct siemens : named_unit<"S", one / ohm> {} siemens; inline constexpr struct weber : named_unit<"Wb", volt * second> {} weber; inline constexpr struct tesla : named_unit<"T", weber / square(metre)> {} tesla; inline constexpr struct henry : named_unit<"H", weber / ampere> {} henry; inline constexpr struct degree_Celsius : named_unit {} degree_Celsius; inline constexpr struct lumen : named_unit<"lm", candela * steradian> {} lumen; inline constexpr struct lux : named_unit<"lx", lumen / square(metre)> {} lux; -inline constexpr struct becquerel : named_unit<"Bq", 1 / second, kind_of> {} becquerel; +inline constexpr struct becquerel : named_unit<"Bq", one / second, kind_of> {} becquerel; inline constexpr struct gray : named_unit<"Gy", joule / kilogram, kind_of> {} gray; inline constexpr struct sievert : named_unit<"Sv", joule / kilogram, kind_of> {} sievert; inline constexpr struct katal : named_unit<"kat", mole / second> {} katal; diff --git a/test/unit_test/runtime/fmt_test.cpp b/test/unit_test/runtime/fmt_test.cpp index 66031140..bda7b936 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/unit_test/runtime/fmt_test.cpp @@ -167,7 +167,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") SECTION("compressibility") { - const auto q = 123 * isq::compressibility[1 / Pa]; + const auto q = 123 * isq::compressibility[one / Pa]; os << q; SECTION("iostream") { CHECK(os.str() == "123 1/Pa"); } diff --git a/test/unit_test/static/cgs_test.cpp b/test/unit_test/static/cgs_test.cpp index 819d2de6..c58c5885 100644 --- a/test/unit_test/static/cgs_test.cpp +++ b/test/unit_test/static/cgs_test.cpp @@ -48,16 +48,16 @@ static_assert(isq::power(10'000'000 * erg / s) == isq::power(1 * si::watt)); static_assert(isq::pressure(10 * Ba) == isq::pressure(1 * si::pascal)); static_assert(isq::dynamic_viscosity(10 * P) == isq::dynamic_viscosity(1 * si::pascal * si::second)); static_assert(isq::kinematic_viscosity(10'000 * St) == isq::kinematic_viscosity(1 * square(si::metre) / si::second)); -static_assert(isq::wavenumber(1 * K) == isq::wavenumber(100 * (1 / si::metre))); +static_assert(isq::wavenumber(1 * K) == isq::wavenumber(100 / si::metre)); static_assert(10'000'000 * erg + 1 * si::joule == 2 * si::joule); static_assert(1 * si::joule + 10'000'000 * erg == 2 * si::joule); static_assert(is_of_type<10'000'000 * erg + 1 * si::joule, quantity>); static_assert(is_of_type<1 * si::joule + 10'000'000 * erg, quantity>); -static_assert(1 * K + 100 * (1 / si::metre) == 2 * K); -static_assert(100 * (1 / si::metre) + 1 * K == 2 * K); -static_assert(is_of_type<1 * K + 100 * (1 / si::metre), quantity<1 / si::metre, int>>); -static_assert(is_of_type<100 * (1 / si::metre) + 1 * K, quantity<1 / si::metre, int>>); +static_assert(1 * K + 100 / si::metre == 2 * K); +static_assert(100 / si::metre + 1 * K == 2 * K); +static_assert(is_of_type<1 * K + 100 / si::metre, quantity>); +static_assert(is_of_type<100 / si::metre + 1 * K, quantity>); } // namespace diff --git a/test/unit_test/static/concepts_test.cpp b/test/unit_test/static/concepts_test.cpp index 21c6cbcc..b63228b0 100644 --- a/test/unit_test/static/concepts_test.cpp +++ b/test/unit_test/static/concepts_test.cpp @@ -48,7 +48,7 @@ struct dim_speed : decltype(isq::dim_length / isq::dim_time) {}; // BaseDimension static_assert(detail::BaseDimension); static_assert(!detail::BaseDimension>); -static_assert(!detail::BaseDimension>); +static_assert(!detail::BaseDimension>); static_assert(!detail::BaseDimension(isq::dim_length))>>); static_assert(!detail::BaseDimension>>); static_assert(!detail::BaseDimension); @@ -58,7 +58,7 @@ static_assert(!detail::BaseDimension); // DerivedDimension static_assert(detail::DerivedDimension>); -static_assert(detail::DerivedDimension>); +static_assert(detail::DerivedDimension>); static_assert(detail::DerivedDimension(isq::dim_length))>>); static_assert(detail::DerivedDimension>>); static_assert(detail::DerivedDimension); @@ -70,7 +70,7 @@ static_assert(!detail::DerivedDimension); // Dimension static_assert(Dimension); static_assert(Dimension>); -static_assert(Dimension>); +static_assert(Dimension>); static_assert(Dimension(isq::dim_length))>>); static_assert(Dimension>>); static_assert(Dimension); @@ -137,7 +137,7 @@ static_assert(Unit); static_assert(Unit)>>); static_assert(Unit); static_assert(Unit>); -static_assert(Unit>); +static_assert(Unit>); static_assert(Unit * si::second)>>); static_assert(Unit>); static_assert(Unit(si::metre))>>); @@ -161,7 +161,7 @@ static_assert(detail::NamedUnit); static_assert(!detail::NamedUnit); static_assert(!detail::NamedUnit)>>); static_assert(!detail::NamedUnit>); -static_assert(!detail::NamedUnit>); +static_assert(!detail::NamedUnit>); static_assert(!detail::NamedUnit * si::second)>>); static_assert(!detail::NamedUnit>); static_assert(!detail::NamedUnit(si::metre))>>); @@ -185,7 +185,7 @@ static_assert(PrefixableUnit); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit)>>); static_assert(!PrefixableUnit>); -static_assert(!PrefixableUnit>); +static_assert(!PrefixableUnit>); static_assert(!PrefixableUnit * si::second)>>); static_assert(!PrefixableUnit>); static_assert(!PrefixableUnit(si::metre))>>); @@ -209,7 +209,7 @@ static_assert(!AssociatedUnit); static_assert(AssociatedUnit); static_assert(AssociatedUnit)>>); static_assert(AssociatedUnit>); -static_assert(AssociatedUnit>); +static_assert(AssociatedUnit>); static_assert(AssociatedUnit * si::second)>>); static_assert(AssociatedUnit>); static_assert(AssociatedUnit(si::metre))>>); @@ -232,7 +232,7 @@ static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); -static_assert(UnitOf); +static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); diff --git a/test/unit_test/static/dimension_test.cpp b/test/unit_test/static/dimension_test.cpp index d5091f54..0ceed4f6 100644 --- a/test/unit_test/static/dimension_test.cpp +++ b/test/unit_test/static/dimension_test.cpp @@ -41,8 +41,8 @@ inline constexpr struct time_ : base_dimension<"T"> {} time; QUANTITY_SPEC_(q_time, time); inline constexpr struct second_ : named_unit<"s", kind_of> {} second; -inline constexpr auto frequency = 1 / time; -inline constexpr auto action = 1 / time; +inline constexpr auto frequency = inverse(time); +inline constexpr auto action = inverse(time); inline constexpr auto area = length * length; inline constexpr auto volume = area * length; inline constexpr auto speed = length / time; @@ -71,13 +71,13 @@ static_assert(detail::DerivedDimension); // dimensio static_assert(detail::BaseDimension); // length // derived dimension expression template syntax verification -static_assert(is_of_type<1 / time, derived_dimension>>); -static_assert(is_of_type<1 / (1 / time), time_>); +static_assert(is_of_type>>); +static_assert(is_of_type); static_assert(is_of_type); static_assert(is_of_type