graphviz_pure_core/math/
mod.rs1#[doc(hidden)]
16pub mod portable;
17#[cfg(feature = "math-trace")]
18mod trace;
19#[cfg(not(feature = "math-trace"))]
20mod trace {
21 #[inline(always)]
22 pub fn log(_name: u8, _x: f64, _y: f64) {}
23}
24
25pub const PORTABLE: bool = cfg!(any(not(target_vendor = "apple"), feature = "portable-math"));
28
29#[derive(Clone, Copy, Debug, PartialEq, Eq)]
33pub enum Profile {
34 Apple,
36 Portable,
38}
39
40impl Profile {
41 #[must_use]
43 pub const fn name(self) -> &'static str {
44 match self {
45 Profile::Apple => "apple",
46 Profile::Portable => "portable",
47 }
48 }
49}
50
51pub const PROFILE: Profile = if PORTABLE {
53 Profile::Portable
54} else {
55 Profile::Apple
56};
57
58#[inline]
60#[must_use]
61pub fn hypot(x: f64, y: f64) -> f64 {
62 trace::log(0, x, y);
63 if PORTABLE {
64 portable::hypot(x, y)
65 } else {
66 x.hypot(y)
67 }
68}
69
70#[inline]
72#[must_use]
73pub fn powf(x: f64, y: f64) -> f64 {
74 trace::log(1, x, y);
75 if PORTABLE {
76 portable::pow(x, y)
77 } else {
78 x.powf(y)
79 }
80}
81
82#[inline]
84#[must_use]
85pub fn atan2(y: f64, x: f64) -> f64 {
86 trace::log(2, y, x);
87 if PORTABLE {
88 portable::atan2(y, x)
89 } else {
90 y.atan2(x)
91 }
92}
93
94#[inline]
96#[must_use]
97pub fn sin(x: f64) -> f64 {
98 trace::log(3, x, 0.0);
99 if PORTABLE { portable::sin(x) } else { x.sin() }
100}
101
102#[inline]
104#[must_use]
105pub fn cos(x: f64) -> f64 {
106 trace::log(4, x, 0.0);
107 if PORTABLE { portable::cos(x) } else { x.cos() }
108}
109
110#[inline]
112#[must_use]
113pub fn tan(x: f64) -> f64 {
114 trace::log(5, x, 0.0);
115 if PORTABLE { portable::tan(x) } else { x.tan() }
116}
117
118#[inline]
120#[must_use]
121pub fn asin(x: f64) -> f64 {
122 trace::log(6, x, 0.0);
123 if PORTABLE {
124 portable::asin(x)
125 } else {
126 x.asin()
127 }
128}
129
130#[inline]
132#[must_use]
133pub fn acos(x: f64) -> f64 {
134 trace::log(7, x, 0.0);
135 if PORTABLE {
136 portable::acos(x)
137 } else {
138 x.acos()
139 }
140}
141
142#[inline]
144#[must_use]
145pub fn exp(x: f64) -> f64 {
146 trace::log(8, x, 0.0);
147 if PORTABLE { portable::exp(x) } else { x.exp() }
148}
149
150#[inline]
152#[must_use]
153pub fn ln(x: f64) -> f64 {
154 trace::log(9, x, 0.0);
155 if PORTABLE { portable::log(x) } else { x.ln() }
156}
157
158#[inline]
160#[must_use]
161pub fn log2(x: f64) -> f64 {
162 trace::log(10, x, 0.0);
163 if PORTABLE {
164 portable::log2(x)
165 } else {
166 x.log2()
167 }
168}
169
170#[inline]
172#[must_use]
173pub fn cbrt(x: f64) -> f64 {
174 trace::log(11, x, 0.0);
175 if PORTABLE {
176 portable::cbrt(x)
177 } else {
178 x.cbrt()
179 }
180}
181
182#[cfg(all(test, target_vendor = "apple"))]
183mod tests;