Debian Codegraph @

debian/missing-sources/glam-0.18.0/src/core/traits/scalar.rs

raw symbols SCIP
1 // Wait until this bug is fix and float cmp to zero don't report a warning.
2 // https://github.com/rust-lang/rust-clippy/issues/3804
3 #![allow(clippy::float_cmp)]
4 // num_traits is optional as it adds 70% to compile times. It is needed by no_std builds
5 #[cfg(feature = "libm")]
6 pub use num_traits::{Float, Num, Signed};
7
8 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{
9 markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#,
10 opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#, Divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#, Mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#, Remrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Rem#, Subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#},
11 };
12
13 // Stub the necessary parts of num traits
14 #[cfg(not(feature = "libm"))]
15 pub trait Numrust-analyzer cargo glam 0.18.0 core/traits/scalar/Num#: PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# {}
16
17 #[cfg(not(feature = "libm"))]
18 pub trait Signedrust-analyzer cargo glam 0.18.0 core/traits/scalar/Signed#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + Numrust-analyzer cargo glam 0.18.0 core/traits/scalar/Num# + corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Negrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Neg#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Neg#Output# = Self> {
19 fn absrust-analyzer cargo glam 0.18.0 core/traits/scalar/Signed#abs().(self) -> Self;
20 fn signumrust-analyzer cargo glam 0.18.0 core/traits/scalar/Signed#signum().(self) -> Self;
21 }
22
23 #[cfg(not(feature = "libm"))]
24 pub trait Floatrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#: Numrust-analyzer cargo glam 0.18.0 core/traits/scalar/Num# + Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy# + corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Negrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Neg#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Neg#Output# = Self> {
25 fn asinrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#asin().(self) -> Self;
26 fn acosrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#acos().(self) -> Self;
27 fn ceilrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#ceil().(self) -> Self;
28 fn exprust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#exp().(self) -> Self;
29 fn floorrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#floor().(self) -> Self;
30 fn is_finiterust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#is_finite().(self) -> bool;
31 fn is_nanrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#is_nan().(self) -> bool;
32 fn powfrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#powf().(self, n: Self) -> Self;
33 fn reciprust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#recip().(self) -> Self;
34 fn roundrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#round().(self) -> Self;
35 fn sqrtrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#sqrt().(self) -> Self;
36 fn sinrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#sin().(self) -> Self;
37 fn sin_cosrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#sin_cos().(self) -> (Self, Self);
38 fn tanrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float#tan().(self) -> Self;
39 }
40
41 #[cfg(not(feature = "libm"))]
42 macro_rules! impl_num_traitrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl_num_trait! {
43 ($t:ident) => {
44 impl Num for $t {}
45 };
46 }
47
48 #[cfg(not(feature = "libm"))]
49 macro_rules! impl_signed_traitrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl_signed_trait! {
50 ($t:ident) => {
51 impl_num_trait!($t);
52
53 impl Signed for $t {
54 #[inline(always)]
55 fn abs(self) -> Self {
56 $t::abs(self)
57 }
58 #[inline(always)]
59 fn signum(self) -> Self {
60 $t::signum(self)
61 }
62 }
63 };
64 }
65
66 #[cfg(not(feature = "libm"))]
67 macro_rules! impl_float_traitrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl_float_trait! {
68 ($t:ident) => {
69 impl_signed_trait!($t);
70
71 impl Float for $t {
72 #[inline(always)]
73 fn asin(self) -> Self {
74 $t::asin(self)
75 }
76 #[inline(always)]
77 fn acos(self) -> Self {
78 $t::acos(self)
79 }
80 #[inline(always)]
81 fn ceil(self) -> Self {
82 $t::ceil(self)
83 }
84 #[inline(always)]
85 fn exp(self) -> Self {
86 $t::exp(self)
87 }
88 #[inline(always)]
89 fn floor(self) -> Self {
90 $t::floor(self)
91 }
92 #[inline(always)]
93 fn is_finite(self) -> bool {
94 $t::is_finite(self)
95 }
96 #[inline(always)]
97 fn is_nan(self) -> bool {
98 $t::is_nan(self)
99 }
100 #[inline(always)]
101 fn powf(self, n: Self) -> Self {
102 $t::powf(self, n)
103 }
104 #[inline(always)]
105 fn recip(self) -> Self {
106 $t::recip(self)
107 }
108 #[inline(always)]
109 fn round(self) -> Self {
110 $t::round(self)
111 }
112 #[inline(always)]
113 fn sin(self) -> Self {
114 $t::sin(self)
115 }
116 #[inline(always)]
117 fn sin_cos(self) -> (Self, Self) {
118 $t::sin_cos(self)
119 }
120 #[inline(always)]
121 fn sqrt(self) -> Self {
122 $t::sqrt(self)
123 }
124 #[inline(always)]
125 fn tan(self) -> Self {
126 $t::tan(self)
127 }
128 }
129 };
130 }
131
132 #[cfg(not(feature = "libm"))]
133 impl_float_traitrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl_float_trait!!(f32);
134 #[cfg(not(feature = "libm"))]
135 impl_float_traitrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl_float_trait!!(f64);
136 #[cfg(not(feature = "libm"))]
137 impl_signed_traitrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl_signed_trait!!(i32);
138 #[cfg(not(feature = "libm"))]
139 impl_num_traitrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl_num_trait!!(u32);
140
141 pub trait MaskConstrust-analyzer cargo glam 0.18.0 core/traits/scalar/MaskConst#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
142 const MASKrust-analyzer cargo glam 0.18.0 core/traits/scalar/MaskConst#MASK.: [Self; 2];
143 }
144
145 pub trait NumConstExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumConstEx#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
146 const ZEROrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumConstEx#ZERO.: Self;
147 const ONErust-analyzer cargo glam 0.18.0 core/traits/scalar/NumConstEx#ONE.: Self;
148 }
149
150 pub trait FloatConstExrust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatConstEx#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
151 const NEG_ONErust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatConstEx#NEG_ONE.: Self;
152 const TWOrust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatConstEx#TWO.: Self;
153 const HALFrust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatConstEx#HALF.: Self;
154 }
155
156 pub trait NumExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumEx#:
157 Numrust-analyzer cargo glam 0.18.0 core/traits/scalar/Num#
158 + NumConstExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumConstEx#
159 + Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#
160 + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#
161 + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#
162 + PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#
163 + Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#Output# = Self>
164 + Divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#Output# = Self>
165 + Mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#Output# = Self>
166 + Subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#Output# = Self>
167 + Remrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Rem#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Rem#Output# = Self>
168 {
169 fn minrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumEx#min().(self, other: Self) -> Self;
170 fn maxrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumEx#max().(self, other: Self) -> Self;
171 }
172
173 pub trait SignedExrust-analyzer cargo glam 0.18.0 core/traits/scalar/SignedEx#: Signedrust-analyzer cargo glam 0.18.0 core/traits/scalar/Signed# + NumExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumEx# {}
174
175 pub trait FloatExrust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatEx#: Floatrust-analyzer cargo glam 0.18.0 core/traits/scalar/Float# + FloatConstExrust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatConstEx# + SignedExrust-analyzer cargo glam 0.18.0 core/traits/scalar/SignedEx# {
176 /// Returns a very close approximation of `self.clamp(-1.0, 1.0).acos()`.
177 fn acos_approxrust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatEx#acos_approx().(self) -> Self;
178 fn from_f32rust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatEx#from_f32().(f: f32) -> Self;
179 fn from_f64rust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatEx#from_f64().(f: f64) -> Self;
180 }
181
182 impl NumConstExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumConstEx# for f32 {
183 const ZEROrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][NumConstEx]ZERO.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][NumConstEx] = 0.0;
184 const ONErust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][NumConstEx]ONE.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][NumConstEx] = 1.0;
185 }
186
187 impl FloatConstExrust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatConstEx# for f32 {
188 const NEG_ONErust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatConstEx]NEG_ONE.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatConstEx] = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().1.0;
189 const TWOrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatConstEx]TWO.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatConstEx] = 2.0;
190 const HALFrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatConstEx]HALF.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatConstEx] = 0.5;
191 }
192
193 impl NumExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumEx# for f32 {
194 #[inline(always)]
195 fn minrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][NumEx]min().(self, other: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][NumEx]) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][NumEx] {
196 f32::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]min().(self, other)
197 }
198 #[inline(always)]
199 fn maxrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][NumEx]max().(self, other: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][NumEx]) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][NumEx] {
200 f32::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]max().(self, other)
201 }
202 }
203
204 impl SignedExrust-analyzer cargo glam 0.18.0 core/traits/scalar/SignedEx# for f32 {}
205
206 impl FloatExrust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatEx# for f32 {
207 #[inline(always)]
208 fn from_f32rust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatEx]from_f32().(v: f32) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatEx] {
209 v
210 }
211 #[inline(always)]
212 fn from_f64rust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatEx]from_f64().(v: f64) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatEx] {
213 v as Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatEx]
214 }
215 #[inline(always)]
216 fn acos_approxrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatEx]acos_approx().(self) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f32][FloatEx] {
217 // Based on https://github.com/microsoft/DirectXMath `XMScalarAcos`
218 // Clamp input to [-1,1].
219 let nonnegative = self 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;
220 let x = self.absrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]abs().();
221 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;
222 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 {
223 omx = 0.0;
224 }
225 let root = omx.sqrtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]sqrt().();
226
227 // 7-degree minimax approximation
228 #[allow(clippy::approx_constant)]
229 let mut result = ((((((-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
230 +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)
231 *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
232 -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)
233 *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
234 +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)
235 *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
236 -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)
237 *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
238 +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;
239 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;
240
241 // acos(x) = pi - acos(-x) when x < 0
242 if nonnegative {
243 result
244 } else {
245 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
246 }
247 }
248 }
249
250 impl NumConstExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumConstEx# for f64 {
251 const ZEROrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][NumConstEx]ZERO.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][NumConstEx] = 0.0;
252 const ONErust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][NumConstEx]ONE.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][NumConstEx] = 1.0;
253 }
254
255 impl FloatConstExrust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatConstEx# for f64 {
256 const NEG_ONErust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatConstEx]NEG_ONE.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatConstEx] = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0;
257 const TWOrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatConstEx]TWO.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatConstEx] = 2.0;
258 const HALFrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatConstEx]HALF.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatConstEx] = 0.5;
259 }
260
261 impl NumExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumEx# for f64 {
262 #[inline(always)]
263 fn minrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][NumEx]min().(self, other: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][NumEx]) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][NumEx] {
264 f64::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]min().(self, other)
265 }
266 #[inline(always)]
267 fn maxrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][NumEx]max().(self, other: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][NumEx]) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][NumEx] {
268 f64::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]max().(self, other)
269 }
270 }
271
272 impl SignedExrust-analyzer cargo glam 0.18.0 core/traits/scalar/SignedEx# for f64 {}
273
274 impl FloatExrust-analyzer cargo glam 0.18.0 core/traits/scalar/FloatEx# for f64 {
275 #[inline(always)]
276 fn from_f32rust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatEx]from_f32().(v: f32) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatEx] {
277 v as Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatEx]
278 }
279 #[inline(always)]
280 fn from_f64rust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatEx]from_f64().(v: f64) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatEx] {
281 v
282 }
283 #[inline(always)]
284 fn acos_approxrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatEx]acos_approx().(self) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[f64][FloatEx] {
285 f64::acosrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/impl#[f64]acos().(self.maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]max().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0).minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]min().(1.0))
286 }
287 }
288
289 impl NumConstExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumConstEx# for i32 {
290 const ZEROrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[i32][NumConstEx]ZERO.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[i32][NumConstEx] = 0;
291 const ONErust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[i32][NumConstEx]ONE.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[i32][NumConstEx] = 1;
292 }
293
294 impl NumExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumEx# for i32 {
295 #[inline(always)]
296 fn minrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[i32][NumEx]min().(self, other: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[i32][NumEx]) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[i32][NumEx] {
297 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(self, other)
298 }
299 #[inline(always)]
300 fn maxrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[i32][NumEx]max().(self, other: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[i32][NumEx]) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[i32][NumEx] {
301 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(self, other)
302 }
303 }
304
305 impl SignedExrust-analyzer cargo glam 0.18.0 core/traits/scalar/SignedEx# for i32 {}
306
307 impl NumConstExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumConstEx# for u32 {
308 const ZEROrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[u32][NumConstEx]ZERO.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[u32][NumConstEx] = 0;
309 const ONErust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[u32][NumConstEx]ONE.: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[u32][NumConstEx] = 1;
310 }
311
312 impl NumExrust-analyzer cargo glam 0.18.0 core/traits/scalar/NumEx# for u32 {
313 #[inline(always)]
314 fn minrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[u32][NumEx]min().(self, other: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[u32][NumEx]) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[u32][NumEx] {
315 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(self, other)
316 }
317 #[inline(always)]
318 fn maxrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[u32][NumEx]max().(self, other: Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[u32][NumEx]) -> Selfrust-analyzer cargo glam 0.18.0 core/traits/scalar/impl#[u32][NumEx] {
319 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(self, other)
320 }
321 }
322
323 #[cfg(test)]
324 macro_rules! assert_approx_eq {
325 ($a:expr, $b:expr) => {{
326 assert_approx_eq!($a, $b, core::f32::EPSILON);
327 }};
328 ($a:expr, $b:expr, $eps:expr) => {{
329 let (a, b) = (&$a, &$b);
330 let eps = $eps;
331 assert!(
332 (a - b).abs() <= eps,
333 "assertion failed: `(left !== right)` \
334 (left: `{:?}`, right: `{:?}`, expect diff: `{:?}`, real diff: `{:?}`)",
335 *a,
336 *b,
337 eps,
338 (a - b).abs()
339 );
340 }};
341 }
342
343 #[cfg(test)]
344 macro_rules! assert_relative_eq {
345 ($a:expr, $b:expr) => {{
346 assert_relative_eq!($a, $b, core::f32::EPSILON);
347 }};
348 ($a:expr, $b:expr, $eps:expr) => {{
349 let (a, b) = (&$a, &$b);
350 let eps = $eps;
351 let diff = (a - b).abs();
352 let largest = a.abs().max(b.abs());
353 assert!(
354 diff <= largest * eps,
355 "assertion failed: `(left !== right)` \
356 (left: `{:?}`, right: `{:?}`, expect diff: `{:?}`, real diff: `{:?}`)",
357 *a,
358 *b,
359 largest * eps,
360 diff
361 );
362 }};
363 }
364
365 #[test]
366 fn test_scalar_acos() {
367 fn test_scalar_acos_angle(a: f32) {
368 // 1e-6 is the lowest epsilon that will pass
369 assert_relative_eq!(a.acos_approx(), a.acos(), 1e-6);
370 // assert_approx_eq!(scalar_acos(a), a.acos(), 1e-6);
371 }
372
373 // test 1024 floats between -1.0 and 1.0 inclusive
374 const MAX_TESTS: u32 = 1024 / 2;
375 const SIGN: u32 = 0x80_00_00_00;
376 const PTVE_ONE: u32 = 0x3f_80_00_00; // 1.0_f32.to_bits();
377 const NGVE_ONE: u32 = SIGN | PTVE_ONE;
378 const STEP_SIZE: usize = (PTVE_ONE / MAX_TESTS) as usize;
379 for f in (SIGN..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#NGVE_ONE).step_by(STEP_SIZE).map(f32::from_bits) {
380 test_scalar_acos_angle(f);
381 }
382 for f in (0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#PTVE_ONE).step_by(STEP_SIZE).map(f32::from_bits) {
383 test_scalar_acos_angle(f);
384 }
385
386 // input is clamped to -1.0..1.0
387 assert_approx_eq!(2.0_f32.acos_approx(), 0.0);
388 assert_approx_eq!((-2.0_f32).acos_approx(), core::f32::consts::PI);
389
390 // input is clamped to -1.0..1.0
391 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(2.0_f64.acos_approx(), 0.0);
392 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(((-2.0_f64).acos_approx() - core::f64::consts::PI).abs() < f64::EPSILON);
393 }