Arithmetic capability traits and checked analytic operations for LunaFlow numeric types, with default real-valued instances.
Dependencies
using @lg { trait Add, trait Mul }
fn hypot2[T : Add + Mul + Sqrt](x : T, y : T) -> T {
Sqrt::sqrt(x * x + y * y)
}
fn polar_x[T : Mul + Trigonometric](r : T, theta : T) -> T {
r * Trigonometric::cos(theta)
}
inspect(hypot2(3.0, 4.0), content="5")
inspect(
polar_x(2.0, Constants::pi() / 3.0),
content="1.0000000000000002",
)moon check
moon testpub(open) trait Cbrt {
fn cbrt(Self) -> Self
}pub(open) trait Constants {
fn pi() -> Self
fn tau() -> Self
fn e() -> Self
}pub(open) trait DivChecked {
fn div_checked(Self, Self, ArithmeticContext) -> Result[Self, ArithmeticError]
}impl DivChecked for Floatfn div_checked(lhs : Float, rhs : Float, _ctx : ArithmeticContext) -> Result[Float, ArithmeticError]impl DivChecked for Doublefn div_checked(lhs : Double, rhs : Double, _ctx : ArithmeticContext) -> Result[Double, ArithmeticError]pub(open) trait Exponential {
fn exp(Self) -> Self
fn exp2(Self) -> Self
}pub(open) trait Hyperbolic {
fn sinh(Self) -> Self
fn cosh(Self) -> Self
fn tanh(Self) -> Self
}pub(open) trait InverseHyperbolic {
fn asinh(Self) -> Self
fn acosh(Self) -> Self
fn atanh(Self) -> Self
}pub(open) trait InverseTrigonometric {
fn asin(Self) -> Self
fn acos(Self) -> Self
fn atan(Self) -> Self
fn atan2(Self, Self) -> Self
}impl InverseTrigonometric for Floatpub(open) trait Logarithmic {
fn ln(Self) -> Self
fn log2(Self) -> Self
fn log10(Self) -> Self
}pub(open) trait ParseChecked {
fn parse_checked(String, ArithmeticContext) -> Result[Self, ArithmeticError]
}pub(open) trait PowIntChecked {
fn pow_int_checked(Self, Int, ArithmeticContext) -> Result[Self, ArithmeticError]
}impl PowIntChecked for Floatfn pow_int_checked(base : Float, exponent : Int, ctx : ArithmeticContext) -> Result[Float, ArithmeticError]impl PowIntChecked for Doublefn pow_int_checked(base : Double, exponent : Int, ctx : ArithmeticContext) -> Result[Double, ArithmeticError]pub(open) trait PowNatChecked {
fn pow_nat_checked(Self, UInt, ArithmeticContext) -> Result[Self, ArithmeticError]
}impl PowNatChecked for Floatfn pow_nat_checked(base : Float, exponent : UInt, _ctx : ArithmeticContext) -> Result[Float, ArithmeticError]impl PowNatChecked for Doublefn pow_nat_checked(base : Double, exponent : UInt, _ctx : ArithmeticContext) -> Result[Double, ArithmeticError]pub(open) trait Power {
fn pow(Self, Self) -> Self
}pub(open) trait Sqrt {
fn sqrt(Self) -> Self
}pub(open) trait SqrtChecked {
fn sqrt_checked(Self, ArithmeticContext) -> Result[Self, ArithmeticError]
}pub(open) trait Trigonometric {
fn sin(Self) -> Self
fn cos(Self) -> Self
fn tan(Self) -> Self
}pub enum ArithmeticErrorKind {
DivisionByZero
ParseError
DomainError
FormatError
UnsupportedOperation
UnorderedComparison
} derive(Eq)Arithmetic capability traits and checked analytic operations for LunaFlow numeric types, with default real-valued instances.
Dependencies