Debian Codegraph @

debian/missing-sources/glam-0.29.3/src/f32/math.rs

raw symbols SCIP
1 /// Returns a very close approximation of `self.clamp(-1.0, 1.0).acos()`.
2 #[inline]
3 fn acos_approx_f32rust-analyzer cargo glam 0.29.3 f32/math/acos_approx_f32().(v: f32) -> f32 {
4 // Based on https://github.com/microsoft/DirectXMath `XMScalarAcos`
5 // Clamp input to [-1,1].
6 let nonnegative = v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]ge().0.0;
7 let x = absrust-analyzer cargo glam 0.29.3 f32/math/std_math/abs().(v);
8 let mut omx = 1.0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().x;
9 if omx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f32][`PartialOrd<Self>`]lt().0.0 {
10 omx = 0.0;
11 }
12 let root = sqrtrust-analyzer cargo glam 0.29.3 f32/math/std_math/sqrt().(omx);
13
14 // 7-degree minimax approximation
15 #[allow(clippy::approx_constant)]
16 let mut result =
17 ((((((-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().0.001_262_491_1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().0.006_670_09) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().0.017_088_126) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().0.030_891_88) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().x
18 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().0.050_174_303)
19 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().x
20 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().0.088_978_99)
21 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().x
22 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().0.214_598_8)
23 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().x
24 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Add<Self>`]add().1.570_796_3;
25 result rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`MulAssign<Self>`]mul_assign().*=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`MulAssign<Self>`]mul_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`MulAssign<Self>`]mul_assign().root;
26
27 // acos(x) = pi - acos(-x) when x < 0
28 if nonnegative {
29 result
30 } else {
31 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::f32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/::constsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/consts/::PIrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/consts/PI. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Sub<Self>`]sub().result
32 }
33 }
34
35 #[cfg(any(feature = "libm", all(feature = "nostd-libm", not(feature = "std"))))]
36 mod libm_math {
37 #[inline(always)]
38 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn abs(f: f32) -> f32 {
39 libm::fabsf(f)
40 }
41
42 #[inline(always)]
43 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn acos_approx(f: f32) -> f32 {
44 superrust-analyzer cargo glam 0.29.3 f32/::acos_approx_f32(f)
45 }
46
47 #[inline(always)]
48 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn atan2(f: f32, other: f32) -> f32 {
49 libm::atan2f(f, other)
50 }
51
52 #[allow(unused)]
53 #[inline(always)]
54 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn sin(f: f32) -> f32 {
55 libm::sinf(f)
56 }
57
58 #[inline(always)]
59 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn sin_cos(f: f32) -> (f32, f32) {
60 libm::sincosf(f)
61 }
62
63 #[inline(always)]
64 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn tan(f: f32) -> f32 {
65 libm::tanf(f)
66 }
67
68 #[inline(always)]
69 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn sqrt(f: f32) -> f32 {
70 libm::sqrtf(f)
71 }
72
73 #[inline(always)]
74 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn copysign(f: f32, sign: f32) -> f32 {
75 libm::copysignf(f, sign)
76 }
77
78 #[inline(always)]
79 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn signum(f: f32) -> f32 {
80 if f.is_nan() {
81 f32::NAN
82 } else {
83 copysignrust-analyzer cargo glam 0.29.3 f32/math/std_math/copysign().(1.0, f)
84 }
85 }
86
87 #[inline(always)]
88 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn round(f: f32) -> f32 {
89 libm::roundf(f)
90 }
91
92 #[inline(always)]
93 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn trunc(f: f32) -> f32 {
94 libm::truncf(f)
95 }
96
97 #[inline(always)]
98 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn ceil(f: f32) -> f32 {
99 libm::ceilf(f)
100 }
101
102 #[inline(always)]
103 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn floor(f: f32) -> f32 {
104 libm::floorf(f)
105 }
106
107 #[inline(always)]
108 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn exp(f: f32) -> f32 {
109 libm::expf(f)
110 }
111
112 #[inline(always)]
113 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn powf(f: f32, n: f32) -> f32 {
114 libm::powf(f, n)
115 }
116
117 #[inline(always)]
118 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn mul_add(a: f32, b: f32, c: f32) -> f32 {
119 libm::fmaf(a, b, c)
120 }
121
122 #[inline]
123 pub fn div_euclid(a: f32, b: f32) -> f32 {
124 // Based on https://doc.rust-lang.org/src/std/f32.rs.html#293
125 let q = libm::truncf(a / b);
126 if a % b < 0.0 {
127 return if b > 0.0 { q - 1.0 } else { q + 1.0 };
128 }
129 q
130 }
131
132 #[inline]
133 pub fn rem_euclid(a: f32, b: f32) -> f32 {
134 let r = a % b;
135 if r < 0.0 {
136 r + absrust-analyzer cargo glam 0.29.3 f32/math/std_math/abs().(b)
137 } else {
138 r
139 }
140 }
141 }
142
143 #[cfg(all(not(feature = "libm"), feature = "std"))]
144 mod std_mathrust-analyzer cargo glam 0.29.3 f32/math/std_math/ {
145 #[inline(always)]
146 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn absrust-analyzer cargo glam 0.29.3 f32/math/std_math/abs().(f: f32) -> f32 {
147 f32::absrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]abs().(f)
148 }
149
150 #[inline(always)]
151 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn acos_approxrust-analyzer cargo glam 0.29.3 f32/math/std_math/acos_approx().(f: f32) -> f32 {
152 superrust-analyzer cargo glam 0.29.3 f32/math/::acos_approx_f32rust-analyzer cargo glam 0.29.3 f32/math/acos_approx_f32().(f)
153 }
154
155 #[inline(always)]
156 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn atan2rust-analyzer cargo glam 0.29.3 f32/math/std_math/atan2().(f: f32, other: f32) -> f32 {
157 f32::atan2rust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]atan2().(f, other)
158 }
159
160 #[allow(unused)]
161 #[inline(always)]
162 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn sinrust-analyzer cargo glam 0.29.3 f32/math/std_math/sin().(f: f32) -> f32 {
163 f32::sinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]sin().(f)
164 }
165
166 #[inline(always)]
167 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn sin_cosrust-analyzer cargo glam 0.29.3 f32/math/std_math/sin_cos().(f: f32) -> (f32, f32) {
168 f32::sin_cosrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]sin_cos().(f)
169 }
170
171 #[inline(always)]
172 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn tanrust-analyzer cargo glam 0.29.3 f32/math/std_math/tan().(f: f32) -> f32 {
173 f32::tanrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]tan().(f)
174 }
175
176 #[inline(always)]
177 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn sqrtrust-analyzer cargo glam 0.29.3 f32/math/std_math/sqrt().(f: f32) -> f32 {
178 f32::sqrtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]sqrt().(f)
179 }
180
181 #[inline(always)]
182 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn copysignrust-analyzer cargo glam 0.29.3 f32/math/std_math/copysign().(f: f32, sign: f32) -> f32 {
183 f32::copysignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]copysign().(f, sign)
184 }
185
186 #[inline(always)]
187 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn signumrust-analyzer cargo glam 0.29.3 f32/math/std_math/signum().(f: f32) -> f32 {
188 f32::signumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]signum().(f)
189 }
190
191 #[inline(always)]
192 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn roundrust-analyzer cargo glam 0.29.3 f32/math/std_math/round().(f: f32) -> f32 {
193 f32::roundrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]round().(f)
194 }
195
196 #[inline(always)]
197 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn truncrust-analyzer cargo glam 0.29.3 f32/math/std_math/trunc().(f: f32) -> f32 {
198 f32::truncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]trunc().(f)
199 }
200
201 #[inline(always)]
202 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn ceilrust-analyzer cargo glam 0.29.3 f32/math/std_math/ceil().(f: f32) -> f32 {
203 f32::ceilrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]ceil().(f)
204 }
205
206 #[inline(always)]
207 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn floorrust-analyzer cargo glam 0.29.3 f32/math/std_math/floor().(f: f32) -> f32 {
208 f32::floorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]floor().(f)
209 }
210
211 #[inline(always)]
212 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn exprust-analyzer cargo glam 0.29.3 f32/math/std_math/exp().(f: f32) -> f32 {
213 f32::exprust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]exp().(f)
214 }
215
216 #[inline(always)]
217 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn powfrust-analyzer cargo glam 0.29.3 f32/math/std_math/powf().(f: f32, n: f32) -> f32 {
218 f32::powfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]powf().(f, n)
219 }
220
221 #[inline(always)]
222 pub(craterust-analyzer cargo glam 0.29.3 crate/) fn mul_addrust-analyzer cargo glam 0.29.3 f32/math/std_math/mul_add().(a: f32, b: f32, c: f32) -> f32 {
223 f32::mul_addrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]mul_add().(a, b, c)
224 }
225
226 #[inline]
227 pub fn div_euclidrust-analyzer cargo glam 0.29.3 f32/math/std_math/div_euclid().(a: f32, b: f32) -> f32 {
228 f32::div_euclidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]div_euclid().(a, b)
229 }
230
231 #[inline]
232 pub fn rem_euclidrust-analyzer cargo glam 0.29.3 f32/math/std_math/rem_euclid().(a: f32, b: f32) -> f32 {
233 f32::rem_euclidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]rem_euclid().(a, b)
234 }
235 }
236
237 #[cfg(any(feature = "libm", all(feature = "nostd-libm", not(feature = "std"))))]
238 pub(craterust-analyzer cargo glam 0.29.3 crate/) use libm_math::*;
239
240 #[cfg(all(not(feature = "libm"), feature = "std"))]
241 pub(craterust-analyzer cargo glam 0.29.3 crate/) use std_mathrust-analyzer cargo glam 0.29.3 f32/math/std_math/::*;