qtty-cpp 0.4.5
Header-only C++ wrapper for qtty
Loading...
Searching...
No Matches
math.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2// Copyright (C) 2026 Vallés Puig, Ramon
3
4#pragma once
5
31#include <cmath>
32#include <type_traits>
33
34#include "units/angular.hpp"
36
37namespace qtty {
38
45template <typename U> Ratio ratio_to(const Quantity<U> &a, const Quantity<U> &b) {
46 return Ratio(a.value() / b.value());
47}
48
49// ── Transcendental helpers on dimensionless quantities ──────────────────────
50
51template <typename U, std::enable_if_t<is_dimensionless_v<U>, int> = 0>
53 return Ratio(std::exp(q.value()));
54}
55
56template <typename U, std::enable_if_t<is_dimensionless_v<U>, int> = 0>
58 return Ratio(std::log(q.value()));
59}
60
61template <typename U, std::enable_if_t<is_dimensionless_v<U>, int> = 0>
62Ratio powi(const Quantity<U> &q, int n) {
63 return Ratio(std::pow(q.value(), static_cast<double>(n)));
64}
65
66template <typename U, std::enable_if_t<is_dimensionless_v<U>, int> = 0>
68 return Ratio(std::pow(q.value(), exponent.value()));
69}
70
71template <typename U, std::enable_if_t<is_dimensionless_v<U>, int> = 0>
73 return Radian(std::asin(q.value()));
74}
75
76template <typename U, std::enable_if_t<is_dimensionless_v<U>, int> = 0>
78 return Radian(std::acos(q.value()));
79}
80
81template <typename U, std::enable_if_t<is_dimensionless_v<U>, int> = 0>
83 return Radian(std::atan(q.value()));
84}
85
86} // namespace qtty
Ratio powf(const Quantity< U > &q, const Ratio &exponent)
Definition math.hpp:67
Radian atan_angle(const Quantity< U > &q)
Definition math.hpp:82
Quantity< RadianTag > Radian
Definition angular.hpp:73
Ratio ratio_to(const Quantity< U > &a, const Quantity< U > &b)
Same-unit division returning a typed dimensionless Ratio.
Definition math.hpp:45
constexpr bool is_angular_v
Definition angles.hpp:49
Ratio powi(const Quantity< U > &q, int n)
Definition math.hpp:62
Ratio exp(const Quantity< U > &q)
Definition math.hpp:52
Ratio ln(const Quantity< U > &q)
Definition math.hpp:57
Radian acos_angle(const Quantity< U > &q)
Definition math.hpp:77
Radian asin_angle(const Quantity< U > &q)
Definition math.hpp:72
Quantity< RatioTag > Ratio