Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
Functions
Phyth::Utils Namespace Reference

Functions

Scalar sin (const Scalar q)
 Sine of a dimensionless quantity.
 
Scalar cos (const Scalar q)
 Cosine of a dimensionless quantity.
 
Scalar tan (const Scalar q)
 Tangent of a dimensionless quantity.
 
Scalar asin (const Scalar q)
 Arc sine (inverse sine)
 
Scalar acos (const Scalar q)
 Arc cosine (inverse cosine)
 
Scalar atan (const Scalar q)
 Arc tangent (inverse tangent)
 
Scalar atan2 (const Scalar y, const Scalar x)
 Two-argument arc tangent (atan2)
 
Scalar sinh (const Scalar q)
 Hyperbolic sine.
 
Scalar cosh (const Scalar q)
 Hyperbolic cosine.
 
Scalar tanh (const Scalar q)
 Hyperbolic tangent.
 
Scalar asinh (const Scalar q)
 Inverse hyperbolic sine.
 
Scalar acosh (const Scalar q)
 Inverse hyperbolic cosine.
 
Scalar atanh (const Scalar q)
 Inverse hyperbolic tangent.
 
Scalar log (const Scalar q)
 Natural logarithm (base e)
 
Scalar log10 (const Scalar q)
 Base-10 logarithm.
 
Scalar log2 (const Scalar q)
 Base-2 logarithm.
 
Scalar log1p (const Scalar q)
 log(1 + q) with higher precision for small q
 
Scalar exp (const Scalar q)
 Exponential (e^q)
 
Scalar expm1 (const Scalar q)
 exp(q) - 1 with higher precision for small q
 
Scalar exp2 (const Scalar q)
 Base-2 exponential (2^q)
 
template<int Power, typename UnitT >
auto pow (Quantity< UnitT > q)
 Raise a quantity to an integer power.
 
template<typename UnitT >
auto square (Quantity< UnitT > q)
 Square of a quantity.
 
template<typename UnitT >
auto cube (Quantity< UnitT > q)
 Cube of a quantity.
 
template<int N, typename UnitT >
auto root (Quantity< UnitT > q)
 N-th root of a quantity.
 
template<typename UnitT >
auto sqrt (Quantity< UnitT > q)
 Square root of a quantity.
 
template<typename UnitT >
auto cbrt (Quantity< UnitT > q)
 Cube root of a quantity.
 
template<typename UnitT >
auto abs (Quantity< UnitT > q)
 Absolute value of a quantity.
 
template<typename UnitT >
Quantity< UnitT > fmod (Quantity< UnitT > x, Quantity< UnitT > y)
 Floating-point remainder of x / y.
 
template<typename UnitT >
Quantity< UnitT > modf (Quantity< UnitT > x, Quantity< UnitT > &y)
 Decompose into integer and fractional parts.
 
template<typename UnitT >
Quantity< UnitT > max (Quantity< UnitT > x, Quantity< UnitT > y)
 Maximum of two quantities.
 
template<typename UnitT >
Quantity< UnitT > min (Quantity< UnitT > x, Quantity< UnitT > y)
 Minimum of two quantities.
 
template<typename UnitT >
Quantity< UnitT > clamp (Quantity< UnitT > x, Quantity< UnitT > min, Quantity< UnitT > max)
 Clamp a quantity between min and max bounds.
 
template<typename UnitT >
Quantity< UnitT > floor (Quantity< UnitT > x)
 Floor of a quantity (largest integer <= x)
 
template<typename UnitT >
bool isnan (Quantity< UnitT > x)
 Determine whether a quantity is nan.
 
template<typename UnitT >
bool isfinite (Quantity< UnitT > x)
 Determine whether a quantity is finite.
 

Function Documentation

◆ abs()

template<typename UnitT >
auto Phyth::Utils::abs ( Quantity< UnitT >  q)

Absolute value of a quantity.

Parameters
qThe quantity
Returns
Quantity with the same unit, value = |q.value|

Definition at line 332 of file QuantityFuncs.hpp.

◆ acos()

Scalar Phyth::Utils::acos ( const Scalar  q)
inline

Arc cosine (inverse cosine)

Parameters
qValue in [-1, 1] (dimensionless)
Returns
Angle in radians (dimensionless)

Definition at line 57 of file QuantityFuncs.hpp.

◆ acosh()

Scalar Phyth::Utils::acosh ( const Scalar  q)
inline

Inverse hyperbolic cosine.

Parameters
qValue (dimensionless)
Returns
acosh(q) as a dimensionless scalar

Definition at line 128 of file QuantityFuncs.hpp.

◆ asin()

Scalar Phyth::Utils::asin ( const Scalar  q)
inline

Arc sine (inverse sine)

Parameters
qValue in [-1, 1] (dimensionless)
Returns
Angle in radians (dimensionless)

Definition at line 47 of file QuantityFuncs.hpp.

◆ asinh()

Scalar Phyth::Utils::asinh ( const Scalar  q)
inline

Inverse hyperbolic sine.

Parameters
qValue (dimensionless)
Returns
asinh(q) as a dimensionless scalar

Definition at line 118 of file QuantityFuncs.hpp.

◆ atan()

Scalar Phyth::Utils::atan ( const Scalar  q)
inline

Arc tangent (inverse tangent)

Parameters
qValue (dimensionless)
Returns
Angle in radians (dimensionless)

Definition at line 67 of file QuantityFuncs.hpp.

◆ atan2()

Scalar Phyth::Utils::atan2 ( const Scalar  y,
const Scalar  x 
)
inline

Two-argument arc tangent (atan2)

Parameters
yY component (dimensionless)
xX component (dimensionless)
Returns
Angle in radians (dimensionless), in [-pi, pi]

Definition at line 78 of file QuantityFuncs.hpp.

◆ atanh()

Scalar Phyth::Utils::atanh ( const Scalar  q)
inline

Inverse hyperbolic tangent.

Parameters
qValue in (-1, 1) (dimensionless)
Returns
atanh(q) as a dimensionless scalar

Definition at line 138 of file QuantityFuncs.hpp.

◆ cbrt()

template<typename UnitT >
auto Phyth::Utils::cbrt ( Quantity< UnitT >  q)

Cube root of a quantity.

Parameters
qThe quantity to take the cube root of
Returns
Quantity with dimension DimT^(1/3)

Definition at line 321 of file QuantityFuncs.hpp.

◆ clamp()

template<typename UnitT >
Quantity< UnitT > Phyth::Utils::clamp ( Quantity< UnitT >  x,
Quantity< UnitT >  min,
Quantity< UnitT >  max 
)

Clamp a quantity between min and max bounds.

Parameters
xValue to clamp
minLower bound (inclusive)
maxUpper bound (inclusive)
Returns
If x < min, returns min; if x > max, returns max; otherwise returns x

Definition at line 400 of file QuantityFuncs.hpp.

◆ cos()

Scalar Phyth::Utils::cos ( const Scalar  q)
inline

Cosine of a dimensionless quantity.

Parameters
qAngle in radians (dimensionless)
Returns
cos(q) as a dimensionless scalar

Definition at line 27 of file QuantityFuncs.hpp.

◆ cosh()

Scalar Phyth::Utils::cosh ( const Scalar  q)
inline

Hyperbolic cosine.

Parameters
qValue (dimensionless)
Returns
cosh(q) as a dimensionless scalar

Definition at line 98 of file QuantityFuncs.hpp.

◆ cube()

template<typename UnitT >
auto Phyth::Utils::cube ( Quantity< UnitT >  q)

Cube of a quantity.

Template Parameters
UnitTUnit type of the input quantity
Parameters
qThe quantity to cube
Returns
Quantity with dimension DimT^3

Definition at line 271 of file QuantityFuncs.hpp.

◆ exp()

Scalar Phyth::Utils::exp ( const Scalar  q)
inline

Exponential (e^q)

Parameters
qValue (dimensionless)
Returns
e^q as a dimensionless scalar

Definition at line 188 of file QuantityFuncs.hpp.

◆ exp2()

Scalar Phyth::Utils::exp2 ( const Scalar  q)
inline

Base-2 exponential (2^q)

Parameters
qValue (dimensionless)
Returns
2^q as a dimensionless scalar

Definition at line 208 of file QuantityFuncs.hpp.

◆ expm1()

Scalar Phyth::Utils::expm1 ( const Scalar  q)
inline

exp(q) - 1 with higher precision for small q

Parameters
qValue (dimensionless)
Returns
e^q - 1 as a dimensionless scalar

Definition at line 198 of file QuantityFuncs.hpp.

◆ floor()

template<typename UnitT >
Quantity< UnitT > Phyth::Utils::floor ( Quantity< UnitT >  x)

Floor of a quantity (largest integer <= x)

Parameters
xInput quantity
Returns
Quantity with the same unit, value = floor(x.value)

Definition at line 412 of file QuantityFuncs.hpp.

◆ fmod()

template<typename UnitT >
Quantity< UnitT > Phyth::Utils::fmod ( Quantity< UnitT >  x,
Quantity< UnitT >  y 
)

Floating-point remainder of x / y.

Parameters
xDividend
yDivisor
Returns
x - n*y for some integer n, with the same unit as x and y

Definition at line 344 of file QuantityFuncs.hpp.

◆ isfinite()

template<typename UnitT >
bool Phyth::Utils::isfinite ( Quantity< UnitT >  x)

Determine whether a quantity is finite.

Parameters
xInput quantity
Returns
Return value = isfintie(x.value)

Definition at line 434 of file QuantityFuncs.hpp.

◆ isnan()

template<typename UnitT >
bool Phyth::Utils::isnan ( Quantity< UnitT >  x)

Determine whether a quantity is nan.

Parameters
xInput quantity
Returns
Return value = isnan(x.value)

Definition at line 423 of file QuantityFuncs.hpp.

◆ log()

Scalar Phyth::Utils::log ( const Scalar  q)
inline

Natural logarithm (base e)

Parameters
qPositive value (dimensionless)
Returns
ln(q) as a dimensionless scalar

Definition at line 148 of file QuantityFuncs.hpp.

◆ log10()

Scalar Phyth::Utils::log10 ( const Scalar  q)
inline

Base-10 logarithm.

Parameters
qPositive value (dimensionless)
Returns
log10(q) as a dimensionless scalar

Definition at line 158 of file QuantityFuncs.hpp.

◆ log1p()

Scalar Phyth::Utils::log1p ( const Scalar  q)
inline

log(1 + q) with higher precision for small q

Parameters
qValue (dimensionless)
Returns
log(1+q) as a dimensionless scalar

Definition at line 178 of file QuantityFuncs.hpp.

◆ log2()

Scalar Phyth::Utils::log2 ( const Scalar  q)
inline

Base-2 logarithm.

Parameters
qPositive value (dimensionless)
Returns
log2(q) as a dimensionless scalar

Definition at line 168 of file QuantityFuncs.hpp.

◆ max()

template<typename UnitT >
Quantity< UnitT > Phyth::Utils::max ( Quantity< UnitT >  x,
Quantity< UnitT >  y 
)

Maximum of two quantities.

Parameters
xFirst quantity
ySecond quantity
Returns
The larger quantity

Definition at line 373 of file QuantityFuncs.hpp.

◆ min()

template<typename UnitT >
Quantity< UnitT > Phyth::Utils::min ( Quantity< UnitT >  x,
Quantity< UnitT >  y 
)

Minimum of two quantities.

Parameters
xFirst quantity
ySecond quantity
Returns
The smaller quantity

Definition at line 386 of file QuantityFuncs.hpp.

◆ modf()

template<typename UnitT >
Quantity< UnitT > Phyth::Utils::modf ( Quantity< UnitT >  x,
Quantity< UnitT > &  y 
)

Decompose into integer and fractional parts.

Parameters
xInput quantity
yOutput: integer part (same unit as x)
Returns
Fractional part (same unit as x)

Example: auto x = 3.14_m; auto frac = Utils::modf(x, int_part); // int_part = 3_m, frac = 0.14_m

Definition at line 361 of file QuantityFuncs.hpp.

◆ pow()

template<int Power, typename UnitT >
auto Phyth::Utils::pow ( Quantity< UnitT >  q)

Raise a quantity to an integer power.

The resulting dimension is the original dimension raised to the power.

Template Parameters
PowerInteger exponent (can be negative)
UnitTUnit type of the input quantity
Parameters
qThe quantity to raise
Returns
Quantity with dimension DimT^Power

Example: auto t = 2.0_s; auto t2 = Utils::pow<2>(t); // 4 s^2 auto inv_t = Utils::pow<-1>(t); // 0.5 s^-1

Definition at line 228 of file QuantityFuncs.hpp.

◆ root()

template<int N, typename UnitT >
auto Phyth::Utils::root ( Quantity< UnitT >  q)

N-th root of a quantity.

Template Parameters
NRoot index (positive integer)
UnitTUnit type of the input quantity
Parameters
qThe quantity to take the root of
Returns
Quantity with dimension DimT^(1/N)

Example: auto area = 9.0_m2; auto length = Utils::root<2>(area); // 3.0_m

Definition at line 291 of file QuantityFuncs.hpp.

◆ sin()

Scalar Phyth::Utils::sin ( const Scalar  q)
inline

Sine of a dimensionless quantity.

Parameters
qAngle in radians (dimensionless)
Returns
sin(q) as a dimensionless scalar

Definition at line 17 of file QuantityFuncs.hpp.

◆ sinh()

Scalar Phyth::Utils::sinh ( const Scalar  q)
inline

Hyperbolic sine.

Parameters
qValue (dimensionless)
Returns
sinh(q) as a dimensionless scalar

Definition at line 88 of file QuantityFuncs.hpp.

◆ sqrt()

template<typename UnitT >
auto Phyth::Utils::sqrt ( Quantity< UnitT >  q)

Square root of a quantity.

Parameters
qThe quantity to take the square root of
Returns
Quantity with dimension DimT^(1/2)

Example: auto area = 9.0_m2; auto length = Utils::sqrt(area); // 3.0_m

Definition at line 310 of file QuantityFuncs.hpp.

◆ square()

template<typename UnitT >
auto Phyth::Utils::square ( Quantity< UnitT >  q)

Square of a quantity.

Template Parameters
UnitTUnit type of the input quantity
Parameters
qThe quantity to square
Returns
Quantity with dimension DimT^2

Example: auto t = 2.0_s; auto t2 = Utils::square(t); // 4 s^2

Definition at line 256 of file QuantityFuncs.hpp.

◆ tan()

Scalar Phyth::Utils::tan ( const Scalar  q)
inline

Tangent of a dimensionless quantity.

Parameters
qAngle in radians (dimensionless)
Returns
tan(q) as a dimensionless scalar

Definition at line 37 of file QuantityFuncs.hpp.

◆ tanh()

Scalar Phyth::Utils::tanh ( const Scalar  q)
inline

Hyperbolic tangent.

Parameters
qValue (dimensionless)
Returns
tanh(q) as a dimensionless scalar

Definition at line 108 of file QuantityFuncs.hpp.