Debian Codegraph @

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

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