devela/num/float/
shared_docs.rs

1// devela::num::float::shared_docs
2//
3//! Defines constants for shared documentation on [`Float`] and [`ExtFloat`].
4//
5
6crate::CONST! { pub(crate),
7/* Rounding */
8
9FORMULA_FLOOR = r#"$$
10\large \lfloor x \rfloor = \max \{ n \in \mathbb{Z} \,|\, n \leq x \} $$"#;
11FORMULA_CEIL = r#"$$
12$$ \lceil x \rceil = \min \{ n \in \mathbb{Z} \,|\, n \geq x \} $$"#;
13FORMULA_ROUND_TIES_AWAY = r#"$$
14\text{round\\_ties\\_away}(x) = \begin{cases}
15\lceil x \rceil, & \text{if } x - \lfloor x \rfloor > 0.5 \text{ or }
16    (x - \lfloor x \rfloor = 0.5 \text{ and } x > 0) \cr
17\lfloor x \rfloor, & \text{if } x - \lfloor x \rfloor < 0.5 \text{ or }
18    (x - \lfloor x \rfloor = 0.5 \text{ and } x < 0)
19\end{cases}
20$$"#;
21FORMULA_ROUND_TIES_EVEN = r#"$$
22\text{round\\_ties\\_even}(x) = \begin{cases}
23\lceil x \rceil, & \text{if } x - \lfloor x \rfloor > 0.5 \cr
24\lfloor x \rfloor, & \text{if } x - \lfloor x \rfloor < 0.5 \cr
25\lfloor x \rfloor, & \text{if } x - \lfloor x \rfloor = 0.5 \text{ and }
26    \lfloor x \rfloor \text{ is even} \cr
27\lceil x \rceil, & \text{if } x - \lfloor x \rfloor = 0.5 \text{ and }
28    \lfloor x \rfloor \text{ is odd}
29\end{cases}
30$$"#;
31FORMULA_ROUND_TIES_ODD = r#"$$
32\text{round\\_ties\\_odd}(x) = \begin{cases}
33\lceil x \rceil, & \text{if } x - \lfloor x \rfloor > 0.5 \cr
34\lfloor x \rfloor, & \text{if } x - \lfloor x \rfloor < 0.5 \cr
35\lfloor x \rfloor, & \text{if } x - \lfloor x \rfloor = 0.5 \text{ and }
36    \lfloor x \rfloor \text{ is odd} \cr
37\lceil x \rceil, & \text{if } x - \lfloor x \rfloor = 0.5 \text{ and }
38    \lfloor x \rfloor \text{ is even}
39\end{cases}
40$$"#;
41FORMULA_TRUNC = r#"$$
42\text{trunc}(x) = \begin{cases}
43\lfloor x \rfloor, & \text{if } x \geq 0 \\
44\lceil x \rceil, & \text{if } x < 0
45\end{cases}
46$$"#;
47FORMULA_FRACT = r#"$$ \text{fract}(x) = x - \text{trunc}(x) $$"#;
48FORMULA_SPLIT = r#"$$ \text{split}(x) = (\text{trunc}(x), \text{fract}(x)) $$"#;
49
50
51/* Linear interpolation */
52
53FORMULA_SCALE = r#"$$
54\large \text{scale}(x, min, max, u, v) = (v - u) \frac{x - min}{max - min} + u $$"#;
55FORMULA_LERP = r#"$$ \large \text{lerp}(x, u, v) = (1 - x) \cdot u + x \cdot v $$"#;
56
57/* Exponentials and Logarithms */
58
59FORMULA_POWF_SERIES = r#"$$ \large x^y = e^{y \cdot \ln(x)} $$"#;
60FORMULA_HYPOT_NR = r#"$$ \text{hypot}(x, y) = \sqrt{x^2 + y^2} $$"#;
61FORMULA_HYPOT_FISR = r#"$$ \text{hypot}(x, y) = \sqrt{x^2 + y^2} $$"#;
62
63FORMULA_EXP_SERIES = r#"$$
64e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \cdots $$
65For values $ x < 0 $ it uses the identity: $$ e^x = \frac{1}{e^-x} $$"#;
66FORMULA_EXP_M1_SERIES = r#"$$
67e^x -1 = x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \cdots $$
68For values $ x < 0 $ it uses the identity: $$ e^x -1 = -\frac{1}{e^{-x}+1} $$
69For values $ x > 0.001 $ it uses [`exp_series`][Self::exp_series]."#;
70FORMULA_EXP2_SERIES = r#"
71The series based on the formula $ 2^x = e^{x \ln(2)} $ is:
72$$ 2^x = 1 + x \ln(2) + \frac{(x \ln(2))^2}{2!} +
73\frac{(x \ln(2))^3}{3!} + \frac{(x \ln(2))^4}{4!} + \cdots $$"#;
74FORMULA_LN_SERIES = r#"$$
75\ln(x) = 2 \left( \frac{x-1}{x+1} + \frac{1}{3} \left( \frac{x-1}{x+1} \right)^3 +
76\frac{1}{5} \left( \frac{x-1}{x+1} \right)^5 + \cdots \right) $$"#;
77FORMULA_LOG_SERIES = r#"$$ \log_{\text{base}}(x) = \frac{\ln(x)}{\ln(\text{base})} $$"#;
78FORMULA_LOG2_SERIES = r#"$$ \log_{2}(x) = \frac{\ln(x)}{\ln(2)} $$"#;
79FORMULA_LOG10_SERIES = r#"$$ \log_{10}(x) = \frac{\ln(x)}{\ln(10)} $$"#;
80
81/* Trigonometry */
82
83FORMULA_SIN_SERIES = r#"$$
84\sin(x) = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \cdots $$"#;
85FORMULA_COS_SERIES = r#"$$
86\cos(x) = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \frac{x^6}{6!} + \cdots $$"#;
87FORMULA_TAN_SERIES = r#"$$ \tan(x) = \frac{\sin(x)}{\cos(x)} $$"#;
88FORMULA_ASIN_SERIES = r#"$$
89\arcsin(x) = x + \left( \frac{1}{2} \right) \frac{x^3}{3} +
90\left( \frac{1}{2} \cdot \frac{3}{4} \right) \frac{x^5}{5} +
91\left( \frac{1}{2} \cdot \frac{3}{4} \cdot \frac{5}{6} \right) \frac{x^7}{7} +
92\cdots $$"#;
93FORMULA_ACOS_SERIES = r#"$$ \arccos(x)=2π-arcsin(x) $$"#;
94FORMULA_ATAN_SERIES = r#"$$
95\arctan(x) = x - \frac{x^3}{3} + \frac{x^5}{5} - \frac{x^7}{7} + \cdots $$
96For values $ |x| > 1 $ it uses the identity:
97$$ \arctan(x) = \frac{\pi}{2} - \arctan(\frac{1}{x}) $$"#;
98FORMULA_SINH_SERIES = r#"$$ \sinh(x) = \frac{e^x - e^{-x}}{2} $$"#;
99FORMULA_COSH_SERIES = r#"$$ \cosh(x) = \frac{e^x + e^{-x}}{2} $$"#;
100FORMULA_TANH_SERIES = r#"$$ \tanh(x) = \frac{\sinh(x)}{\cosh(x)} $$"#;
101FORMULA_ASINH_SERIES = r#"$$ \text{asinh}(x) = \ln(x + \sqrt{x^2 + 1}) $$"#;
102FORMULA_ACOSH_SERIES = r#"$$ \text{acosh}(x) = \ln(x + \sqrt{x^2 - 1}) $$"#;
103FORMULA_ATANH_SERIES = r#"$$
104\text{atanh}(x) = \frac{1}{2} \ln\left(\frac{1 + x}{1 - x}\right) $$"#;
105
106/* Calculus */
107
108FORMULA_DERIVATIVE = r#"$$ f'(x) \approx \frac{f(x + h) - f(x)}{h} $$"#;
109FORMULA_INTEGRATE = r#"$$
110\int_a^b f(x) \, dx \approx \sum_{i=0}^{n-1} f(x_i) \cdot \Delta x $$
111where $$ \Delta x = \frac{b-a}{n} $$"#;
112FORMULA_PARTIAL_DERIVATIVE_X = r#"
113\frac{\partial f}{\partial x} \approx \frac{f(x + h, y) - f(x, y)}{h} $$"#;
114FORMULA_PARTIAL_DERIVATIVE_Y = r#"
115\frac{\partial f}{\partial x} \approx \frac{f(x + h, y) - f(x, y)}{h} $$"#;
116}