Skip to main content

faer_traits/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![allow(non_camel_case_types)]
3use bytemuck::Pod;
4use core::fmt::Debug;
5use num_complex::Complex;
6use pulp::Simd;
7use qd::Quad;
8// taken from imply-hack (MIT license)
9pub mod imply {
10	pub trait Imply<T: ?Sized>: sealed::ImplyInner<T, Is = T> {}
11	impl<T: ?Sized, U: ?Sized> Imply<T> for U {}
12	mod sealed {
13		pub trait ImplyInner<T: ?Sized> {
14			type Is: ?Sized;
15		}
16		impl<T: ?Sized, U: ?Sized> ImplyInner<T> for U {
17			type Is = T;
18		}
19	}
20}
21use core::ops::*;
22use imply::Imply;
23use math_utils::*;
24pub mod math_utils {
25	use crate::{ByRef, ComplexField, RealField, abs_impl};
26	#[inline(always)]
27	#[must_use]
28	pub fn eps<T: RealField>() -> T {
29		T::Real::epsilon_impl()
30	}
31	#[inline(always)]
32	#[must_use]
33	pub fn nbits<T: ComplexField>() -> usize {
34		T::Real::nbits_impl()
35	}
36	#[inline(always)]
37	#[must_use]
38	pub fn min_positive<T: RealField>() -> T {
39		T::min_positive_impl()
40	}
41	#[inline(always)]
42	#[must_use]
43	pub fn max_positive<T: RealField>() -> T {
44		T::max_positive_impl()
45	}
46	#[inline(always)]
47	#[must_use]
48	pub fn sqrt_min_positive<T: RealField>() -> T {
49		T::sqrt_min_positive_impl()
50	}
51	#[inline(always)]
52	#[must_use]
53	pub fn sqrt_max_positive<T: RealField>() -> T {
54		T::sqrt_max_positive_impl()
55	}
56	#[inline(always)]
57	#[must_use]
58	pub fn zero<T: ComplexField>() -> T {
59		T::zero_impl()
60	}
61	#[inline(always)]
62	#[must_use]
63	pub fn one<T: ComplexField>() -> T {
64		T::one_impl()
65	}
66	#[inline(always)]
67	#[must_use]
68	pub fn nan<T: ComplexField>() -> T {
69		T::nan_impl()
70	}
71	#[inline(always)]
72	#[must_use]
73	pub fn infinity<T: ComplexField>() -> T {
74		T::infinity_impl()
75	}
76	#[inline(always)]
77	#[must_use]
78	pub fn as_real<T: ComplexField>(value: &T) -> T {
79		T::from_real_impl(&T::real_part_impl((value).by_ref()))
80	}
81	#[inline(always)]
82	#[must_use]
83	pub fn real<T: ComplexField>(value: &T) -> T::Real {
84		T::real_part_impl((value).by_ref())
85	}
86	#[inline(always)]
87	#[must_use]
88	pub fn imag<T: ComplexField>(value: &T) -> T::Real {
89		T::imag_part_impl((value).by_ref())
90	}
91	#[inline(always)]
92	#[track_caller]
93	#[must_use]
94	pub fn neg<T: NegByRef>(value: &T) -> T::Output {
95		value.neg_by_ref()
96	}
97	#[inline(always)]
98	#[must_use]
99	pub fn copy<T: ComplexField>(value: &T) -> T {
100		T::copy_impl((value).by_ref())
101	}
102	#[inline(always)]
103	#[must_use]
104	pub fn conj<T: ComplexField>(value: &T) -> T {
105		T::conj_impl((value).by_ref())
106	}
107	#[inline(always)]
108	#[track_caller]
109	#[must_use]
110	pub fn add<T: AddByRef<U>, U>(lhs: &T, rhs: &U) -> T::Output {
111		lhs.add_by_ref(rhs)
112	}
113	#[inline(always)]
114	#[track_caller]
115	#[must_use]
116	pub fn sub<T: SubByRef<U>, U>(lhs: &T, rhs: &U) -> T::Output {
117		lhs.sub_by_ref(rhs)
118	}
119	#[inline(always)]
120	#[track_caller]
121	#[must_use]
122	pub fn mul<T: MulByRef<U>, U>(lhs: &T, rhs: &U) -> T::Output {
123		lhs.mul_by_ref(rhs)
124	}
125	#[inline(always)]
126	#[track_caller]
127	#[must_use]
128	pub fn div<T: DivByRef<U>, U>(lhs: &T, rhs: &U) -> T::Output {
129		lhs.div_by_ref(rhs)
130	}
131	#[inline(always)]
132	#[must_use]
133	pub fn mul_real<T: ComplexField>(lhs: &T, rhs: &T::Real) -> T {
134		T::mul_real_impl((lhs).by_ref(), (rhs).by_ref())
135	}
136	#[inline(always)]
137	#[must_use]
138	pub fn mul_pow2<T: ComplexField>(lhs: &T, rhs: &T::Real) -> T {
139		T::mul_real_impl((lhs).by_ref(), (rhs).by_ref())
140	}
141	#[inline(always)]
142	#[must_use]
143	pub fn abs1<T: ComplexField>(value: &T) -> T::Real {
144		T::abs1_impl((value).by_ref())
145	}
146	#[inline(always)]
147	#[must_use]
148	pub fn absmax<T: ComplexField>(value: &T) -> T::Real {
149		if const { T::IS_REAL } {
150			T::abs1_impl(value)
151		} else {
152			&T::Real::abs1_impl(&real(value))
153				+ &T::Real::abs1_impl(&imag(value))
154		}
155	}
156	#[inline(always)]
157	#[must_use]
158	pub fn abs<T: ComplexField>(value: &T) -> T::Real {
159		T::abs_impl((value).by_ref())
160	}
161	#[inline(always)]
162	#[must_use]
163	pub fn hypot<T: RealField>(lhs: &T, rhs: &T) -> T {
164		abs_impl::<T::Real>(lhs.clone(), rhs.clone())
165	}
166	#[inline(always)]
167	#[must_use]
168	pub fn abs2<T: ComplexField>(value: &T) -> T::Real {
169		T::abs2_impl((value).by_ref())
170	}
171	#[inline(always)]
172	#[must_use]
173	pub fn max<T: RealField>(lhs: &T, rhs: &T) -> T {
174		if lhs > rhs { copy(lhs) } else { copy(rhs) }
175	}
176	#[inline(always)]
177	#[must_use]
178	pub fn min<T: RealField>(lhs: &T, rhs: &T) -> T {
179		if lhs < rhs { copy(lhs) } else { copy(rhs) }
180	}
181	#[inline(always)]
182	#[must_use]
183	pub fn is_nan<T: ComplexField>(value: &T) -> bool {
184		T::is_nan_impl((value).by_ref())
185	}
186	#[inline(always)]
187	#[must_use]
188	pub fn is_finite<T: ComplexField>(value: &T) -> bool {
189		T::is_finite_impl((value).by_ref())
190	}
191	#[inline(always)]
192	#[must_use]
193	pub fn sqrt<T: ComplexField>(value: &T) -> T {
194		T::sqrt_impl((value).by_ref())
195	}
196	#[inline(always)]
197	#[must_use]
198	pub fn recip<T: ComplexField>(value: &T) -> T {
199		T::recip_impl((value).by_ref())
200	}
201	#[inline(always)]
202	#[must_use]
203	pub fn from_real<T: ComplexField>(value: &T::Real) -> T {
204		T::from_real_impl((value).by_ref())
205	}
206	#[inline(always)]
207	#[must_use]
208	pub fn from_f64<T: ComplexField>(value: f64) -> T {
209		T::from_f64_impl(value)
210	}
211	pub use crate::{AddByRef, DivByRef, MulByRef, NegByRef, SubByRef};
212}
213macro_rules! impl_op {
214	({$(
215		impl$(<$T:ident: $bound:ident>)? $op:ident for $ty:ty {
216			fn $op_fn:ident($self:ident, $rhs:ident: Self) -> Self::Output $body:block
217		}
218	)*}) => {$(
219		impl$(<$T: $bound>)? $op for $ty {
220			type Output = $ty;
221			#[inline(always)]
222			fn $op_fn($self, $rhs: $ty) -> Self::Output $body
223		}
224		impl$(<$T: $bound>)? $op<&$ty> for $ty {
225			type Output = $ty;
226			#[inline(always)]
227			fn $op_fn($self, $rhs: &$ty) -> Self::Output $body
228		}
229		impl$(<$T: $bound>)? $op<$ty> for &$ty {
230			type Output = $ty;
231			#[inline(always)]
232			fn $op_fn($self, $rhs: $ty) -> Self::Output $body
233		}
234		impl$(<$T: $bound>)? $op<&$ty> for &$ty {
235			type Output = $ty;
236			#[inline(always)]
237			fn $op_fn($self, $rhs: &$ty) -> Self::Output $body
238		}
239	)*};
240}
241macro_rules! impl_assign_op {
242	({$(
243		impl$(<$T:ident: $bound:ident>)? $op:ident for $ty:ty {
244			fn $op_fn:ident(&mut $self:ident, $rhs:ident: Self) $body:block
245		}
246	)*}) => {$(
247		impl$(<$T: $bound>)? $op for $ty {
248			#[inline(always)]
249			fn $op_fn(&mut $self, $rhs: Self) $body
250		}
251		impl$(<$T: $bound>)? $op<&$ty> for $ty {
252			#[inline(always)]
253			fn $op_fn(&mut $self, $rhs: &$ty) $body
254		}
255	)*};
256}
257pub trait AddByRef<Rhs = Self> {
258	type Output;
259	fn add_by_ref(&self, rhs: &Rhs) -> Self::Output;
260}
261pub trait SubByRef<Rhs = Self> {
262	type Output;
263	fn sub_by_ref(&self, rhs: &Rhs) -> Self::Output;
264}
265pub trait NegByRef {
266	type Output;
267	fn neg_by_ref(&self) -> Self::Output;
268}
269pub trait MulByRef<Rhs = Self> {
270	type Output;
271	fn mul_by_ref(&self, rhs: &Rhs) -> Self::Output;
272}
273pub trait DivByRef<Rhs = Self> {
274	type Output;
275	fn div_by_ref(&self, rhs: &Rhs) -> Self::Output;
276}
277impl<Rhs, Lhs, Output> AddByRef<Rhs> for Lhs
278where
279	for<'a> &'a Lhs: core::ops::Add<&'a Rhs, Output = Output>,
280{
281	type Output = Output;
282
283	#[inline]
284	#[track_caller]
285	fn add_by_ref(&self, rhs: &Rhs) -> Self::Output {
286		self + rhs
287	}
288}
289impl<Rhs, Lhs, Output> SubByRef<Rhs> for Lhs
290where
291	for<'a> &'a Lhs: core::ops::Sub<&'a Rhs, Output = Output>,
292{
293	type Output = Output;
294
295	#[inline]
296	#[track_caller]
297	fn sub_by_ref(&self, rhs: &Rhs) -> Self::Output {
298		self - rhs
299	}
300}
301impl<Rhs, Lhs, Output> MulByRef<Rhs> for Lhs
302where
303	for<'a> &'a Lhs: core::ops::Mul<&'a Rhs, Output = Output>,
304{
305	type Output = Output;
306
307	#[inline]
308	#[track_caller]
309	fn mul_by_ref(&self, rhs: &Rhs) -> Self::Output {
310		self * rhs
311	}
312}
313impl<Rhs, Lhs, Output> DivByRef<Rhs> for Lhs
314where
315	for<'a> &'a Lhs: core::ops::Div<&'a Rhs, Output = Output>,
316{
317	type Output = Output;
318
319	#[inline]
320	#[track_caller]
321	fn div_by_ref(&self, rhs: &Rhs) -> Self::Output {
322		self / rhs
323	}
324}
325impl<T, Output> NegByRef for T
326where
327	for<'a> &'a T: core::ops::Neg<Output = Output>,
328{
329	type Output = Output;
330
331	#[inline]
332	#[track_caller]
333	fn neg_by_ref(&self) -> Self::Output {
334		-self
335	}
336}
337fn abs_impl<T: RealField>(re: T, im: T) -> T {
338	use ext::*;
339	let (re, im) = &(re, im);
340	let small = &sqrt_min_positive();
341	let big = &sqrt_max_positive();
342	let one = &one();
343	let re_abs = &re.abs();
344	let im_abs = &im.abs();
345	if re_abs > big || im_abs > big {
346		((re * small).abs2() + (im * small).abs2()).sqrt() * big
347	} else if re_abs > one || im_abs > one {
348		(re.abs2() + im.abs2()).sqrt()
349	} else {
350		((re * big).abs2() + (im * big).abs2()).sqrt() * small
351	}
352}
353fn recip_impl<T: RealField>(re: T, im: T) -> (T, T) {
354	use ext::*;
355	let (re, im) = &(re, im);
356	if is_nan(re) || is_nan(im) {
357		return (nan(), nan());
358	}
359	if *re == zero() && *im == zero() {
360		return (infinity(), infinity());
361	}
362	if !is_finite(re) || !is_finite(im) {
363		return (zero(), zero());
364	}
365	let small = &sqrt_min_positive();
366	let big = &sqrt_max_positive();
367	let one = &one();
368	let re_abs = &abs(re);
369	let im_abs = &abs(im);
370	if re_abs > big || im_abs > big {
371		let re = re * small;
372		let im = im * small;
373		let inv = &(re.abs2() + im.abs2()).recip();
374		(((re * inv) * small), ((-im * inv) * small))
375	} else if re_abs > one || im_abs > one {
376		let inv = &(re.abs2() + im.abs2()).recip();
377		((re * inv), (-im * inv))
378	} else {
379		let re = re * big;
380		let im = im * big;
381		let inv = &(re.abs2() + im.abs2()).recip();
382		(((re * inv) * big), ((-im * inv) * big))
383	}
384}
385fn sqrt_impl<T: RealField>(re: T, im: T) -> (T, T) {
386	use ext::*;
387	let im_negative = im < zero();
388	let half = &from_f64(0.5);
389	let abs = &abs_impl(re.clone(), im);
390	let zero = &zero::<T>();
391	let re = &re;
392	let mut sum = re + abs;
393	if &sum < zero {
394		sum = zero.copy();
395	}
396	let out_re = sum.mul_pow2(half).sqrt();
397	let mut out_im = (abs - re).mul_pow2(half).fmax(zero).sqrt();
398	if im_negative {
399		out_im = -out_im;
400	}
401	(out_re, out_im)
402}
403pub trait ByRef<T> {
404	fn by_ref(&self) -> &T;
405}
406impl<T> ByRef<T> for T {
407	#[inline]
408	fn by_ref(&self) -> &T {
409		self
410	}
411}
412impl<T> ByRef<T> for &T {
413	#[inline]
414	fn by_ref(&self) -> &T {
415		*self
416	}
417}
418#[repr(transparent)]
419pub struct SimdCtx<T: ComplexField, S: Simd>(pub T::SimdCtx<S>);
420impl<T: ComplexField, S: Simd> Copy for SimdCtx<T, S> {}
421impl<T: ComplexField, S: Simd> Clone for SimdCtx<T, S> {
422	#[inline]
423	fn clone(&self) -> Self {
424		*self
425	}
426}
427#[derive(Copy, Clone, Debug)]
428#[repr(transparent)]
429pub struct RealReg<T>(pub T);
430impl<T: ComplexField, S: Simd> SimdCtx<T, S> {
431	#[inline(always)]
432	pub fn new(ctx: &T::SimdCtx<S>) -> &Self {
433		unsafe { &*(ctx as *const T::SimdCtx<S> as *const Self) }
434	}
435
436	#[inline(always)]
437	pub fn zero(&self) -> T::SimdVec<S> {
438		unsafe { core::mem::zeroed() }
439	}
440
441	#[inline(always)]
442	pub fn splat(&self, value: impl ByRef<T>) -> T::SimdVec<S> {
443		unsafe {
444			core::mem::transmute_copy(&T::simd_splat(&self.0, value.by_ref()))
445		}
446	}
447
448	#[inline(always)]
449	pub fn splat_real(
450		&self,
451		value: impl ByRef<T::Real>,
452	) -> RealReg<T::SimdVec<S>> {
453		RealReg(unsafe {
454			core::mem::transmute_copy(&T::simd_splat_real(
455				&self.0,
456				value.by_ref(),
457			))
458		})
459	}
460
461	#[inline(always)]
462	pub fn add(&self, lhs: T::SimdVec<S>, rhs: T::SimdVec<S>) -> T::SimdVec<S> {
463		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
464		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
465		unsafe { core::mem::transmute_copy(&T::simd_add(&self.0, lhs, rhs)) }
466	}
467
468	#[inline(always)]
469	pub fn sub(&self, lhs: T::SimdVec<S>, rhs: T::SimdVec<S>) -> T::SimdVec<S> {
470		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
471		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
472		unsafe { core::mem::transmute_copy(&T::simd_sub(&self.0, lhs, rhs)) }
473	}
474
475	#[inline(always)]
476	pub fn neg(&self, value: T::SimdVec<S>) -> T::SimdVec<S> {
477		let value = unsafe { core::mem::transmute_copy(&value) };
478		unsafe { core::mem::transmute_copy(&T::simd_neg(&self.0, value)) }
479	}
480
481	#[inline(always)]
482	pub fn conj(&self, value: T::SimdVec<S>) -> T::SimdVec<S> {
483		let value = unsafe { core::mem::transmute_copy(&value) };
484		unsafe { core::mem::transmute_copy(&T::simd_conj(&self.0, value)) }
485	}
486
487	#[inline(always)]
488	pub fn abs1(&self, value: T::SimdVec<S>) -> RealReg<T::SimdVec<S>> {
489		let value = unsafe { core::mem::transmute_copy(&value) };
490		RealReg(unsafe {
491			core::mem::transmute_copy(&T::simd_abs1(&self.0, value))
492		})
493	}
494
495	#[inline(always)]
496	pub fn abs_max(&self, value: T::SimdVec<S>) -> RealReg<T::SimdVec<S>> {
497		let value = unsafe { core::mem::transmute_copy(&value) };
498		RealReg(unsafe {
499			core::mem::transmute_copy(&T::simd_abs_max(&self.0, value))
500		})
501	}
502
503	#[inline(always)]
504	pub fn mul_real(
505		&self,
506		lhs: T::SimdVec<S>,
507		rhs: RealReg<T::SimdVec<S>>,
508	) -> T::SimdVec<S> {
509		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
510		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
511		unsafe {
512			core::mem::transmute_copy(&T::simd_mul_real(&self.0, lhs, rhs))
513		}
514	}
515
516	#[inline(always)]
517	pub fn mul_pow2(
518		&self,
519		lhs: T::SimdVec<S>,
520		rhs: RealReg<T::SimdVec<S>>,
521	) -> T::SimdVec<S> {
522		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
523		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
524		unsafe {
525			core::mem::transmute_copy(&T::simd_mul_pow2(&self.0, lhs, rhs))
526		}
527	}
528
529	#[inline(always)]
530	pub fn mul(&self, lhs: T::SimdVec<S>, rhs: T::SimdVec<S>) -> T::SimdVec<S> {
531		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
532		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
533		unsafe { core::mem::transmute_copy(&T::simd_mul(&self.0, lhs, rhs)) }
534	}
535
536	#[inline(always)]
537	pub fn conj_mul(
538		&self,
539		lhs: T::SimdVec<S>,
540		rhs: T::SimdVec<S>,
541	) -> T::SimdVec<S> {
542		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
543		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
544		unsafe {
545			core::mem::transmute_copy(&T::simd_conj_mul(&self.0, lhs, rhs))
546		}
547	}
548
549	#[inline(always)]
550	pub fn mul_add(
551		&self,
552		lhs: T::SimdVec<S>,
553		rhs: T::SimdVec<S>,
554		acc: T::SimdVec<S>,
555	) -> T::SimdVec<S> {
556		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
557		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
558		let acc = unsafe { core::mem::transmute_copy(&acc) };
559		unsafe {
560			core::mem::transmute_copy(&T::simd_mul_add(&self.0, lhs, rhs, acc))
561		}
562	}
563
564	#[inline(always)]
565	pub fn conj_mul_add(
566		&self,
567		lhs: T::SimdVec<S>,
568		rhs: T::SimdVec<S>,
569		acc: T::SimdVec<S>,
570	) -> T::SimdVec<S> {
571		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
572		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
573		let acc = unsafe { core::mem::transmute_copy(&acc) };
574		unsafe {
575			core::mem::transmute_copy(&T::simd_conj_mul_add(
576				&self.0, lhs, rhs, acc,
577			))
578		}
579	}
580
581	#[inline(always)]
582	pub fn maybe_conj_mul_add<const CONJ: bool>(
583		&self,
584		lhs: T::SimdVec<S>,
585		rhs: T::SimdVec<S>,
586		acc: T::SimdVec<S>,
587	) -> T::SimdVec<S> {
588		if const { CONJ } {
589			self.conj_mul_add(lhs, rhs, acc)
590		} else {
591			self.mul_add(lhs, rhs, acc)
592		}
593	}
594
595	#[inline(always)]
596	pub fn abs2(&self, value: T::SimdVec<S>) -> RealReg<T::SimdVec<S>> {
597		let value = unsafe { core::mem::transmute_copy(&value) };
598		RealReg(unsafe {
599			core::mem::transmute_copy(&T::simd_abs2(&self.0, value))
600		})
601	}
602
603	#[inline(always)]
604	pub fn abs2_add(
605		&self,
606		value: T::SimdVec<S>,
607		acc: RealReg<T::SimdVec<S>>,
608	) -> RealReg<T::SimdVec<S>> {
609		let value = unsafe { core::mem::transmute_copy(&value) };
610		let acc = unsafe { core::mem::transmute_copy(&acc) };
611		RealReg(unsafe {
612			core::mem::transmute_copy(&T::simd_abs2_add(&self.0, value, acc))
613		})
614	}
615
616	#[inline(always)]
617	pub fn reduce_sum(&self, value: T::SimdVec<S>) -> T {
618		let value = unsafe { core::mem::transmute_copy(&value) };
619		unsafe {
620			core::mem::transmute_copy(&T::simd_reduce_sum(&self.0, value))
621		}
622	}
623
624	#[inline(always)]
625	pub fn reduce_max(&self, value: RealReg<T::SimdVec<S>>) -> T {
626		let value = unsafe { core::mem::transmute_copy(&value) };
627		unsafe {
628			core::mem::transmute_copy(&T::simd_reduce_max(&self.0, value))
629		}
630	}
631
632	#[inline(always)]
633	pub fn reduce_sum_real(&self, value: RealReg<T::SimdVec<S>>) -> Real<T> {
634		let value = T::simd_reduce_sum(&self.0, value.0);
635		if const { T::SIMD_ABS_SPLIT_REAL_IMAG && !S::IS_SCALAR } {
636			let r = real(&value);
637			let i = imag(&value);
638			&r + &i
639		} else {
640			real(&value)
641		}
642	}
643
644	#[inline(always)]
645	pub fn reduce_max_real(&self, value: RealReg<T::SimdVec<S>>) -> Real<T> {
646		use crate::ext::*;
647		let value = T::simd_reduce_max(&self.0, value.0);
648		if const { T::SIMD_ABS_SPLIT_REAL_IMAG && !S::IS_SCALAR } {
649			value.real().fmax(value.imag())
650		} else {
651			value.real()
652		}
653	}
654
655	#[inline(always)]
656	pub fn max(
657		&self,
658		lhs: RealReg<T::SimdVec<S>>,
659		rhs: RealReg<T::SimdVec<S>>,
660	) -> RealReg<T::SimdVec<S>> {
661		let cmp = self.gt(lhs, rhs);
662		RealReg(self.select(cmp, lhs.0, rhs.0))
663	}
664
665	#[inline(always)]
666	pub fn eq(&self, lhs: T::SimdVec<S>, rhs: T::SimdVec<S>) -> T::SimdMask<S> {
667		T::simd_equal(&self.0, lhs, rhs)
668	}
669
670	#[inline(always)]
671	pub fn lt(
672		&self,
673		lhs: RealReg<T::SimdVec<S>>,
674		rhs: RealReg<T::SimdVec<S>>,
675	) -> T::SimdMask<S> {
676		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
677		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
678		unsafe {
679			core::mem::transmute_copy(&T::simd_less_than(&self.0, lhs, rhs))
680		}
681	}
682
683	#[inline(always)]
684	pub fn gt(
685		&self,
686		lhs: RealReg<T::SimdVec<S>>,
687		rhs: RealReg<T::SimdVec<S>>,
688	) -> T::SimdMask<S> {
689		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
690		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
691		unsafe {
692			core::mem::transmute_copy(&T::simd_greater_than(&self.0, lhs, rhs))
693		}
694	}
695
696	#[inline(always)]
697	pub fn le(
698		&self,
699		lhs: RealReg<T::SimdVec<S>>,
700		rhs: RealReg<T::SimdVec<S>>,
701	) -> T::SimdMask<S> {
702		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
703		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
704		unsafe {
705			core::mem::transmute_copy(&T::simd_less_than_or_equal(
706				&self.0, lhs, rhs,
707			))
708		}
709	}
710
711	#[inline(always)]
712	pub fn ge(
713		&self,
714		lhs: RealReg<T::SimdVec<S>>,
715		rhs: RealReg<T::SimdVec<S>>,
716	) -> T::SimdMask<S> {
717		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
718		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
719		unsafe {
720			core::mem::transmute_copy(&T::simd_greater_than_or_equal(
721				&self.0, lhs, rhs,
722			))
723		}
724	}
725
726	#[inline(always)]
727	pub fn select(
728		&self,
729		mask: T::SimdMask<S>,
730		lhs: T::SimdVec<S>,
731		rhs: T::SimdVec<S>,
732	) -> T::SimdVec<S> {
733		let lhs = unsafe { core::mem::transmute_copy(&lhs) };
734		let rhs = unsafe { core::mem::transmute_copy(&rhs) };
735		unsafe {
736			core::mem::transmute_copy(&T::simd_select(&self.0, mask, lhs, rhs))
737		}
738	}
739
740	#[inline(always)]
741	pub fn iselect(
742		&self,
743		mask: T::SimdMask<S>,
744		lhs: T::SimdIndex<S>,
745		rhs: T::SimdIndex<S>,
746	) -> T::SimdIndex<S> {
747		unsafe {
748			core::mem::transmute_copy(&T::simd_index_select(
749				&self.0, mask, lhs, rhs,
750			))
751		}
752	}
753
754	#[inline(always)]
755	pub fn isplat(&self, value: T::Index) -> T::SimdIndex<S> {
756		unsafe {
757			core::mem::transmute_copy(&T::simd_index_splat(&self.0, value))
758		}
759	}
760
761	#[inline(always)]
762	pub fn izero(&self) -> T::SimdIndex<S> {
763		unsafe { core::mem::zeroed() }
764	}
765
766	#[inline(always)]
767	pub fn iadd(
768		&self,
769		lhs: T::SimdIndex<S>,
770		rhs: T::SimdIndex<S>,
771	) -> T::SimdIndex<S> {
772		unsafe {
773			core::mem::transmute_copy(&T::simd_index_add(&self.0, lhs, rhs))
774		}
775	}
776
777	#[inline(always)]
778	pub fn or_mask(
779		&self,
780		lhs: T::SimdMask<S>,
781		rhs: T::SimdMask<S>,
782	) -> T::SimdMask<S> {
783		T::simd_or_mask(&self.0, lhs, rhs)
784	}
785
786	#[inline(always)]
787	pub fn and_mask(
788		&self,
789		lhs: T::SimdMask<S>,
790		rhs: T::SimdMask<S>,
791	) -> T::SimdMask<S> {
792		T::simd_and_mask(&self.0, lhs, rhs)
793	}
794
795	#[inline(always)]
796	pub fn not_mask(&self, mask: T::SimdMask<S>) -> T::SimdMask<S> {
797		T::simd_not_mask(&self.0, mask)
798	}
799
800	#[inline(always)]
801	pub fn first_true_mask(&self, value: T::SimdMask<S>) -> usize {
802		T::simd_first_true_mask(&self.0, value)
803	}
804
805	#[inline(always)]
806	pub unsafe fn mask_load(
807		&self,
808		mask: T::SimdMemMask<S>,
809		ptr: *const T::SimdVec<S>,
810	) -> T::SimdVec<S> {
811		unsafe { T::simd_mask_load(&self.0, mask, ptr) }
812	}
813
814	#[inline(always)]
815	pub unsafe fn mask_store(
816		&self,
817		mask: T::SimdMemMask<S>,
818		ptr: *mut T::SimdVec<S>,
819		value: T::SimdVec<S>,
820	) {
821		let value = unsafe { core::mem::transmute_copy(&value) };
822		unsafe { T::simd_mask_store(&self.0, mask, ptr, value) }
823	}
824
825	#[inline(always)]
826	pub fn load(&self, ptr: &T::SimdVec<S>) -> T::SimdVec<S> {
827		unsafe { core::mem::transmute_copy(&T::simd_load(&self.0, ptr)) }
828	}
829
830	#[inline(always)]
831	pub fn store(&self, ptr: &mut T::SimdVec<S>, value: T::SimdVec<S>) {
832		let value = unsafe { core::mem::transmute_copy(&value) };
833		unsafe {
834			core::mem::transmute_copy(&T::simd_store(&self.0, ptr, value))
835		}
836	}
837}
838pub unsafe trait Conjugate:
839	Send + Sync + core::fmt::Debug + Imply<Self::Canonical, Is: RefOps>
840{
841	const IS_CANONICAL: bool;
842	type Conj: Conjugate<Conj = Self, Canonical = Self::Canonical>;
843	type Canonical: Conjugate<Canonical = Self::Canonical> + ComplexField;
844}
845pub type Real<T> = <<T as Conjugate>::Canonical as ComplexField>::Real;
846#[derive(Copy, Clone, Debug, PartialEq, Eq)]
847pub struct ComplexConj<T> {
848	pub re: T,
849	pub im_neg: T,
850}
851#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
852pub enum SimdCapabilities {
853	None,
854	Copy,
855	Simd,
856}
857impl SimdCapabilities {
858	#[inline]
859	pub const fn is_copy(self) -> bool {
860		matches!(self, Self::Copy | Self::Simd)
861	}
862
863	#[inline]
864	pub const fn is_simd(self) -> bool {
865		matches!(self, Self::Simd)
866	}
867}
868mod seal {
869	pub trait Seal {}
870	impl Seal for u8 {}
871	impl Seal for u16 {}
872	impl Seal for u32 {}
873	impl Seal for u64 {}
874	impl Seal for u128 {}
875	impl Seal for usize {}
876	impl Seal for i32 {}
877	impl Seal for i64 {}
878	impl Seal for isize {}
879}
880pub trait Seal: seal::Seal {}
881impl<T: seal::Seal> Seal for T {}
882/// Trait for signed integers corresponding to the ones satisfying [`Index`].
883///
884/// Always smaller than or equal to `isize`.
885pub trait SignedIndex:
886	Seal
887	+ core::fmt::Debug
888	+ core::ops::Neg<Output = Self>
889	+ core::ops::Add<Output = Self>
890	+ core::ops::Sub<Output = Self>
891	+ core::ops::AddAssign
892	+ core::ops::SubAssign
893	+ bytemuck::Pod
894	+ Eq
895	+ Ord
896	+ Send
897	+ Sync
898{
899	/// Maximum representable value.
900	const MAX: Self;
901	/// Truncate `value` to type [`Self`].
902	#[must_use]
903	fn truncate(value: usize) -> Self;
904	/// Zero extend `self`.
905	#[must_use]
906	fn zx(self) -> usize;
907	/// Sign extend `self`.
908	#[must_use]
909	fn sx(self) -> usize;
910	/// Sum nonnegative values while checking for overflow.
911	fn sum_nonnegative(slice: &[Self]) -> Option<Self> {
912		let mut acc = Self::zeroed();
913		for &i in slice {
914			if Self::MAX - i < acc {
915				return None;
916			}
917			acc += i;
918		}
919		Some(acc)
920	}
921}
922impl SignedIndex for i32 {
923	const MAX: Self = Self::MAX;
924
925	#[inline(always)]
926	fn truncate(value: usize) -> Self {
927		value as isize as Self
928	}
929
930	#[inline(always)]
931	fn zx(self) -> usize {
932		self as u32 as usize
933	}
934
935	#[inline(always)]
936	fn sx(self) -> usize {
937		self as isize as usize
938	}
939}
940impl SignedIndex for i64 {
941	const MAX: Self = Self::MAX;
942
943	#[inline(always)]
944	fn truncate(value: usize) -> Self {
945		value as isize as Self
946	}
947
948	#[inline(always)]
949	fn zx(self) -> usize {
950		self as u64 as usize
951	}
952
953	#[inline(always)]
954	fn sx(self) -> usize {
955		self as isize as usize
956	}
957}
958impl SignedIndex for isize {
959	const MAX: Self = Self::MAX;
960
961	#[inline(always)]
962	fn truncate(value: usize) -> Self {
963		value as isize
964	}
965
966	#[inline(always)]
967	fn zx(self) -> usize {
968		self as usize
969	}
970
971	#[inline(always)]
972	fn sx(self) -> usize {
973		self as usize
974	}
975}
976pub trait IndexCore:
977	Seal
978	+ core::fmt::Debug
979	+ core::ops::Not<Output = Self>
980	+ core::ops::BitAnd<Output = Self>
981	+ core::ops::BitOr<Output = Self>
982	+ core::ops::BitXor<Output = Self>
983	+ core::ops::Add<Output = Self>
984	+ core::ops::Sub<Output = Self>
985	+ core::ops::AddAssign
986	+ core::ops::SubAssign
987	+ bytemuck::Pod
988	+ Eq
989	+ Ord
990	+ Send
991	+ Sync
992	+ Ord
993{
994	const MAX: Self;
995	/// Truncate `value` to type [`Self`].
996	#[must_use]
997	fn truncate(value: usize) -> Self;
998	/// Zero extend `self`.
999	#[must_use]
1000	fn zx(self) -> usize;
1001}
1002pub trait Index: IndexCore {
1003	/// Equally-sized index type with a fixed size (no `usize`).
1004	type FixedWidth: Index;
1005	/// Equally-sized signed index type.
1006	type Signed: SignedIndex;
1007	const BITS: u32 = core::mem::size_of::<Self>() as u32 * 8;
1008	/// Convert a reference to a slice of [`Self`] to fixed width types.
1009	#[inline(always)]
1010	fn canonicalize(slice: &[Self]) -> &[Self::FixedWidth] {
1011		bytemuck::cast_slice(slice)
1012	}
1013	/// Convert a mutable reference to a slice of [`Self`] to fixed width types.
1014	#[inline(always)]
1015	fn canonicalize_mut(slice: &mut [Self]) -> &mut [Self::FixedWidth] {
1016		bytemuck::cast_slice_mut(slice)
1017	}
1018	/// Convert a signed value to an unsigned one.
1019	#[inline(always)]
1020	fn from_signed(value: Self::Signed) -> Self {
1021		bytemuck::cast(value)
1022	}
1023	/// Convert an unsigned value to a signed one.
1024	#[inline(always)]
1025	fn to_signed(self) -> Self::Signed {
1026		bytemuck::cast(self)
1027	}
1028	/// Sum values while checking for overflow.
1029	#[inline]
1030	fn sum_nonnegative(slice: &[Self]) -> Option<Self> {
1031		Self::Signed::sum_nonnegative(bytemuck::cast_slice(slice))
1032			.map(Self::from_signed)
1033	}
1034}
1035impl IndexCore for u8 {
1036	const MAX: Self = Self::MAX;
1037
1038	#[inline(always)]
1039	fn truncate(value: usize) -> Self {
1040		value as _
1041	}
1042
1043	#[inline(always)]
1044	fn zx(self) -> usize {
1045		self as _
1046	}
1047}
1048impl IndexCore for u16 {
1049	const MAX: Self = Self::MAX;
1050
1051	#[inline(always)]
1052	fn truncate(value: usize) -> Self {
1053		value as _
1054	}
1055
1056	#[inline(always)]
1057	fn zx(self) -> usize {
1058		self as _
1059	}
1060}
1061impl IndexCore for u32 {
1062	const MAX: Self = Self::MAX;
1063
1064	#[inline(always)]
1065	fn truncate(value: usize) -> Self {
1066		value as _
1067	}
1068
1069	#[inline(always)]
1070	fn zx(self) -> usize {
1071		self as _
1072	}
1073}
1074impl IndexCore for u64 {
1075	const MAX: Self = Self::MAX;
1076
1077	#[inline(always)]
1078	fn truncate(value: usize) -> Self {
1079		value as _
1080	}
1081
1082	#[inline(always)]
1083	fn zx(self) -> usize {
1084		self as _
1085	}
1086}
1087impl IndexCore for u128 {
1088	const MAX: Self = Self::MAX;
1089
1090	#[inline(always)]
1091	fn truncate(value: usize) -> Self {
1092		value as _
1093	}
1094
1095	#[inline(always)]
1096	fn zx(self) -> usize {
1097		self as _
1098	}
1099}
1100impl IndexCore for usize {
1101	const MAX: Self = Self::MAX;
1102
1103	#[inline(always)]
1104	fn truncate(value: usize) -> Self {
1105		value
1106	}
1107
1108	#[inline(always)]
1109	fn zx(self) -> usize {
1110		self
1111	}
1112}
1113impl Index for u32 {
1114	type FixedWidth = u32;
1115	type Signed = i32;
1116}
1117impl Index for u64 {
1118	type FixedWidth = u64;
1119	type Signed = i64;
1120}
1121impl Index for usize {
1122	#[cfg(target_pointer_width = "32")]
1123	type FixedWidth = u32;
1124	#[cfg(target_pointer_width = "64")]
1125	type FixedWidth = u64;
1126	type Signed = isize;
1127}
1128unsafe impl<T: RealField> Conjugate for T {
1129	type Canonical = T;
1130	type Conj = T;
1131
1132	const IS_CANONICAL: bool = true;
1133}
1134unsafe impl<T: RealField> Conjugate for Complex<T> {
1135	type Canonical = Complex<T>;
1136	type Conj = ComplexConj<T>;
1137
1138	const IS_CANONICAL: bool = true;
1139}
1140unsafe impl<T: RealField> Conjugate for ComplexConj<T> {
1141	type Canonical = Complex<T>;
1142	type Conj = Complex<T>;
1143
1144	const IS_CANONICAL: bool = false;
1145}
1146pub trait SimdArch: Copy + Default + Send + Sync {
1147	fn dispatch<R>(self, f: impl pulp::WithSimd<Output = R>) -> R;
1148}
1149impl SimdArch for pulp::Arch {
1150	#[inline]
1151	fn dispatch<R>(self, f: impl pulp::WithSimd<Output = R>) -> R {
1152		self.dispatch(f)
1153	}
1154}
1155impl SimdArch for pulp::Scalar {
1156	#[inline]
1157	fn dispatch<R>(self, f: impl pulp::WithSimd<Output = R>) -> R {
1158		f.with_simd(self)
1159	}
1160}
1161pub trait RefOps:
1162	Sized
1163	+ core::ops::Neg<Output = Self>
1164	+ core::ops::Add<Output = Self>
1165	+ core::ops::Sub<Output = Self>
1166	+ core::ops::Mul<Output = Self>
1167	+ core::ops::Div<Output = Self>
1168	+ core::ops::AddAssign
1169	+ core::ops::SubAssign
1170	+ core::ops::MulAssign
1171	+ core::ops::DivAssign
1172	+ for<'a> core::ops::Add<&'a Self, Output = Self>
1173	+ for<'a> core::ops::Sub<&'a Self, Output = Self>
1174	+ for<'a> core::ops::Mul<&'a Self, Output = Self>
1175	+ for<'a> core::ops::Div<&'a Self, Output = Self>
1176	+ for<'a> core::ops::AddAssign<&'a Self>
1177	+ for<'a> core::ops::SubAssign<&'a Self>
1178	+ for<'a> core::ops::MulAssign<&'a Self>
1179	+ for<'a> core::ops::DivAssign<&'a Self>
1180	+ for<'a> Imply<
1181		&'a Self,
1182		Is: core::ops::Neg<Output = Self>
1183		        + core::ops::Add<Output = Self>
1184		        + core::ops::Sub<Output = Self>
1185		        + core::ops::Mul<Output = Self>
1186		        + core::ops::Div<Output = Self>
1187		        + core::ops::Add<Self, Output = Self>
1188		        + core::ops::Sub<Self, Output = Self>
1189		        + core::ops::Mul<Self, Output = Self>
1190		        + core::ops::Div<Self, Output = Self>,
1191	>
1192{
1193}
1194impl<T> RefOps for T
1195where
1196	T: core::ops::Neg<Output = Self>
1197		+ core::ops::Add<Output = Self>
1198		+ core::ops::Sub<Output = Self>
1199		+ core::ops::Mul<Output = Self>
1200		+ core::ops::Div<Output = Self>
1201		+ core::ops::AddAssign
1202		+ core::ops::SubAssign
1203		+ core::ops::MulAssign
1204		+ core::ops::DivAssign
1205		+ for<'a> core::ops::Add<&'a T, Output = Self>
1206		+ for<'a> core::ops::Sub<&'a T, Output = Self>
1207		+ for<'a> core::ops::Mul<&'a T, Output = Self>
1208		+ for<'a> core::ops::Div<&'a T, Output = Self>
1209		+ for<'a> core::ops::AddAssign<&'a T>
1210		+ for<'a> core::ops::SubAssign<&'a T>
1211		+ for<'a> core::ops::MulAssign<&'a T>
1212		+ for<'a> core::ops::DivAssign<&'a T>,
1213	for<'a> &'a T: core::ops::Neg<Output = T>
1214		+ core::ops::Add<Output = T>
1215		+ core::ops::Sub<Output = T>
1216		+ core::ops::Mul<Output = T>
1217		+ core::ops::Div<Output = T>
1218		+ core::ops::Add<T, Output = T>
1219		+ core::ops::Sub<T, Output = T>
1220		+ core::ops::Mul<T, Output = T>
1221		+ core::ops::Div<T, Output = T>,
1222{
1223}
1224pub trait ComplexField:
1225	Debug
1226	+ Clone
1227	+ Conjugate<Canonical = Self>
1228	+ PartialEq
1229	+ RefOps
1230	+ Imply<Self::Real, Is: RefOps>
1231{
1232	const IS_REAL: bool;
1233	const SIMD_ABS_SPLIT_REAL_IMAG: bool = false;
1234	type Arch: SimdArch;
1235	type Unit: ComplexField;
1236	type SimdCtx<S: Simd>: Copy;
1237	type Index: IndexCore;
1238	type Real: RealField;
1239	#[doc(hidden)]
1240	const IS_NATIVE_F32: bool = false;
1241	#[doc(hidden)]
1242	const IS_NATIVE_C32: bool = false;
1243	#[doc(hidden)]
1244	const IS_NATIVE_F64: bool = false;
1245	#[doc(hidden)]
1246	const IS_NATIVE_C64: bool = false;
1247	const SIMD_CAPABILITIES: SimdCapabilities;
1248	type SimdMask<S: Simd>: Copy + Debug;
1249	type SimdMemMask<S: Simd>: Copy + Debug;
1250	type SimdVec<S: Simd>: Pod + Debug;
1251	type SimdIndex<S: Simd>: Pod + Debug;
1252	fn zero_impl() -> Self;
1253	fn one_impl() -> Self;
1254	fn nan_impl() -> Self;
1255	fn infinity_impl() -> Self;
1256	fn from_real_impl(real: &Self::Real) -> Self;
1257	fn from_f64_impl(real: f64) -> Self;
1258	fn real_part_impl(value: &Self) -> Self::Real;
1259	fn imag_part_impl(value: &Self) -> Self::Real;
1260	fn copy_impl(value: &Self) -> Self;
1261	fn conj_impl(value: &Self) -> Self;
1262	fn recip_impl(value: &Self) -> Self;
1263	fn sqrt_impl(value: &Self) -> Self;
1264	fn abs_impl(value: &Self) -> Self::Real;
1265	fn abs1_impl(value: &Self) -> Self::Real;
1266	fn abs2_impl(value: &Self) -> Self::Real;
1267	fn mul_real_impl(lhs: &Self, rhs: &Self::Real) -> Self;
1268	fn mul_pow2_impl(lhs: &Self, rhs: &Self::Real) -> Self;
1269	fn is_finite_impl(value: &Self) -> bool;
1270	// NaN is the only value that compares unequal to itself.
1271	#[allow(clippy::eq_op)]
1272	fn is_nan_impl(value: &Self) -> bool {
1273		value != value
1274	}
1275	fn simd_ctx<S: Simd>(simd: S) -> Self::SimdCtx<S>;
1276	fn ctx_from_simd<S: Simd>(ctx: &Self::SimdCtx<S>) -> S;
1277	fn simd_mask_between<S: Simd>(
1278		ctx: &Self::SimdCtx<S>,
1279		start: Self::Index,
1280		end: Self::Index,
1281	) -> Self::SimdMask<S>;
1282	fn simd_mem_mask_between<S: Simd>(
1283		ctx: &Self::SimdCtx<S>,
1284		start: Self::Index,
1285		end: Self::Index,
1286	) -> Self::SimdMemMask<S>;
1287	unsafe fn simd_mask_load_raw<S: Simd>(
1288		ctx: &Self::SimdCtx<S>,
1289		mask: Self::SimdMemMask<S>,
1290		ptr: *const Self::SimdVec<S>,
1291	) -> Self::SimdVec<S>;
1292	unsafe fn simd_mask_store_raw<S: Simd>(
1293		ctx: &Self::SimdCtx<S>,
1294		mask: Self::SimdMemMask<S>,
1295		ptr: *mut Self::SimdVec<S>,
1296		values: Self::SimdVec<S>,
1297	);
1298	fn simd_splat<S: Simd>(
1299		ctx: &Self::SimdCtx<S>,
1300		value: &Self,
1301	) -> Self::SimdVec<S>;
1302	fn simd_splat_real<S: Simd>(
1303		ctx: &Self::SimdCtx<S>,
1304		value: &Self::Real,
1305	) -> Self::SimdVec<S>;
1306	fn simd_add<S: Simd>(
1307		ctx: &Self::SimdCtx<S>,
1308		lhs: Self::SimdVec<S>,
1309		rhs: Self::SimdVec<S>,
1310	) -> Self::SimdVec<S>;
1311	fn simd_sub<S: Simd>(
1312		ctx: &Self::SimdCtx<S>,
1313		lhs: Self::SimdVec<S>,
1314		rhs: Self::SimdVec<S>,
1315	) -> Self::SimdVec<S>;
1316	fn simd_neg<S: Simd>(
1317		ctx: &Self::SimdCtx<S>,
1318		value: Self::SimdVec<S>,
1319	) -> Self::SimdVec<S>;
1320	fn simd_conj<S: Simd>(
1321		ctx: &Self::SimdCtx<S>,
1322		value: Self::SimdVec<S>,
1323	) -> Self::SimdVec<S>;
1324	fn simd_abs1<S: Simd>(
1325		ctx: &Self::SimdCtx<S>,
1326		value: Self::SimdVec<S>,
1327	) -> Self::SimdVec<S>;
1328	fn simd_abs_max<S: Simd>(
1329		ctx: &Self::SimdCtx<S>,
1330		value: Self::SimdVec<S>,
1331	) -> Self::SimdVec<S>;
1332	fn simd_mul_real<S: Simd>(
1333		ctx: &Self::SimdCtx<S>,
1334		lhs: Self::SimdVec<S>,
1335		real_rhs: Self::SimdVec<S>,
1336	) -> Self::SimdVec<S>;
1337	fn simd_mul_pow2<S: Simd>(
1338		ctx: &Self::SimdCtx<S>,
1339		lhs: Self::SimdVec<S>,
1340		real_rhs: Self::SimdVec<S>,
1341	) -> Self::SimdVec<S>;
1342	fn simd_mul<S: Simd>(
1343		ctx: &Self::SimdCtx<S>,
1344		lhs: Self::SimdVec<S>,
1345		rhs: Self::SimdVec<S>,
1346	) -> Self::SimdVec<S>;
1347	fn simd_conj_mul<S: Simd>(
1348		ctx: &Self::SimdCtx<S>,
1349		lhs: Self::SimdVec<S>,
1350		rhs: Self::SimdVec<S>,
1351	) -> Self::SimdVec<S>;
1352	fn simd_mul_add<S: Simd>(
1353		ctx: &Self::SimdCtx<S>,
1354		lhs: Self::SimdVec<S>,
1355		rhs: Self::SimdVec<S>,
1356		acc: Self::SimdVec<S>,
1357	) -> Self::SimdVec<S>;
1358	fn simd_conj_mul_add<S: Simd>(
1359		ctx: &Self::SimdCtx<S>,
1360		lhs: Self::SimdVec<S>,
1361		rhs: Self::SimdVec<S>,
1362		acc: Self::SimdVec<S>,
1363	) -> Self::SimdVec<S>;
1364	fn simd_abs2<S: Simd>(
1365		ctx: &Self::SimdCtx<S>,
1366		value: Self::SimdVec<S>,
1367	) -> Self::SimdVec<S>;
1368	fn simd_abs2_add<S: Simd>(
1369		ctx: &Self::SimdCtx<S>,
1370		value: Self::SimdVec<S>,
1371		acc: Self::SimdVec<S>,
1372	) -> Self::SimdVec<S>;
1373	fn simd_reduce_sum<S: Simd>(
1374		ctx: &Self::SimdCtx<S>,
1375		value: Self::SimdVec<S>,
1376	) -> Self;
1377	fn simd_reduce_max<S: Simd>(
1378		ctx: &Self::SimdCtx<S>,
1379		value: Self::SimdVec<S>,
1380	) -> Self;
1381	fn simd_equal<S: Simd>(
1382		ctx: &Self::SimdCtx<S>,
1383		real_lhs: Self::SimdVec<S>,
1384		real_rhs: Self::SimdVec<S>,
1385	) -> Self::SimdMask<S>;
1386	fn simd_less_than<S: Simd>(
1387		ctx: &Self::SimdCtx<S>,
1388		real_lhs: Self::SimdVec<S>,
1389		real_rhs: Self::SimdVec<S>,
1390	) -> Self::SimdMask<S>;
1391	fn simd_less_than_or_equal<S: Simd>(
1392		ctx: &Self::SimdCtx<S>,
1393		real_lhs: Self::SimdVec<S>,
1394		real_rhs: Self::SimdVec<S>,
1395	) -> Self::SimdMask<S>;
1396	fn simd_greater_than<S: Simd>(
1397		ctx: &Self::SimdCtx<S>,
1398		real_lhs: Self::SimdVec<S>,
1399		real_rhs: Self::SimdVec<S>,
1400	) -> Self::SimdMask<S>;
1401	fn simd_greater_than_or_equal<S: Simd>(
1402		ctx: &Self::SimdCtx<S>,
1403		real_lhs: Self::SimdVec<S>,
1404		real_rhs: Self::SimdVec<S>,
1405	) -> Self::SimdMask<S>;
1406	fn simd_select<S: Simd>(
1407		ctx: &Self::SimdCtx<S>,
1408		mask: Self::SimdMask<S>,
1409		lhs: Self::SimdVec<S>,
1410		rhs: Self::SimdVec<S>,
1411	) -> Self::SimdVec<S>;
1412	fn simd_index_select<S: Simd>(
1413		ctx: &Self::SimdCtx<S>,
1414		mask: Self::SimdMask<S>,
1415		lhs: Self::SimdIndex<S>,
1416		rhs: Self::SimdIndex<S>,
1417	) -> Self::SimdIndex<S>;
1418	fn simd_index_splat<S: Simd>(
1419		ctx: &Self::SimdCtx<S>,
1420		value: Self::Index,
1421	) -> Self::SimdIndex<S>;
1422	fn simd_index_add<S: Simd>(
1423		ctx: &Self::SimdCtx<S>,
1424		lhs: Self::SimdIndex<S>,
1425		rhs: Self::SimdIndex<S>,
1426	) -> Self::SimdIndex<S>;
1427	fn simd_index_less_than<S: Simd>(
1428		ctx: &Self::SimdCtx<S>,
1429		lhs: Self::SimdIndex<S>,
1430		rhs: Self::SimdIndex<S>,
1431	) -> Self::SimdMask<S>;
1432	#[inline(always)]
1433	fn simd_index_greater_than<S: Simd>(
1434		ctx: &Self::SimdCtx<S>,
1435		lhs: Self::SimdIndex<S>,
1436		rhs: Self::SimdIndex<S>,
1437	) -> Self::SimdMask<S> {
1438		Self::simd_index_less_than(ctx, rhs, lhs)
1439	}
1440	#[inline(always)]
1441	fn simd_index_less_than_or_equal<S: Simd>(
1442		ctx: &Self::SimdCtx<S>,
1443		lhs: Self::SimdIndex<S>,
1444		rhs: Self::SimdIndex<S>,
1445	) -> Self::SimdMask<S> {
1446		Self::simd_not_mask(ctx, Self::simd_index_less_than(ctx, rhs, lhs))
1447	}
1448	#[inline(always)]
1449	fn simd_index_greater_than_or_equal<S: Simd>(
1450		ctx: &Self::SimdCtx<S>,
1451		lhs: Self::SimdIndex<S>,
1452		rhs: Self::SimdIndex<S>,
1453	) -> Self::SimdMask<S> {
1454		Self::simd_not_mask(ctx, Self::simd_index_greater_than(ctx, rhs, lhs))
1455	}
1456	fn simd_and_mask<S: Simd>(
1457		ctx: &Self::SimdCtx<S>,
1458		lhs: Self::SimdMask<S>,
1459		rhs: Self::SimdMask<S>,
1460	) -> Self::SimdMask<S>;
1461	fn simd_or_mask<S: Simd>(
1462		ctx: &Self::SimdCtx<S>,
1463		lhs: Self::SimdMask<S>,
1464		rhs: Self::SimdMask<S>,
1465	) -> Self::SimdMask<S>;
1466	fn simd_not_mask<S: Simd>(
1467		ctx: &Self::SimdCtx<S>,
1468		mask: Self::SimdMask<S>,
1469	) -> Self::SimdMask<S>;
1470	fn simd_first_true_mask<S: Simd>(
1471		ctx: &Self::SimdCtx<S>,
1472		value: Self::SimdMask<S>,
1473	) -> usize;
1474	#[inline(always)]
1475	fn simd_load<S: Simd>(
1476		ctx: &Self::SimdCtx<S>,
1477		ptr: &Self::SimdVec<S>,
1478	) -> Self::SimdVec<S> {
1479		let simd = Self::ctx_from_simd(ctx);
1480		if const { Self::Unit::IS_NATIVE_F32 } {
1481			simd.deinterleave_shfl_f32s(*ptr)
1482		} else if const { Self::Unit::IS_NATIVE_F64 } {
1483			simd.deinterleave_shfl_f64s(*ptr)
1484		} else {
1485			panic!();
1486		}
1487	}
1488	#[inline(always)]
1489	fn simd_store<S: Simd>(
1490		ctx: &Self::SimdCtx<S>,
1491		ptr: &mut Self::SimdVec<S>,
1492		value: Self::SimdVec<S>,
1493	) {
1494		let simd = Self::ctx_from_simd(ctx);
1495		if const { Self::Unit::IS_NATIVE_F32 } {
1496			*ptr = simd.interleave_shfl_f32s(value)
1497		} else if const { Self::Unit::IS_NATIVE_F64 } {
1498			*ptr = simd.interleave_shfl_f64s(value)
1499		} else {
1500			panic!();
1501		}
1502	}
1503	#[inline(always)]
1504	unsafe fn simd_mask_load<S: Simd>(
1505		ctx: &Self::SimdCtx<S>,
1506		mask: Self::SimdMemMask<S>,
1507		ptr: *const Self::SimdVec<S>,
1508	) -> Self::SimdVec<S> {
1509		let simd = Self::ctx_from_simd(ctx);
1510		let value = Self::simd_mask_load_raw(ctx, mask, ptr);
1511		if const { Self::Unit::IS_NATIVE_F32 } {
1512			simd.deinterleave_shfl_f32s(value)
1513		} else if const { Self::Unit::IS_NATIVE_F64 } {
1514			simd.deinterleave_shfl_f64s(value)
1515		} else {
1516			panic!();
1517		}
1518	}
1519	#[inline(always)]
1520	unsafe fn simd_mask_store<S: Simd>(
1521		ctx: &Self::SimdCtx<S>,
1522		mask: Self::SimdMemMask<S>,
1523		ptr: *mut Self::SimdVec<S>,
1524		value: Self::SimdVec<S>,
1525	) {
1526		let simd = Self::ctx_from_simd(ctx);
1527		if const { Self::Unit::IS_NATIVE_F32 } {
1528			Self::simd_mask_store_raw(
1529				ctx,
1530				mask,
1531				ptr,
1532				simd.interleave_shfl_f32s(value),
1533			)
1534		} else if const { Self::Unit::IS_NATIVE_F64 } {
1535			Self::simd_mask_store_raw(
1536				ctx,
1537				mask,
1538				ptr,
1539				simd.interleave_shfl_f64s(value),
1540			)
1541		} else {
1542			panic!();
1543		}
1544	}
1545	#[inline(always)]
1546	fn simd_iota<S: Simd>(ctx: &Self::SimdCtx<S>) -> Self::SimdIndex<S> {
1547		let simd = Self::ctx_from_simd(ctx);
1548		#[repr(transparent)]
1549		struct Interleave<T>(T);
1550		unsafe impl<T> pulp::Interleave for Interleave<T> {}
1551		unsafe {
1552			if const { Self::Unit::IS_NATIVE_F32 } {
1553				core::mem::transmute_copy::<_, Self::SimdIndex<S>>(
1554					&simd.deinterleave_shfl_f32s(Interleave(
1555						core::mem::transmute_copy::<_, Self::SimdVec<S>>(
1556							&pulp::iota_32::<Interleave<Self>, 64>(),
1557						),
1558					)),
1559				)
1560			} else if const { Self::Unit::IS_NATIVE_F64 } {
1561				core::mem::transmute_copy::<_, Self::SimdIndex<S>>(
1562					&simd.deinterleave_shfl_f64s(core::mem::transmute_copy::<
1563						_,
1564						Self::SimdVec<S>,
1565					>(&pulp::iota_64::<
1566						Interleave<Self>,
1567						64,
1568					>())),
1569				)
1570			} else {
1571				panic!();
1572			}
1573		}
1574	}
1575}
1576pub trait RealField:
1577	ComplexField<Real = Self, Conj = Self>
1578	+ PartialOrd
1579	+ num_traits::NumAssign
1580	+ num_traits::Num
1581	+ RefOps
1582{
1583	fn epsilon_impl() -> Self;
1584	fn nbits_impl() -> usize;
1585	fn min_positive_impl() -> Self;
1586	fn max_positive_impl() -> Self;
1587	fn sqrt_min_positive_impl() -> Self;
1588	fn sqrt_max_positive_impl() -> Self;
1589}
1590impl ComplexField for f32 {
1591	type Arch = pulp::Arch;
1592	type Index = u32;
1593	type Real = Self;
1594	type SimdCtx<S: Simd> = S;
1595	type SimdIndex<S: Simd> = S::u32s;
1596	type SimdMask<S: Simd> = S::m32s;
1597	type SimdMemMask<S: Simd> = pulp::MemMask<S::m32s>;
1598	type SimdVec<S: Simd> = S::f32s;
1599	type Unit = Self;
1600
1601	const IS_NATIVE_F32: bool = true;
1602	const IS_REAL: bool = true;
1603	const SIMD_CAPABILITIES: SimdCapabilities = SimdCapabilities::Simd;
1604
1605	#[inline(always)]
1606	fn zero_impl() -> Self {
1607		0.0
1608	}
1609
1610	#[inline(always)]
1611	fn one_impl() -> Self {
1612		1.0
1613	}
1614
1615	#[inline(always)]
1616	fn nan_impl() -> Self {
1617		Self::NAN
1618	}
1619
1620	#[inline(always)]
1621	fn infinity_impl() -> Self {
1622		Self::INFINITY
1623	}
1624
1625	#[inline(always)]
1626	fn from_real_impl(value: &Self) -> Self {
1627		*value
1628	}
1629
1630	#[inline(always)]
1631	fn from_f64_impl(value: f64) -> Self {
1632		value as _
1633	}
1634
1635	#[inline(always)]
1636	fn real_part_impl(value: &Self) -> Self {
1637		*value
1638	}
1639
1640	#[inline(always)]
1641	fn imag_part_impl(_: &Self) -> Self {
1642		0.0
1643	}
1644
1645	#[inline(always)]
1646	fn copy_impl(value: &Self) -> Self {
1647		*value
1648	}
1649
1650	#[inline(always)]
1651	fn conj_impl(value: &Self) -> Self {
1652		*value
1653	}
1654
1655	#[inline(always)]
1656	fn recip_impl(value: &Self) -> Self {
1657		1.0 / *value
1658	}
1659
1660	#[inline(always)]
1661	fn sqrt_impl(value: &Self) -> Self {
1662		#[cfg(feature = "std")]
1663		{
1664			Self::sqrt(*value)
1665		}
1666		#[cfg(not(feature = "std"))]
1667		{
1668			libm::sqrtf(*value)
1669		}
1670	}
1671
1672	#[inline(always)]
1673	fn abs_impl(value: &Self) -> Self {
1674		(*value).abs()
1675	}
1676
1677	#[inline(always)]
1678	fn abs1_impl(value: &Self) -> Self {
1679		(*value).abs()
1680	}
1681
1682	#[inline(always)]
1683	fn abs2_impl(value: &Self) -> Self {
1684		(*value) * (*value)
1685	}
1686
1687	#[inline(always)]
1688	fn mul_real_impl(lhs: &Self, rhs: &Self) -> Self {
1689		(*lhs) * (*rhs)
1690	}
1691
1692	#[inline(always)]
1693	fn mul_pow2_impl(lhs: &Self, rhs: &Self) -> Self {
1694		(*lhs) * (*rhs)
1695	}
1696
1697	#[inline(always)]
1698	fn is_finite_impl(value: &Self) -> bool {
1699		(*value).is_finite()
1700	}
1701
1702	#[inline(always)]
1703	fn is_nan_impl(value: &Self) -> bool {
1704		(*value).is_nan()
1705	}
1706
1707	#[inline(always)]
1708	fn simd_ctx<S: Simd>(simd: S) -> Self::SimdCtx<S> {
1709		simd
1710	}
1711
1712	#[inline(always)]
1713	fn simd_splat<S: Simd>(
1714		ctx: &Self::SimdCtx<S>,
1715		value: &Self,
1716	) -> Self::SimdVec<S> {
1717		ctx.splat_f32s(*value)
1718	}
1719
1720	#[inline(always)]
1721	fn simd_splat_real<S: Simd>(
1722		ctx: &Self::SimdCtx<S>,
1723		value: &Self::Real,
1724	) -> Self::SimdVec<S> {
1725		ctx.splat_f32s(*value)
1726	}
1727
1728	#[inline(always)]
1729	fn simd_add<S: Simd>(
1730		ctx: &Self::SimdCtx<S>,
1731		lhs: Self::SimdVec<S>,
1732		rhs: Self::SimdVec<S>,
1733	) -> Self::SimdVec<S> {
1734		ctx.add_f32s(lhs, rhs)
1735	}
1736
1737	#[inline(always)]
1738	fn simd_sub<S: Simd>(
1739		ctx: &Self::SimdCtx<S>,
1740		lhs: Self::SimdVec<S>,
1741		rhs: Self::SimdVec<S>,
1742	) -> Self::SimdVec<S> {
1743		ctx.sub_f32s(lhs, rhs)
1744	}
1745
1746	#[inline(always)]
1747	fn simd_neg<S: Simd>(
1748		ctx: &Self::SimdCtx<S>,
1749		value: Self::SimdVec<S>,
1750	) -> Self::SimdVec<S> {
1751		ctx.neg_f32s(value)
1752	}
1753
1754	#[inline(always)]
1755	fn simd_conj<S: Simd>(
1756		_: &Self::SimdCtx<S>,
1757		value: Self::SimdVec<S>,
1758	) -> Self::SimdVec<S> {
1759		value
1760	}
1761
1762	#[inline(always)]
1763	fn simd_abs1<S: Simd>(
1764		ctx: &Self::SimdCtx<S>,
1765		value: Self::SimdVec<S>,
1766	) -> Self::SimdVec<S> {
1767		ctx.abs_f32s(value)
1768	}
1769
1770	#[inline(always)]
1771	fn simd_mul<S: Simd>(
1772		ctx: &Self::SimdCtx<S>,
1773		lhs: Self::SimdVec<S>,
1774		rhs: Self::SimdVec<S>,
1775	) -> Self::SimdVec<S> {
1776		ctx.mul_f32s(lhs, rhs)
1777	}
1778
1779	#[inline(always)]
1780	fn simd_mul_real<S: Simd>(
1781		ctx: &Self::SimdCtx<S>,
1782		lhs: Self::SimdVec<S>,
1783		real_rhs: Self::SimdVec<S>,
1784	) -> Self::SimdVec<S> {
1785		ctx.mul_f32s(lhs, real_rhs)
1786	}
1787
1788	#[inline(always)]
1789	fn simd_mul_pow2<S: Simd>(
1790		ctx: &Self::SimdCtx<S>,
1791		lhs: Self::SimdVec<S>,
1792		real_rhs: Self::SimdVec<S>,
1793	) -> Self::SimdVec<S> {
1794		ctx.mul_f32s(lhs, real_rhs)
1795	}
1796
1797	#[inline(always)]
1798	fn simd_conj_mul<S: Simd>(
1799		ctx: &Self::SimdCtx<S>,
1800		lhs: Self::SimdVec<S>,
1801		rhs: Self::SimdVec<S>,
1802	) -> Self::SimdVec<S> {
1803		ctx.mul_f32s(lhs, rhs)
1804	}
1805
1806	#[inline(always)]
1807	fn simd_mul_add<S: Simd>(
1808		ctx: &Self::SimdCtx<S>,
1809		lhs: Self::SimdVec<S>,
1810		rhs: Self::SimdVec<S>,
1811		acc: Self::SimdVec<S>,
1812	) -> Self::SimdVec<S> {
1813		ctx.mul_add_e_f32s(lhs, rhs, acc)
1814	}
1815
1816	#[inline(always)]
1817	fn simd_conj_mul_add<S: Simd>(
1818		ctx: &Self::SimdCtx<S>,
1819		lhs: Self::SimdVec<S>,
1820		rhs: Self::SimdVec<S>,
1821		acc: Self::SimdVec<S>,
1822	) -> Self::SimdVec<S> {
1823		ctx.mul_add_e_f32s(lhs, rhs, acc)
1824	}
1825
1826	#[inline(always)]
1827	fn simd_abs2<S: Simd>(
1828		ctx: &Self::SimdCtx<S>,
1829		value: Self::SimdVec<S>,
1830	) -> Self::SimdVec<S> {
1831		ctx.mul_f32s(value, value)
1832	}
1833
1834	#[inline(always)]
1835	fn simd_abs2_add<S: Simd>(
1836		ctx: &Self::SimdCtx<S>,
1837		value: Self::SimdVec<S>,
1838		acc: Self::SimdVec<S>,
1839	) -> Self::SimdVec<S> {
1840		ctx.mul_add_e_f32s(value, value, acc)
1841	}
1842
1843	#[inline(always)]
1844	fn simd_reduce_sum<S: Simd>(
1845		ctx: &Self::SimdCtx<S>,
1846		value: Self::SimdVec<S>,
1847	) -> Self {
1848		ctx.reduce_sum_f32s(value)
1849	}
1850
1851	#[inline(always)]
1852	fn simd_reduce_max<S: Simd>(
1853		ctx: &Self::SimdCtx<S>,
1854		value: Self::SimdVec<S>,
1855	) -> Self {
1856		ctx.reduce_max_f32s(value)
1857	}
1858
1859	#[inline(always)]
1860	fn simd_equal<S: Simd>(
1861		ctx: &Self::SimdCtx<S>,
1862		real_lhs: Self::SimdVec<S>,
1863		real_rhs: Self::SimdVec<S>,
1864	) -> Self::SimdMask<S> {
1865		ctx.equal_f32s(real_lhs, real_rhs)
1866	}
1867
1868	#[inline(always)]
1869	fn simd_less_than<S: Simd>(
1870		ctx: &Self::SimdCtx<S>,
1871		real_lhs: Self::SimdVec<S>,
1872		real_rhs: Self::SimdVec<S>,
1873	) -> Self::SimdMask<S> {
1874		ctx.less_than_f32s(real_lhs, real_rhs)
1875	}
1876
1877	#[inline(always)]
1878	fn simd_greater_than<S: Simd>(
1879		ctx: &Self::SimdCtx<S>,
1880		real_lhs: Self::SimdVec<S>,
1881		real_rhs: Self::SimdVec<S>,
1882	) -> Self::SimdMask<S> {
1883		ctx.greater_than_f32s(real_lhs, real_rhs)
1884	}
1885
1886	#[inline(always)]
1887	fn simd_less_than_or_equal<S: Simd>(
1888		ctx: &Self::SimdCtx<S>,
1889		real_lhs: Self::SimdVec<S>,
1890		real_rhs: Self::SimdVec<S>,
1891	) -> Self::SimdMask<S> {
1892		ctx.less_than_or_equal_f32s(real_lhs, real_rhs)
1893	}
1894
1895	#[inline(always)]
1896	fn simd_greater_than_or_equal<S: Simd>(
1897		ctx: &Self::SimdCtx<S>,
1898		real_lhs: Self::SimdVec<S>,
1899		real_rhs: Self::SimdVec<S>,
1900	) -> Self::SimdMask<S> {
1901		ctx.greater_than_or_equal_f32s(real_lhs, real_rhs)
1902	}
1903
1904	#[inline(always)]
1905	fn simd_select<S: Simd>(
1906		ctx: &Self::SimdCtx<S>,
1907		mask: Self::SimdMask<S>,
1908		lhs: Self::SimdVec<S>,
1909		rhs: Self::SimdVec<S>,
1910	) -> Self::SimdVec<S> {
1911		ctx.select_f32s(mask, lhs, rhs)
1912	}
1913
1914	#[inline(always)]
1915	fn simd_index_select<S: Simd>(
1916		ctx: &Self::SimdCtx<S>,
1917		mask: Self::SimdMask<S>,
1918		lhs: Self::SimdIndex<S>,
1919		rhs: Self::SimdIndex<S>,
1920	) -> Self::SimdIndex<S> {
1921		ctx.select_u32s(mask, lhs, rhs)
1922	}
1923
1924	#[inline(always)]
1925	fn simd_index_splat<S: Simd>(
1926		ctx: &Self::SimdCtx<S>,
1927		value: Self::Index,
1928	) -> Self::SimdIndex<S> {
1929		ctx.splat_u32s(value as _)
1930	}
1931
1932	#[inline(always)]
1933	fn simd_index_add<S: Simd>(
1934		ctx: &Self::SimdCtx<S>,
1935		lhs: Self::SimdIndex<S>,
1936		rhs: Self::SimdIndex<S>,
1937	) -> Self::SimdIndex<S> {
1938		ctx.add_u32s(lhs, rhs)
1939	}
1940
1941	#[inline(always)]
1942	fn simd_index_less_than<S: Simd>(
1943		ctx: &Self::SimdCtx<S>,
1944		lhs: Self::SimdIndex<S>,
1945		rhs: Self::SimdIndex<S>,
1946	) -> Self::SimdMask<S> {
1947		ctx.less_than_u32s(lhs, rhs)
1948	}
1949
1950	#[inline(always)]
1951	fn simd_abs_max<S: Simd>(
1952		ctx: &Self::SimdCtx<S>,
1953		value: Self::SimdVec<S>,
1954	) -> Self::SimdVec<S> {
1955		ctx.abs_f32s(value)
1956	}
1957
1958	#[inline(always)]
1959	fn ctx_from_simd<S: Simd>(ctx: &Self::SimdCtx<S>) -> S {
1960		*ctx
1961	}
1962
1963	#[inline(always)]
1964	fn simd_and_mask<S: Simd>(
1965		simd: &Self::SimdCtx<S>,
1966		lhs: Self::SimdMask<S>,
1967		rhs: Self::SimdMask<S>,
1968	) -> Self::SimdMask<S> {
1969		simd.and_m32s(lhs, rhs)
1970	}
1971
1972	#[inline(always)]
1973	fn simd_or_mask<S: Simd>(
1974		simd: &Self::SimdCtx<S>,
1975		lhs: Self::SimdMask<S>,
1976		rhs: Self::SimdMask<S>,
1977	) -> Self::SimdMask<S> {
1978		simd.or_m32s(lhs, rhs)
1979	}
1980
1981	#[inline(always)]
1982	fn simd_not_mask<S: Simd>(
1983		ctx: &Self::SimdCtx<S>,
1984		mask: Self::SimdMask<S>,
1985	) -> Self::SimdMask<S> {
1986		ctx.not_m32s(mask)
1987	}
1988
1989	#[inline(always)]
1990	fn simd_first_true_mask<S: Simd>(
1991		ctx: &Self::SimdCtx<S>,
1992		value: Self::SimdMask<S>,
1993	) -> usize {
1994		ctx.first_true_m32s(value)
1995	}
1996
1997	#[inline(always)]
1998	fn simd_mem_mask_between<S: Simd>(
1999		ctx: &Self::SimdCtx<S>,
2000		start: Self::Index,
2001		end: Self::Index,
2002	) -> Self::SimdMemMask<S> {
2003		ctx.mask_between_m32s(start as _, end as _)
2004	}
2005
2006	#[inline(always)]
2007	fn simd_mask_between<S: Simd>(
2008		ctx: &Self::SimdCtx<S>,
2009		start: Self::Index,
2010		end: Self::Index,
2011	) -> Self::SimdMask<S> {
2012		ctx.mask_between_m32s(start as _, end as _).mask()
2013	}
2014
2015	#[inline(always)]
2016	unsafe fn simd_mask_load_raw<S: Simd>(
2017		ctx: &Self::SimdCtx<S>,
2018		mask: Self::SimdMemMask<S>,
2019		ptr: *const Self::SimdVec<S>,
2020	) -> Self::SimdVec<S> {
2021		ctx.mask_load_ptr_f32s(mask, ptr as _)
2022	}
2023
2024	#[inline(always)]
2025	unsafe fn simd_mask_store_raw<S: Simd>(
2026		ctx: &Self::SimdCtx<S>,
2027		mask: Self::SimdMemMask<S>,
2028		ptr: *mut Self::SimdVec<S>,
2029		values: Self::SimdVec<S>,
2030	) {
2031		ctx.mask_store_ptr_f32s(mask, ptr as _, values);
2032	}
2033}
2034impl RealField for f32 {
2035	#[inline(always)]
2036	fn epsilon_impl() -> Self {
2037		Self::EPSILON
2038	}
2039
2040	#[inline(always)]
2041	fn min_positive_impl() -> Self {
2042		Self::MIN_POSITIVE
2043	}
2044
2045	#[inline(always)]
2046	fn max_positive_impl() -> Self {
2047		Self::MIN_POSITIVE.recip()
2048	}
2049
2050	#[inline(always)]
2051	fn sqrt_min_positive_impl() -> Self {
2052		Self::sqrt_impl(&Self::MIN_POSITIVE)
2053	}
2054
2055	#[inline(always)]
2056	fn sqrt_max_positive_impl() -> Self {
2057		Self::sqrt_impl(&Self::MIN_POSITIVE.recip())
2058	}
2059
2060	#[inline(always)]
2061	fn nbits_impl() -> usize {
2062		Self::MANTISSA_DIGITS as usize
2063	}
2064}
2065impl ComplexField for f64 {
2066	type Arch = pulp::Arch;
2067	type Index = u64;
2068	type Real = Self;
2069	type SimdCtx<S: Simd> = S;
2070	type SimdIndex<S: Simd> = S::u64s;
2071	type SimdMask<S: Simd> = S::m64s;
2072	type SimdMemMask<S: Simd> = pulp::MemMask<S::m64s>;
2073	type SimdVec<S: Simd> = S::f64s;
2074	type Unit = Self;
2075
2076	const IS_NATIVE_F64: bool = true;
2077	const IS_REAL: bool = true;
2078	const SIMD_CAPABILITIES: SimdCapabilities = SimdCapabilities::Simd;
2079
2080	#[inline(always)]
2081	fn zero_impl() -> Self {
2082		0.0
2083	}
2084
2085	#[inline(always)]
2086	fn one_impl() -> Self {
2087		1.0
2088	}
2089
2090	#[inline(always)]
2091	fn nan_impl() -> Self {
2092		Self::NAN
2093	}
2094
2095	#[inline(always)]
2096	fn infinity_impl() -> Self {
2097		Self::INFINITY
2098	}
2099
2100	#[inline(always)]
2101	fn from_real_impl(value: &Self) -> Self {
2102		*value
2103	}
2104
2105	#[inline(always)]
2106	fn from_f64_impl(value: f64) -> Self {
2107		value as _
2108	}
2109
2110	#[inline(always)]
2111	fn real_part_impl(value: &Self) -> Self {
2112		*value
2113	}
2114
2115	#[inline(always)]
2116	fn imag_part_impl(_: &Self) -> Self {
2117		0.0
2118	}
2119
2120	#[inline(always)]
2121	fn copy_impl(value: &Self) -> Self {
2122		*value
2123	}
2124
2125	#[inline(always)]
2126	fn conj_impl(value: &Self) -> Self {
2127		*value
2128	}
2129
2130	#[inline(always)]
2131	fn recip_impl(value: &Self) -> Self {
2132		1.0 / *value
2133	}
2134
2135	#[inline(always)]
2136	fn sqrt_impl(value: &Self) -> Self {
2137		#[cfg(feature = "std")]
2138		{
2139			Self::sqrt(*value)
2140		}
2141		#[cfg(not(feature = "std"))]
2142		{
2143			libm::sqrt(*value)
2144		}
2145	}
2146
2147	#[inline(always)]
2148	fn abs_impl(value: &Self) -> Self {
2149		(*value).abs()
2150	}
2151
2152	#[inline(always)]
2153	fn abs1_impl(value: &Self) -> Self {
2154		(*value).abs()
2155	}
2156
2157	#[inline(always)]
2158	fn abs2_impl(value: &Self) -> Self {
2159		(*value) * (*value)
2160	}
2161
2162	#[inline(always)]
2163	fn mul_real_impl(lhs: &Self, rhs: &Self) -> Self {
2164		(*lhs) * (*rhs)
2165	}
2166
2167	#[inline(always)]
2168	fn mul_pow2_impl(lhs: &Self, rhs: &Self) -> Self {
2169		(*lhs) * (*rhs)
2170	}
2171
2172	#[inline(always)]
2173	fn is_nan_impl(value: &Self) -> bool {
2174		(*value).is_nan()
2175	}
2176
2177	#[inline(always)]
2178	fn simd_ctx<S: Simd>(simd: S) -> Self::SimdCtx<S> {
2179		simd
2180	}
2181
2182	#[inline(always)]
2183	fn simd_splat<S: Simd>(
2184		ctx: &Self::SimdCtx<S>,
2185		value: &Self,
2186	) -> Self::SimdVec<S> {
2187		ctx.splat_f64s(*value)
2188	}
2189
2190	#[inline(always)]
2191	fn simd_splat_real<S: Simd>(
2192		ctx: &Self::SimdCtx<S>,
2193		value: &Self::Real,
2194	) -> Self::SimdVec<S> {
2195		ctx.splat_f64s(*value)
2196	}
2197
2198	#[inline(always)]
2199	fn simd_add<S: Simd>(
2200		ctx: &Self::SimdCtx<S>,
2201		lhs: Self::SimdVec<S>,
2202		rhs: Self::SimdVec<S>,
2203	) -> Self::SimdVec<S> {
2204		ctx.add_f64s(lhs, rhs)
2205	}
2206
2207	#[inline(always)]
2208	fn simd_sub<S: Simd>(
2209		ctx: &Self::SimdCtx<S>,
2210		lhs: Self::SimdVec<S>,
2211		rhs: Self::SimdVec<S>,
2212	) -> Self::SimdVec<S> {
2213		ctx.sub_f64s(lhs, rhs)
2214	}
2215
2216	#[inline(always)]
2217	fn simd_neg<S: Simd>(
2218		ctx: &Self::SimdCtx<S>,
2219		value: Self::SimdVec<S>,
2220	) -> Self::SimdVec<S> {
2221		ctx.neg_f64s(value)
2222	}
2223
2224	#[inline(always)]
2225	fn simd_conj<S: Simd>(
2226		_: &Self::SimdCtx<S>,
2227		value: Self::SimdVec<S>,
2228	) -> Self::SimdVec<S> {
2229		value
2230	}
2231
2232	#[inline(always)]
2233	fn simd_abs1<S: Simd>(
2234		ctx: &Self::SimdCtx<S>,
2235		value: Self::SimdVec<S>,
2236	) -> Self::SimdVec<S> {
2237		ctx.abs_f64s(value)
2238	}
2239
2240	#[inline(always)]
2241	fn simd_mul<S: Simd>(
2242		ctx: &Self::SimdCtx<S>,
2243		lhs: Self::SimdVec<S>,
2244		rhs: Self::SimdVec<S>,
2245	) -> Self::SimdVec<S> {
2246		ctx.mul_f64s(lhs, rhs)
2247	}
2248
2249	#[inline(always)]
2250	fn simd_mul_real<S: Simd>(
2251		ctx: &Self::SimdCtx<S>,
2252		lhs: Self::SimdVec<S>,
2253		real_rhs: Self::SimdVec<S>,
2254	) -> Self::SimdVec<S> {
2255		ctx.mul_f64s(lhs, real_rhs)
2256	}
2257
2258	#[inline(always)]
2259	fn simd_mul_pow2<S: Simd>(
2260		ctx: &Self::SimdCtx<S>,
2261		lhs: Self::SimdVec<S>,
2262		real_rhs: Self::SimdVec<S>,
2263	) -> Self::SimdVec<S> {
2264		ctx.mul_f64s(lhs, real_rhs)
2265	}
2266
2267	#[inline(always)]
2268	fn simd_conj_mul<S: Simd>(
2269		ctx: &Self::SimdCtx<S>,
2270		lhs: Self::SimdVec<S>,
2271		rhs: Self::SimdVec<S>,
2272	) -> Self::SimdVec<S> {
2273		ctx.mul_f64s(lhs, rhs)
2274	}
2275
2276	#[inline(always)]
2277	fn simd_mul_add<S: Simd>(
2278		ctx: &Self::SimdCtx<S>,
2279		lhs: Self::SimdVec<S>,
2280		rhs: Self::SimdVec<S>,
2281		acc: Self::SimdVec<S>,
2282	) -> Self::SimdVec<S> {
2283		ctx.mul_add_e_f64s(lhs, rhs, acc)
2284	}
2285
2286	#[inline(always)]
2287	fn simd_conj_mul_add<S: Simd>(
2288		ctx: &Self::SimdCtx<S>,
2289		lhs: Self::SimdVec<S>,
2290		rhs: Self::SimdVec<S>,
2291		acc: Self::SimdVec<S>,
2292	) -> Self::SimdVec<S> {
2293		ctx.mul_add_e_f64s(lhs, rhs, acc)
2294	}
2295
2296	#[inline(always)]
2297	fn simd_abs2<S: Simd>(
2298		ctx: &Self::SimdCtx<S>,
2299		value: Self::SimdVec<S>,
2300	) -> Self::SimdVec<S> {
2301		ctx.mul_f64s(value, value)
2302	}
2303
2304	#[inline(always)]
2305	fn simd_abs2_add<S: Simd>(
2306		ctx: &Self::SimdCtx<S>,
2307		value: Self::SimdVec<S>,
2308		acc: Self::SimdVec<S>,
2309	) -> Self::SimdVec<S> {
2310		ctx.mul_add_e_f64s(value, value, acc)
2311	}
2312
2313	#[inline(always)]
2314	fn simd_reduce_sum<S: Simd>(
2315		ctx: &Self::SimdCtx<S>,
2316		value: Self::SimdVec<S>,
2317	) -> Self {
2318		ctx.reduce_sum_f64s(value)
2319	}
2320
2321	#[inline(always)]
2322	fn simd_reduce_max<S: Simd>(
2323		ctx: &Self::SimdCtx<S>,
2324		value: Self::SimdVec<S>,
2325	) -> Self {
2326		ctx.reduce_max_f64s(value)
2327	}
2328
2329	#[inline(always)]
2330	fn simd_equal<S: Simd>(
2331		ctx: &Self::SimdCtx<S>,
2332		real_lhs: Self::SimdVec<S>,
2333		real_rhs: Self::SimdVec<S>,
2334	) -> Self::SimdMask<S> {
2335		ctx.equal_f64s(real_lhs, real_rhs)
2336	}
2337
2338	#[inline(always)]
2339	fn simd_less_than<S: Simd>(
2340		ctx: &Self::SimdCtx<S>,
2341		real_lhs: Self::SimdVec<S>,
2342		real_rhs: Self::SimdVec<S>,
2343	) -> Self::SimdMask<S> {
2344		ctx.less_than_f64s(real_lhs, real_rhs)
2345	}
2346
2347	#[inline(always)]
2348	fn simd_greater_than<S: Simd>(
2349		ctx: &Self::SimdCtx<S>,
2350		real_lhs: Self::SimdVec<S>,
2351		real_rhs: Self::SimdVec<S>,
2352	) -> Self::SimdMask<S> {
2353		ctx.greater_than_f64s(real_lhs, real_rhs)
2354	}
2355
2356	#[inline(always)]
2357	fn simd_less_than_or_equal<S: Simd>(
2358		ctx: &Self::SimdCtx<S>,
2359		real_lhs: Self::SimdVec<S>,
2360		real_rhs: Self::SimdVec<S>,
2361	) -> Self::SimdMask<S> {
2362		ctx.less_than_or_equal_f64s(real_lhs, real_rhs)
2363	}
2364
2365	#[inline(always)]
2366	fn simd_greater_than_or_equal<S: Simd>(
2367		ctx: &Self::SimdCtx<S>,
2368		real_lhs: Self::SimdVec<S>,
2369		real_rhs: Self::SimdVec<S>,
2370	) -> Self::SimdMask<S> {
2371		ctx.greater_than_or_equal_f64s(real_lhs, real_rhs)
2372	}
2373
2374	#[inline(always)]
2375	fn simd_select<S: Simd>(
2376		ctx: &Self::SimdCtx<S>,
2377		mask: Self::SimdMask<S>,
2378		lhs: Self::SimdVec<S>,
2379		rhs: Self::SimdVec<S>,
2380	) -> Self::SimdVec<S> {
2381		ctx.select_f64s(mask, lhs, rhs)
2382	}
2383
2384	#[inline(always)]
2385	fn simd_index_select<S: Simd>(
2386		ctx: &Self::SimdCtx<S>,
2387		mask: Self::SimdMask<S>,
2388		lhs: Self::SimdIndex<S>,
2389		rhs: Self::SimdIndex<S>,
2390	) -> Self::SimdIndex<S> {
2391		ctx.select_u64s(mask, lhs, rhs)
2392	}
2393
2394	#[inline(always)]
2395	fn simd_index_splat<S: Simd>(
2396		ctx: &Self::SimdCtx<S>,
2397		value: Self::Index,
2398	) -> Self::SimdIndex<S> {
2399		ctx.splat_u64s(value as _)
2400	}
2401
2402	#[inline(always)]
2403	fn simd_index_add<S: Simd>(
2404		ctx: &Self::SimdCtx<S>,
2405		lhs: Self::SimdIndex<S>,
2406		rhs: Self::SimdIndex<S>,
2407	) -> Self::SimdIndex<S> {
2408		ctx.add_u64s(lhs, rhs)
2409	}
2410
2411	#[inline(always)]
2412	fn simd_index_less_than<S: Simd>(
2413		ctx: &Self::SimdCtx<S>,
2414		lhs: Self::SimdIndex<S>,
2415		rhs: Self::SimdIndex<S>,
2416	) -> Self::SimdMask<S> {
2417		ctx.less_than_u64s(lhs, rhs)
2418	}
2419
2420	#[inline(always)]
2421	fn simd_abs_max<S: Simd>(
2422		ctx: &Self::SimdCtx<S>,
2423		value: Self::SimdVec<S>,
2424	) -> Self::SimdVec<S> {
2425		ctx.abs_f64s(value)
2426	}
2427
2428	#[inline(always)]
2429	fn ctx_from_simd<S: Simd>(ctx: &Self::SimdCtx<S>) -> S {
2430		*ctx
2431	}
2432
2433	#[inline(always)]
2434	fn simd_and_mask<S: Simd>(
2435		simd: &Self::SimdCtx<S>,
2436		lhs: Self::SimdMask<S>,
2437		rhs: Self::SimdMask<S>,
2438	) -> Self::SimdMask<S> {
2439		simd.and_m64s(lhs, rhs)
2440	}
2441
2442	#[inline(always)]
2443	fn simd_or_mask<S: Simd>(
2444		simd: &Self::SimdCtx<S>,
2445		lhs: Self::SimdMask<S>,
2446		rhs: Self::SimdMask<S>,
2447	) -> Self::SimdMask<S> {
2448		simd.or_m64s(lhs, rhs)
2449	}
2450
2451	#[inline(always)]
2452	fn simd_not_mask<S: Simd>(
2453		ctx: &Self::SimdCtx<S>,
2454		mask: Self::SimdMask<S>,
2455	) -> Self::SimdMask<S> {
2456		ctx.not_m64s(mask)
2457	}
2458
2459	#[inline(always)]
2460	fn simd_first_true_mask<S: Simd>(
2461		ctx: &Self::SimdCtx<S>,
2462		value: Self::SimdMask<S>,
2463	) -> usize {
2464		ctx.first_true_m64s(value)
2465	}
2466
2467	#[inline(always)]
2468	fn is_finite_impl(value: &Self) -> bool {
2469		(*value).is_finite()
2470	}
2471
2472	#[inline(always)]
2473	fn simd_mem_mask_between<S: Simd>(
2474		ctx: &Self::SimdCtx<S>,
2475		start: Self::Index,
2476		end: Self::Index,
2477	) -> Self::SimdMemMask<S> {
2478		ctx.mask_between_m64s(start as _, end as _)
2479	}
2480
2481	#[inline(always)]
2482	fn simd_mask_between<S: Simd>(
2483		ctx: &Self::SimdCtx<S>,
2484		start: Self::Index,
2485		end: Self::Index,
2486	) -> Self::SimdMask<S> {
2487		ctx.mask_between_m64s(start as _, end as _).mask()
2488	}
2489
2490	#[inline(always)]
2491	unsafe fn simd_mask_load_raw<S: Simd>(
2492		ctx: &Self::SimdCtx<S>,
2493		mask: Self::SimdMemMask<S>,
2494		ptr: *const Self::SimdVec<S>,
2495	) -> Self::SimdVec<S> {
2496		ctx.mask_load_ptr_f64s(mask, ptr as _)
2497	}
2498
2499	#[inline(always)]
2500	unsafe fn simd_mask_store_raw<S: Simd>(
2501		ctx: &Self::SimdCtx<S>,
2502		mask: Self::SimdMemMask<S>,
2503		ptr: *mut Self::SimdVec<S>,
2504		values: Self::SimdVec<S>,
2505	) {
2506		ctx.mask_store_ptr_f64s(mask, ptr as _, values);
2507	}
2508}
2509impl RealField for f64 {
2510	#[inline(always)]
2511	fn epsilon_impl() -> Self {
2512		Self::EPSILON
2513	}
2514
2515	#[inline(always)]
2516	fn min_positive_impl() -> Self {
2517		Self::MIN_POSITIVE
2518	}
2519
2520	#[inline(always)]
2521	fn max_positive_impl() -> Self {
2522		Self::MIN_POSITIVE.recip()
2523	}
2524
2525	#[inline(always)]
2526	fn sqrt_min_positive_impl() -> Self {
2527		Self::sqrt_impl(&Self::MIN_POSITIVE)
2528	}
2529
2530	#[inline(always)]
2531	fn sqrt_max_positive_impl() -> Self {
2532		Self::sqrt_impl(&Self::MIN_POSITIVE.recip())
2533	}
2534
2535	#[inline(always)]
2536	fn nbits_impl() -> usize {
2537		Self::MANTISSA_DIGITS as usize
2538	}
2539}
2540impl<T: RealField<Unit: ComplexField>> ComplexField for Complex<T> {
2541	type Arch = T::Arch;
2542	type Index = T::Index;
2543	type Real = T;
2544	type SimdCtx<S: Simd> = T::SimdCtx<S>;
2545	type SimdIndex<S: Simd> = T::SimdIndex<S>;
2546	type SimdMask<S: Simd> = T::SimdMask<S>;
2547	type SimdMemMask<S: Simd> = Complex<T::SimdMemMask<S>>;
2548	type SimdVec<S: Simd> = Complex<T::SimdVec<S>>;
2549	type Unit = T::Unit;
2550
2551	const IS_NATIVE_C32: bool = T::IS_NATIVE_F32;
2552	const IS_NATIVE_C64: bool = T::IS_NATIVE_F64;
2553	const IS_REAL: bool = false;
2554	const SIMD_CAPABILITIES: SimdCapabilities = T::SIMD_CAPABILITIES;
2555
2556	#[inline]
2557	fn zero_impl() -> Self {
2558		Complex {
2559			re: T::zero_impl(),
2560			im: T::zero_impl(),
2561		}
2562	}
2563
2564	#[inline]
2565	fn one_impl() -> Self {
2566		Complex {
2567			re: T::one_impl(),
2568			im: T::zero_impl(),
2569		}
2570	}
2571
2572	#[inline]
2573	fn nan_impl() -> Self {
2574		Complex {
2575			re: T::nan_impl(),
2576			im: T::nan_impl(),
2577		}
2578	}
2579
2580	#[inline]
2581	fn infinity_impl() -> Self {
2582		Complex {
2583			re: T::infinity_impl(),
2584			im: T::infinity_impl(),
2585		}
2586	}
2587
2588	#[inline]
2589	fn from_real_impl(real: &Self::Real) -> Self {
2590		Complex {
2591			re: real.clone(),
2592			im: T::zero_impl(),
2593		}
2594	}
2595
2596	#[inline]
2597	fn from_f64_impl(real: f64) -> Self {
2598		Complex {
2599			re: T::from_f64_impl(real),
2600			im: T::zero_impl(),
2601		}
2602	}
2603
2604	#[inline]
2605	fn real_part_impl(value: &Self) -> Self::Real {
2606		value.re.clone()
2607	}
2608
2609	#[inline]
2610	fn imag_part_impl(value: &Self) -> Self::Real {
2611		value.im.clone()
2612	}
2613
2614	#[inline]
2615	fn copy_impl(value: &Self) -> Self {
2616		value.clone()
2617	}
2618
2619	#[inline]
2620	fn conj_impl(value: &Self) -> Self {
2621		Self {
2622			re: value.re.clone(),
2623			im: value.im.neg_by_ref(),
2624		}
2625	}
2626
2627	#[inline]
2628	fn recip_impl(value: &Self) -> Self {
2629		let (re, im) = recip_impl(value.re.clone(), value.im.clone());
2630		Complex { re, im }
2631	}
2632
2633	#[inline]
2634	fn sqrt_impl(value: &Self) -> Self {
2635		let (re, im) = sqrt_impl(value.re.clone(), value.im.clone());
2636		Complex { re, im }
2637	}
2638
2639	#[inline]
2640	fn abs_impl(value: &Self) -> Self::Real {
2641		abs_impl(value.re.clone(), value.im.clone())
2642	}
2643
2644	#[inline]
2645	fn abs1_impl(value: &Self) -> Self::Real {
2646		use crate::ext::*;
2647		value.re.abs1() + value.im.abs1()
2648	}
2649
2650	#[inline]
2651	fn abs2_impl(value: &Self) -> Self::Real {
2652		use crate::ext::*;
2653		value.re.abs2() + value.im.abs2()
2654	}
2655
2656	#[inline]
2657	fn mul_real_impl(lhs: &Self, rhs: &Self::Real) -> Self {
2658		Complex {
2659			re: &lhs.re * rhs,
2660			im: &lhs.im * rhs,
2661		}
2662	}
2663
2664	#[inline]
2665	fn mul_pow2_impl(lhs: &Self, rhs: &Self::Real) -> Self {
2666		use crate::ext::*;
2667		Complex {
2668			re: lhs.re.mul_pow2(rhs),
2669			im: lhs.im.mul_pow2(rhs),
2670		}
2671	}
2672
2673	#[inline]
2674	fn is_finite_impl(value: &Self) -> bool {
2675		use crate::ext::*;
2676		value.re.is_finite() && value.im.is_finite()
2677	}
2678
2679	#[inline(always)]
2680	fn simd_ctx<S: Simd>(simd: S) -> Self::SimdCtx<S> {
2681		T::simd_ctx(simd)
2682	}
2683
2684	#[inline(always)]
2685	fn ctx_from_simd<S: Simd>(ctx: &Self::SimdCtx<S>) -> S {
2686		T::ctx_from_simd(ctx)
2687	}
2688
2689	#[inline(always)]
2690	fn simd_splat<S: Simd>(
2691		ctx: &Self::SimdCtx<S>,
2692		value: &Self,
2693	) -> Self::SimdVec<S> {
2694		Complex {
2695			re: T::simd_splat(ctx, &value.re),
2696			im: T::simd_splat(ctx, &value.im),
2697		}
2698	}
2699
2700	#[inline(always)]
2701	fn simd_splat_real<S: Simd>(
2702		ctx: &Self::SimdCtx<S>,
2703		value: &Self::Real,
2704	) -> Self::SimdVec<S> {
2705		Complex {
2706			re: T::simd_splat_real(ctx, value),
2707			im: T::simd_splat_real(ctx, value),
2708		}
2709	}
2710
2711	#[inline(always)]
2712	fn simd_add<S: Simd>(
2713		ctx: &Self::SimdCtx<S>,
2714		lhs: Self::SimdVec<S>,
2715		rhs: Self::SimdVec<S>,
2716	) -> Self::SimdVec<S> {
2717		Complex {
2718			re: T::simd_add(ctx, lhs.re, rhs.re),
2719			im: T::simd_add(ctx, lhs.im, rhs.im),
2720		}
2721	}
2722
2723	#[inline(always)]
2724	fn simd_sub<S: Simd>(
2725		ctx: &Self::SimdCtx<S>,
2726		lhs: Self::SimdVec<S>,
2727		rhs: Self::SimdVec<S>,
2728	) -> Self::SimdVec<S> {
2729		Complex {
2730			re: T::simd_sub(ctx, lhs.re, rhs.re),
2731			im: T::simd_sub(ctx, lhs.im, rhs.im),
2732		}
2733	}
2734
2735	#[inline(always)]
2736	fn simd_neg<S: Simd>(
2737		ctx: &Self::SimdCtx<S>,
2738		value: Self::SimdVec<S>,
2739	) -> Self::SimdVec<S> {
2740		Complex {
2741			re: T::simd_neg(ctx, value.re),
2742			im: T::simd_neg(ctx, value.im),
2743		}
2744	}
2745
2746	#[inline(always)]
2747	fn simd_conj<S: Simd>(
2748		ctx: &Self::SimdCtx<S>,
2749		value: Self::SimdVec<S>,
2750	) -> Self::SimdVec<S> {
2751		Complex {
2752			re: value.re,
2753			im: T::simd_neg(ctx, value.im),
2754		}
2755	}
2756
2757	#[inline(always)]
2758	fn simd_abs1<S: Simd>(
2759		ctx: &Self::SimdCtx<S>,
2760		value: Self::SimdVec<S>,
2761	) -> Self::SimdVec<S> {
2762		let v = T::simd_add(
2763			ctx,
2764			T::simd_abs1(ctx, value.re),
2765			T::simd_abs1(ctx, value.im),
2766		);
2767		Complex { re: v, im: v }
2768	}
2769
2770	#[inline(always)]
2771	fn simd_abs_max<S: Simd>(
2772		ctx: &Self::SimdCtx<S>,
2773		value: Self::SimdVec<S>,
2774	) -> Self::SimdVec<S> {
2775		let re = T::simd_abs_max(ctx, value.re);
2776		let im = T::simd_abs_max(ctx, value.im);
2777		let v = T::simd_select(ctx, T::simd_greater_than(ctx, re, im), re, im);
2778		Complex { re: v, im: v }
2779	}
2780
2781	#[inline(always)]
2782	fn simd_mul_real<S: Simd>(
2783		ctx: &Self::SimdCtx<S>,
2784		lhs: Self::SimdVec<S>,
2785		real_rhs: Self::SimdVec<S>,
2786	) -> Self::SimdVec<S> {
2787		Complex {
2788			re: T::simd_mul_real(ctx, lhs.re, real_rhs.re),
2789			im: T::simd_mul_real(ctx, lhs.im, real_rhs.re),
2790		}
2791	}
2792
2793	#[inline(always)]
2794	fn simd_mul_pow2<S: Simd>(
2795		ctx: &Self::SimdCtx<S>,
2796		lhs: Self::SimdVec<S>,
2797		real_rhs: Self::SimdVec<S>,
2798	) -> Self::SimdVec<S> {
2799		Complex {
2800			re: T::simd_mul_pow2(ctx, lhs.re, real_rhs.re),
2801			im: T::simd_mul_pow2(ctx, lhs.im, real_rhs.re),
2802		}
2803	}
2804
2805	#[inline(always)]
2806	fn simd_mul<S: Simd>(
2807		ctx: &Self::SimdCtx<S>,
2808		lhs: Self::SimdVec<S>,
2809		rhs: Self::SimdVec<S>,
2810	) -> Self::SimdVec<S> {
2811		Complex {
2812			re: T::simd_mul_add(
2813				ctx,
2814				lhs.re,
2815				rhs.re,
2816				T::simd_neg(ctx, T::simd_mul(ctx, lhs.im, rhs.im)),
2817			),
2818			im: T::simd_mul_add(
2819				ctx,
2820				lhs.re,
2821				rhs.im,
2822				T::simd_mul(ctx, lhs.im, rhs.re),
2823			),
2824		}
2825	}
2826
2827	#[inline(always)]
2828	fn simd_conj_mul<S: Simd>(
2829		ctx: &Self::SimdCtx<S>,
2830		lhs: Self::SimdVec<S>,
2831		rhs: Self::SimdVec<S>,
2832	) -> Self::SimdVec<S> {
2833		Complex {
2834			re: T::simd_mul_add(
2835				ctx,
2836				lhs.re,
2837				rhs.re,
2838				T::simd_mul(ctx, lhs.im, rhs.im),
2839			),
2840			im: T::simd_mul_add(
2841				ctx,
2842				lhs.re,
2843				rhs.im,
2844				T::simd_neg(ctx, T::simd_mul(ctx, lhs.im, rhs.re)),
2845			),
2846		}
2847	}
2848
2849	#[inline(always)]
2850	fn simd_mul_add<S: Simd>(
2851		ctx: &Self::SimdCtx<S>,
2852		lhs: Self::SimdVec<S>,
2853		rhs: Self::SimdVec<S>,
2854		acc: Self::SimdVec<S>,
2855	) -> Self::SimdVec<S> {
2856		Complex {
2857			re: T::simd_mul_add(
2858				ctx,
2859				T::simd_neg(ctx, lhs.im),
2860				rhs.im,
2861				T::simd_mul_add(ctx, lhs.re, rhs.re, acc.re),
2862			),
2863			im: T::simd_mul_add(
2864				ctx,
2865				lhs.re,
2866				rhs.im,
2867				T::simd_mul_add(ctx, lhs.im, rhs.re, acc.im),
2868			),
2869		}
2870	}
2871
2872	#[inline(always)]
2873	fn simd_conj_mul_add<S: Simd>(
2874		ctx: &Self::SimdCtx<S>,
2875		lhs: Self::SimdVec<S>,
2876		rhs: Self::SimdVec<S>,
2877		acc: Self::SimdVec<S>,
2878	) -> Self::SimdVec<S> {
2879		Complex {
2880			re: T::simd_mul_add(
2881				ctx,
2882				lhs.im,
2883				rhs.im,
2884				T::simd_mul_add(ctx, lhs.re, rhs.re, acc.re),
2885			),
2886			im: T::simd_mul_add(
2887				ctx,
2888				lhs.re,
2889				rhs.im,
2890				T::simd_mul_add(ctx, T::simd_neg(ctx, lhs.im), rhs.re, acc.im),
2891			),
2892		}
2893	}
2894
2895	#[inline(always)]
2896	fn simd_abs2<S: Simd>(
2897		ctx: &Self::SimdCtx<S>,
2898		value: Self::SimdVec<S>,
2899	) -> Self::SimdVec<S> {
2900		let v = T::simd_abs2_add(ctx, value.re, T::simd_abs2(ctx, value.im));
2901		Complex { re: v, im: v }
2902	}
2903
2904	#[inline(always)]
2905	fn simd_abs2_add<S: Simd>(
2906		ctx: &Self::SimdCtx<S>,
2907		value: Self::SimdVec<S>,
2908		acc: Self::SimdVec<S>,
2909	) -> Self::SimdVec<S> {
2910		let v = T::simd_abs2_add(
2911			ctx,
2912			value.re,
2913			T::simd_abs2_add(ctx, value.im, acc.re),
2914		);
2915		Complex { re: v, im: v }
2916	}
2917
2918	#[inline(always)]
2919	fn simd_reduce_sum<S: Simd>(
2920		ctx: &Self::SimdCtx<S>,
2921		value: Self::SimdVec<S>,
2922	) -> Self {
2923		Complex {
2924			re: T::simd_reduce_sum(ctx, value.re),
2925			im: T::simd_reduce_sum(ctx, value.im),
2926		}
2927	}
2928
2929	#[inline(always)]
2930	fn simd_reduce_max<S: Simd>(
2931		ctx: &Self::SimdCtx<S>,
2932		value: Self::SimdVec<S>,
2933	) -> Self {
2934		Complex {
2935			re: T::simd_reduce_max(ctx, value.re),
2936			im: T::simd_reduce_max(ctx, value.im),
2937		}
2938	}
2939
2940	#[inline(always)]
2941	fn simd_equal<S: Simd>(
2942		ctx: &Self::SimdCtx<S>,
2943		real_lhs: Self::SimdVec<S>,
2944		real_rhs: Self::SimdVec<S>,
2945	) -> Self::SimdMask<S> {
2946		T::simd_and_mask(
2947			ctx,
2948			T::simd_equal(ctx, real_lhs.re, real_rhs.re),
2949			T::simd_equal(ctx, real_lhs.im, real_rhs.im),
2950		)
2951	}
2952
2953	#[inline(always)]
2954	fn simd_less_than<S: Simd>(
2955		ctx: &Self::SimdCtx<S>,
2956		real_lhs: Self::SimdVec<S>,
2957		real_rhs: Self::SimdVec<S>,
2958	) -> Self::SimdMask<S> {
2959		T::simd_less_than(ctx, real_lhs.re, real_rhs.re)
2960	}
2961
2962	#[inline(always)]
2963	fn simd_less_than_or_equal<S: Simd>(
2964		ctx: &Self::SimdCtx<S>,
2965		real_lhs: Self::SimdVec<S>,
2966		real_rhs: Self::SimdVec<S>,
2967	) -> Self::SimdMask<S> {
2968		T::simd_less_than_or_equal(ctx, real_lhs.re, real_rhs.re)
2969	}
2970
2971	#[inline(always)]
2972	fn simd_greater_than<S: Simd>(
2973		ctx: &Self::SimdCtx<S>,
2974		real_lhs: Self::SimdVec<S>,
2975		real_rhs: Self::SimdVec<S>,
2976	) -> Self::SimdMask<S> {
2977		T::simd_greater_than(ctx, real_lhs.re, real_rhs.re)
2978	}
2979
2980	#[inline(always)]
2981	fn simd_greater_than_or_equal<S: Simd>(
2982		ctx: &Self::SimdCtx<S>,
2983		real_lhs: Self::SimdVec<S>,
2984		real_rhs: Self::SimdVec<S>,
2985	) -> Self::SimdMask<S> {
2986		T::simd_greater_than_or_equal(ctx, real_lhs.re, real_rhs.re)
2987	}
2988
2989	#[inline(always)]
2990	fn simd_select<S: Simd>(
2991		ctx: &Self::SimdCtx<S>,
2992		mask: Self::SimdMask<S>,
2993		lhs: Self::SimdVec<S>,
2994		rhs: Self::SimdVec<S>,
2995	) -> Self::SimdVec<S> {
2996		Complex {
2997			re: T::simd_select(ctx, mask, lhs.re, rhs.re),
2998			im: T::simd_select(ctx, mask, lhs.im, rhs.im),
2999		}
3000	}
3001
3002	#[inline(always)]
3003	fn simd_index_select<S: Simd>(
3004		ctx: &Self::SimdCtx<S>,
3005		mask: Self::SimdMask<S>,
3006		lhs: Self::SimdIndex<S>,
3007		rhs: Self::SimdIndex<S>,
3008	) -> Self::SimdIndex<S> {
3009		T::simd_index_select(ctx, mask, lhs, rhs)
3010	}
3011
3012	#[inline(always)]
3013	fn simd_index_splat<S: Simd>(
3014		ctx: &Self::SimdCtx<S>,
3015		value: Self::Index,
3016	) -> Self::SimdIndex<S> {
3017		T::simd_index_splat(ctx, value)
3018	}
3019
3020	#[inline(always)]
3021	fn simd_index_add<S: Simd>(
3022		ctx: &Self::SimdCtx<S>,
3023		lhs: Self::SimdIndex<S>,
3024		rhs: Self::SimdIndex<S>,
3025	) -> Self::SimdIndex<S> {
3026		T::simd_index_add(ctx, lhs, rhs)
3027	}
3028
3029	#[inline(always)]
3030	fn simd_index_less_than<S: Simd>(
3031		ctx: &Self::SimdCtx<S>,
3032		lhs: Self::SimdIndex<S>,
3033		rhs: Self::SimdIndex<S>,
3034	) -> Self::SimdMask<S> {
3035		T::simd_index_less_than(ctx, lhs, rhs)
3036	}
3037
3038	#[inline(always)]
3039	fn simd_and_mask<S: Simd>(
3040		ctx: &Self::SimdCtx<S>,
3041		lhs: Self::SimdMask<S>,
3042		rhs: Self::SimdMask<S>,
3043	) -> Self::SimdMask<S> {
3044		T::simd_and_mask(ctx, lhs, rhs)
3045	}
3046
3047	#[inline(always)]
3048	fn simd_or_mask<S: Simd>(
3049		ctx: &Self::SimdCtx<S>,
3050		lhs: Self::SimdMask<S>,
3051		rhs: Self::SimdMask<S>,
3052	) -> Self::SimdMask<S> {
3053		T::simd_or_mask(ctx, lhs, rhs)
3054	}
3055
3056	#[inline(always)]
3057	fn simd_not_mask<S: Simd>(
3058		ctx: &Self::SimdCtx<S>,
3059		mask: Self::SimdMask<S>,
3060	) -> Self::SimdMask<S> {
3061		T::simd_not_mask(ctx, mask)
3062	}
3063
3064	#[inline(always)]
3065	fn simd_first_true_mask<S: Simd>(
3066		ctx: &Self::SimdCtx<S>,
3067		value: Self::SimdMask<S>,
3068	) -> usize {
3069		T::simd_first_true_mask(ctx, value)
3070	}
3071
3072	#[inline(always)]
3073	fn simd_mem_mask_between<S: Simd>(
3074		ctx: &Self::SimdCtx<S>,
3075		start: Self::Index,
3076		end: Self::Index,
3077	) -> Self::SimdMemMask<S> {
3078		let n = core::mem::size_of::<Self::SimdVec<S>>()
3079			/ core::mem::size_of::<Self>();
3080		let start = start.zx() * 2;
3081		let end = end.zx() * 2;
3082		let mut sa = start.min(n);
3083		let mut ea = end.min(n);
3084		let mut sb = start.max(n) - n;
3085		let mut eb = end.max(n) - n;
3086		if sa == ea {
3087			sa = 0;
3088			ea = 0;
3089		}
3090		if sb == eb {
3091			sb = 0;
3092			eb = 0;
3093		}
3094		let re = T::simd_mem_mask_between(
3095			ctx,
3096			T::Index::truncate(sa),
3097			T::Index::truncate(ea),
3098		);
3099		let im = T::simd_mem_mask_between(
3100			ctx,
3101			T::Index::truncate(sb),
3102			T::Index::truncate(eb),
3103		);
3104		Complex { re, im }
3105	}
3106
3107	#[inline(always)]
3108	fn simd_mask_between<S: Simd>(
3109		ctx: &Self::SimdCtx<S>,
3110		start: Self::Index,
3111		end: Self::Index,
3112	) -> Self::SimdMask<S> {
3113		T::simd_mask_between(ctx, start, end)
3114	}
3115
3116	#[inline(always)]
3117	unsafe fn simd_mask_load_raw<S: Simd>(
3118		ctx: &Self::SimdCtx<S>,
3119		mask: Self::SimdMemMask<S>,
3120		ptr: *const Self::SimdVec<S>,
3121	) -> Self::SimdVec<S> {
3122		Complex {
3123			re: T::simd_mask_load_raw(
3124				ctx,
3125				mask.re,
3126				core::ptr::addr_of!((*ptr).re),
3127			),
3128			im: T::simd_mask_load_raw(
3129				ctx,
3130				mask.im,
3131				core::ptr::addr_of!((*ptr).im),
3132			),
3133		}
3134	}
3135
3136	#[inline(always)]
3137	unsafe fn simd_mask_store_raw<S: Simd>(
3138		ctx: &Self::SimdCtx<S>,
3139		mask: Self::SimdMemMask<S>,
3140		ptr: *mut Self::SimdVec<S>,
3141		values: Self::SimdVec<S>,
3142	) {
3143		T::simd_mask_store_raw(
3144			ctx,
3145			mask.re,
3146			core::ptr::addr_of_mut!((*ptr).re),
3147			values.re,
3148		);
3149		T::simd_mask_store_raw(
3150			ctx,
3151			mask.im,
3152			core::ptr::addr_of_mut!((*ptr).im),
3153			values.im,
3154		);
3155	}
3156}
3157#[repr(transparent)]
3158#[doc(hidden)]
3159#[derive(Copy, Clone, Debug, PartialEq)]
3160pub struct ComplexImpl<T>(Complex<T>);
3161#[repr(transparent)]
3162#[doc(hidden)]
3163#[derive(Copy, Clone, Debug, PartialEq)]
3164pub struct ComplexImplConj<T>(Complex<T>);
3165unsafe impl Conjugate for ComplexImpl<f32> {
3166	type Canonical = ComplexImpl<f32>;
3167	type Conj = ComplexImplConj<f32>;
3168
3169	const IS_CANONICAL: bool = true;
3170}
3171unsafe impl Conjugate for ComplexImplConj<f32> {
3172	type Canonical = ComplexImpl<f32>;
3173	type Conj = ComplexImpl<f32>;
3174
3175	const IS_CANONICAL: bool = false;
3176}
3177unsafe impl Conjugate for ComplexImpl<f64> {
3178	type Canonical = ComplexImpl<f64>;
3179	type Conj = ComplexImplConj<f64>;
3180
3181	const IS_CANONICAL: bool = true;
3182}
3183unsafe impl Conjugate for ComplexImplConj<f64> {
3184	type Canonical = ComplexImpl<f64>;
3185	type Conj = ComplexImpl<f64>;
3186
3187	const IS_CANONICAL: bool = false;
3188}
3189impl<T: RealField> core::ops::Neg for ComplexImpl<T> {
3190	type Output = ComplexImpl<T>;
3191
3192	#[inline]
3193	fn neg(self) -> Self::Output {
3194		use math_utils::*;
3195		ComplexImpl(neg(&self.0))
3196	}
3197}
3198impl<T: RealField> core::ops::Neg for &ComplexImpl<T> {
3199	type Output = ComplexImpl<T>;
3200
3201	#[inline]
3202	fn neg(self) -> Self::Output {
3203		use math_utils::*;
3204		ComplexImpl(neg(&self.0))
3205	}
3206}
3207impl_op!({
3208	impl<T: RealField> Add for ComplexImpl<T> {
3209		fn add(self, rhs: Self) -> Self::Output {
3210			use math_utils::*;
3211			ComplexImpl(add(&self.0, &rhs.0))
3212		}
3213	}
3214	impl<T: RealField> Sub for ComplexImpl<T> {
3215		fn sub(self, rhs: Self) -> Self::Output {
3216			use math_utils::*;
3217			ComplexImpl(sub(&self.0, &rhs.0))
3218		}
3219	}
3220	impl<T: RealField> Mul for ComplexImpl<T> {
3221		fn mul(self, rhs: Self) -> Self::Output {
3222			use math_utils::*;
3223			ComplexImpl(mul(&self.0, &rhs.0))
3224		}
3225	}
3226	impl<T: RealField> Div for ComplexImpl<T> {
3227		fn div(self, rhs: Self) -> Self::Output {
3228			use math_utils::*;
3229			ComplexImpl(div(&self.0, &rhs.0))
3230		}
3231	}
3232});
3233impl_assign_op!({
3234	impl<T: RealField> AddAssign for ComplexImpl<T> {
3235		fn add_assign(&mut self, rhs: Self) {
3236			use math_utils::*;
3237			*self = ComplexImpl(add(&self.0, &rhs.0));
3238		}
3239	}
3240	impl<T: RealField> SubAssign for ComplexImpl<T> {
3241		fn sub_assign(&mut self, rhs: Self) {
3242			use math_utils::*;
3243			*self = ComplexImpl(sub(&self.0, &rhs.0));
3244		}
3245	}
3246	impl<T: RealField> MulAssign for ComplexImpl<T> {
3247		fn mul_assign(&mut self, rhs: Self) {
3248			use math_utils::*;
3249			*self = ComplexImpl(mul(&self.0, &rhs.0));
3250		}
3251	}
3252	impl<T: RealField> DivAssign for ComplexImpl<T> {
3253		fn div_assign(&mut self, rhs: Self) {
3254			use math_utils::*;
3255			*self = ComplexImpl(div(&self.0, &rhs.0));
3256		}
3257	}
3258});
3259impl<T> From<Complex<T>> for ComplexImpl<T> {
3260	#[inline]
3261	fn from(value: Complex<T>) -> Self {
3262		Self(value)
3263	}
3264}
3265impl ComplexField for ComplexImpl<f32> {
3266	type Arch = pulp::Arch;
3267	type Index = u32;
3268	type Real = f32;
3269	type SimdCtx<S: Simd> = S;
3270	type SimdIndex<S: Simd> = S::u32s;
3271	type SimdMask<S: Simd> = S::m32s;
3272	type SimdMemMask<S: Simd> = pulp::MemMask<S::m32s>;
3273	type SimdVec<S: Simd> = S::c32s;
3274	type Unit = f32;
3275
3276	const IS_NATIVE_C32: bool = true;
3277	const IS_REAL: bool = false;
3278	const SIMD_ABS_SPLIT_REAL_IMAG: bool = true;
3279	const SIMD_CAPABILITIES: SimdCapabilities = SimdCapabilities::Simd;
3280
3281	#[inline]
3282	fn zero_impl() -> Self {
3283		Complex {
3284			re: f32::zero_impl(),
3285			im: f32::zero_impl(),
3286		}
3287		.into()
3288	}
3289
3290	#[inline]
3291	fn one_impl() -> Self {
3292		Complex {
3293			re: f32::one_impl(),
3294			im: f32::zero_impl(),
3295		}
3296		.into()
3297	}
3298
3299	#[inline]
3300	fn nan_impl() -> Self {
3301		Complex {
3302			re: f32::nan_impl(),
3303			im: f32::nan_impl(),
3304		}
3305		.into()
3306	}
3307
3308	#[inline]
3309	fn infinity_impl() -> Self {
3310		Complex {
3311			re: f32::infinity_impl(),
3312			im: f32::infinity_impl(),
3313		}
3314		.into()
3315	}
3316
3317	#[inline]
3318	fn from_real_impl(real: &Self::Real) -> Self {
3319		Complex {
3320			re: real.clone(),
3321			im: f32::zero_impl(),
3322		}
3323		.into()
3324	}
3325
3326	#[inline]
3327	fn from_f64_impl(real: f64) -> Self {
3328		Complex {
3329			re: f32::from_f64_impl(real),
3330			im: f32::zero_impl(),
3331		}
3332		.into()
3333	}
3334
3335	#[inline]
3336	fn real_part_impl(value: &Self) -> Self::Real {
3337		value.0.re.clone()
3338	}
3339
3340	#[inline]
3341	fn imag_part_impl(value: &Self) -> Self::Real {
3342		value.0.im.clone()
3343	}
3344
3345	#[inline]
3346	fn copy_impl(value: &Self) -> Self {
3347		value.clone()
3348	}
3349
3350	#[inline]
3351	fn conj_impl(value: &Self) -> Self {
3352		Complex {
3353			re: value.0.re.clone(),
3354			im: value.0.im.neg_by_ref(),
3355		}
3356		.into()
3357	}
3358
3359	#[inline]
3360	fn recip_impl(value: &Self) -> Self {
3361		let (re, im) = recip_impl(value.0.re.clone(), value.0.im.clone());
3362		Complex { re, im }.into()
3363	}
3364
3365	#[inline]
3366	fn sqrt_impl(value: &Self) -> Self {
3367		let (re, im) = sqrt_impl(value.0.re.clone(), value.0.im.clone());
3368		Complex { re, im }.into()
3369	}
3370
3371	#[inline]
3372	fn abs_impl(value: &Self) -> Self::Real {
3373		abs_impl(value.0.re.clone(), value.0.im.clone())
3374	}
3375
3376	#[inline]
3377	fn abs1_impl(value: &Self) -> Self::Real {
3378		use crate::ext::*;
3379		value.0.re.abs1() + value.0.im.abs1()
3380	}
3381
3382	#[inline]
3383	fn abs2_impl(value: &Self) -> Self::Real {
3384		use crate::ext::*;
3385		value.0.re.abs2() + value.0.im.abs2()
3386	}
3387
3388	#[inline]
3389	fn mul_real_impl(lhs: &Self, rhs: &Self::Real) -> Self {
3390		Complex {
3391			re: lhs.0.re * rhs,
3392			im: lhs.0.im * rhs,
3393		}
3394		.into()
3395	}
3396
3397	#[inline]
3398	fn mul_pow2_impl(lhs: &Self, rhs: &Self::Real) -> Self {
3399		use crate::ext::*;
3400		Complex {
3401			re: lhs.0.re.mul_pow2(rhs),
3402			im: lhs.0.im.mul_pow2(rhs),
3403		}
3404		.into()
3405	}
3406
3407	#[inline]
3408	fn is_finite_impl(value: &Self) -> bool {
3409		value.0.re.is_finite() && value.0.im.is_finite()
3410	}
3411
3412	#[inline(always)]
3413	fn simd_ctx<S: Simd>(simd: S) -> Self::SimdCtx<S> {
3414		f32::simd_ctx(simd)
3415	}
3416
3417	#[inline(always)]
3418	fn ctx_from_simd<S: Simd>(ctx: &Self::SimdCtx<S>) -> S {
3419		f32::ctx_from_simd(ctx)
3420	}
3421
3422	#[inline(always)]
3423	fn simd_splat<S: Simd>(
3424		ctx: &Self::SimdCtx<S>,
3425		value: &Self,
3426	) -> Self::SimdVec<S> {
3427		ctx.splat_c32s(value.0)
3428	}
3429
3430	#[inline(always)]
3431	fn simd_splat_real<S: Simd>(
3432		ctx: &Self::SimdCtx<S>,
3433		value: &Self::Real,
3434	) -> Self::SimdVec<S> {
3435		ctx.splat_c32s(Complex {
3436			re: *value,
3437			im: *value,
3438		})
3439	}
3440
3441	#[inline(always)]
3442	fn simd_add<S: Simd>(
3443		ctx: &Self::SimdCtx<S>,
3444		lhs: Self::SimdVec<S>,
3445		rhs: Self::SimdVec<S>,
3446	) -> Self::SimdVec<S> {
3447		ctx.add_c32s(lhs, rhs)
3448	}
3449
3450	#[inline(always)]
3451	fn simd_sub<S: Simd>(
3452		ctx: &Self::SimdCtx<S>,
3453		lhs: Self::SimdVec<S>,
3454		rhs: Self::SimdVec<S>,
3455	) -> Self::SimdVec<S> {
3456		ctx.sub_c32s(lhs, rhs)
3457	}
3458
3459	#[inline(always)]
3460	fn simd_neg<S: Simd>(
3461		ctx: &Self::SimdCtx<S>,
3462		value: Self::SimdVec<S>,
3463	) -> Self::SimdVec<S> {
3464		ctx.neg_c32s(value)
3465	}
3466
3467	#[inline(always)]
3468	fn simd_conj<S: Simd>(
3469		ctx: &Self::SimdCtx<S>,
3470		value: Self::SimdVec<S>,
3471	) -> Self::SimdVec<S> {
3472		ctx.conj_c32s(value)
3473	}
3474
3475	#[inline(always)]
3476	fn simd_abs1<S: Simd>(
3477		ctx: &Self::SimdCtx<S>,
3478		value: Self::SimdVec<S>,
3479	) -> Self::SimdVec<S> {
3480		if const {
3481			core::mem::size_of::<S::c32s>() == core::mem::size_of::<S::f32s>()
3482		} {
3483			bytemuck::cast(ctx.abs_f32s(bytemuck::cast(value)))
3484		} else if const {
3485			core::mem::size_of::<S::c32s>()
3486				== core::mem::size_of::<Complex<f32>>()
3487		} {
3488			let value: Complex<f32> = bytemuck::cast(value);
3489			let v = value.re.abs() + value.im.abs();
3490			bytemuck::cast(Complex { re: v, im: v })
3491		} else {
3492			panic!();
3493		}
3494	}
3495
3496	#[inline(always)]
3497	fn simd_abs_max<S: Simd>(
3498		ctx: &Self::SimdCtx<S>,
3499		value: Self::SimdVec<S>,
3500	) -> Self::SimdVec<S> {
3501		if const {
3502			core::mem::size_of::<S::c32s>() == core::mem::size_of::<S::f32s>()
3503		} {
3504			bytemuck::cast(ctx.abs_f32s(bytemuck::cast(value)))
3505		} else if const {
3506			core::mem::size_of::<S::c32s>()
3507				== core::mem::size_of::<Complex<f32>>()
3508		} {
3509			let value: Complex<f32> = bytemuck::cast(value);
3510			let re = value.re.abs();
3511			let im = value.im.abs();
3512			let v = if re > im { re } else { im };
3513			bytemuck::cast(Complex { re: v, im: v })
3514		} else {
3515			panic!();
3516		}
3517	}
3518
3519	#[inline(always)]
3520	fn simd_mul_real<S: Simd>(
3521		ctx: &Self::SimdCtx<S>,
3522		lhs: Self::SimdVec<S>,
3523		real_rhs: Self::SimdVec<S>,
3524	) -> Self::SimdVec<S> {
3525		if const {
3526			core::mem::size_of::<S::c32s>() == core::mem::size_of::<S::f32s>()
3527		} {
3528			bytemuck::cast(
3529				ctx.mul_f32s(bytemuck::cast(lhs), bytemuck::cast(real_rhs)),
3530			)
3531		} else if const {
3532			core::mem::size_of::<S::c32s>()
3533				== core::mem::size_of::<Complex<f32>>()
3534		} {
3535			let mut lhs: Complex<f32> = bytemuck::cast(lhs);
3536			let rhs: Complex<f32> = bytemuck::cast(real_rhs);
3537			lhs *= rhs.re;
3538			bytemuck::cast(lhs)
3539		} else {
3540			panic!();
3541		}
3542	}
3543
3544	#[inline(always)]
3545	fn simd_mul_pow2<S: Simd>(
3546		ctx: &Self::SimdCtx<S>,
3547		lhs: Self::SimdVec<S>,
3548		real_rhs: Self::SimdVec<S>,
3549	) -> Self::SimdVec<S> {
3550		Self::simd_mul_real(ctx, lhs, real_rhs)
3551	}
3552
3553	#[inline(always)]
3554	fn simd_mul<S: Simd>(
3555		ctx: &Self::SimdCtx<S>,
3556		lhs: Self::SimdVec<S>,
3557		rhs: Self::SimdVec<S>,
3558	) -> Self::SimdVec<S> {
3559		ctx.mul_e_c32s(lhs, rhs)
3560	}
3561
3562	#[inline(always)]
3563	fn simd_conj_mul<S: Simd>(
3564		ctx: &Self::SimdCtx<S>,
3565		lhs: Self::SimdVec<S>,
3566		rhs: Self::SimdVec<S>,
3567	) -> Self::SimdVec<S> {
3568		ctx.conj_mul_e_c32s(lhs, rhs)
3569	}
3570
3571	#[inline(always)]
3572	fn simd_mul_add<S: Simd>(
3573		ctx: &Self::SimdCtx<S>,
3574		lhs: Self::SimdVec<S>,
3575		rhs: Self::SimdVec<S>,
3576		acc: Self::SimdVec<S>,
3577	) -> Self::SimdVec<S> {
3578		ctx.mul_add_e_c32s(lhs, rhs, acc)
3579	}
3580
3581	#[inline(always)]
3582	fn simd_conj_mul_add<S: Simd>(
3583		ctx: &Self::SimdCtx<S>,
3584		lhs: Self::SimdVec<S>,
3585		rhs: Self::SimdVec<S>,
3586		acc: Self::SimdVec<S>,
3587	) -> Self::SimdVec<S> {
3588		ctx.conj_mul_add_e_c32s(lhs, rhs, acc)
3589	}
3590
3591	#[inline(always)]
3592	fn simd_abs2<S: Simd>(
3593		ctx: &Self::SimdCtx<S>,
3594		value: Self::SimdVec<S>,
3595	) -> Self::SimdVec<S> {
3596		if const {
3597			core::mem::size_of::<S::c32s>() == core::mem::size_of::<S::f32s>()
3598		} {
3599			bytemuck::cast(
3600				ctx.mul_f32s(bytemuck::cast(value), bytemuck::cast(value)),
3601			)
3602		} else if const {
3603			core::mem::size_of::<S::c32s>()
3604				== core::mem::size_of::<Complex<f32>>()
3605		} {
3606			let value: Complex<f32> = bytemuck::cast(value);
3607			let v = value.re * value.re + value.im * value.im;
3608			bytemuck::cast(Complex { re: v, im: v })
3609		} else {
3610			panic!();
3611		}
3612	}
3613
3614	#[inline(always)]
3615	fn simd_abs2_add<S: Simd>(
3616		ctx: &Self::SimdCtx<S>,
3617		value: Self::SimdVec<S>,
3618		acc: Self::SimdVec<S>,
3619	) -> Self::SimdVec<S> {
3620		if const {
3621			core::mem::size_of::<S::c32s>() == core::mem::size_of::<S::f32s>()
3622		} {
3623			bytemuck::cast(ctx.mul_add_f32s(
3624				bytemuck::cast(value),
3625				bytemuck::cast(value),
3626				bytemuck::cast(acc),
3627			))
3628		} else if const {
3629			core::mem::size_of::<S::c32s>()
3630				== core::mem::size_of::<Complex<f32>>()
3631		} {
3632			let value: Complex<f32> = bytemuck::cast(value);
3633			let acc: Complex<f32> = bytemuck::cast(acc);
3634			let v = value.re * value.re + value.im * value.im + acc.re;
3635			bytemuck::cast(Complex { re: v, im: v })
3636		} else {
3637			panic!();
3638		}
3639	}
3640
3641	#[inline(always)]
3642	fn simd_reduce_sum<S: Simd>(
3643		ctx: &Self::SimdCtx<S>,
3644		value: Self::SimdVec<S>,
3645	) -> Self {
3646		ctx.reduce_sum_c32s(value).into()
3647	}
3648
3649	#[inline(always)]
3650	fn simd_reduce_max<S: Simd>(
3651		ctx: &Self::SimdCtx<S>,
3652		value: Self::SimdVec<S>,
3653	) -> Self {
3654		ctx.reduce_max_c32s(value).into()
3655	}
3656
3657	#[inline(always)]
3658	fn simd_equal<S: Simd>(
3659		_: &Self::SimdCtx<S>,
3660		_: Self::SimdVec<S>,
3661		_: Self::SimdVec<S>,
3662	) -> Self::SimdMask<S> {
3663		panic!()
3664	}
3665
3666	#[inline(always)]
3667	fn simd_less_than<S: Simd>(
3668		ctx: &Self::SimdCtx<S>,
3669		real_lhs: Self::SimdVec<S>,
3670		real_rhs: Self::SimdVec<S>,
3671	) -> Self::SimdMask<S> {
3672		if const {
3673			core::mem::size_of::<S::c32s>() == core::mem::size_of::<S::f32s>()
3674		} {
3675			ctx.less_than_f32s(
3676				bytemuck::cast(real_lhs),
3677				bytemuck::cast(real_rhs),
3678			)
3679		} else if const {
3680			core::mem::size_of::<S::c32s>()
3681				== core::mem::size_of::<Complex<f32>>()
3682		} {
3683			assert!(
3684				const {
3685					core::mem::size_of::<S::m32s>()
3686						== core::mem::size_of::<bool>()
3687				}
3688			);
3689			let lhs: Complex<f32> = bytemuck::cast(real_lhs);
3690			let rhs: Complex<f32> = bytemuck::cast(real_rhs);
3691			unsafe { core::mem::transmute_copy(&(lhs.re < rhs.re)) }
3692		} else {
3693			panic!();
3694		}
3695	}
3696
3697	#[inline(always)]
3698	fn simd_less_than_or_equal<S: Simd>(
3699		ctx: &Self::SimdCtx<S>,
3700		real_lhs: Self::SimdVec<S>,
3701		real_rhs: Self::SimdVec<S>,
3702	) -> Self::SimdMask<S> {
3703		if const {
3704			core::mem::size_of::<S::c32s>() == core::mem::size_of::<S::f32s>()
3705		} {
3706			ctx.less_than_or_equal_f32s(
3707				bytemuck::cast(real_lhs),
3708				bytemuck::cast(real_rhs),
3709			)
3710		} else if const {
3711			core::mem::size_of::<S::c32s>()
3712				== core::mem::size_of::<Complex<f32>>()
3713		} {
3714			assert!(
3715				const {
3716					core::mem::size_of::<S::m32s>()
3717						== core::mem::size_of::<bool>()
3718				}
3719			);
3720			let lhs: Complex<f32> = bytemuck::cast(real_lhs);
3721			let rhs: Complex<f32> = bytemuck::cast(real_rhs);
3722			unsafe { core::mem::transmute_copy(&(lhs.re <= rhs.re)) }
3723		} else {
3724			panic!();
3725		}
3726	}
3727
3728	#[inline(always)]
3729	fn simd_greater_than<S: Simd>(
3730		ctx: &Self::SimdCtx<S>,
3731		real_lhs: Self::SimdVec<S>,
3732		real_rhs: Self::SimdVec<S>,
3733	) -> Self::SimdMask<S> {
3734		if const {
3735			core::mem::size_of::<S::c32s>() == core::mem::size_of::<S::f32s>()
3736		} {
3737			ctx.greater_than_f32s(
3738				bytemuck::cast(real_lhs),
3739				bytemuck::cast(real_rhs),
3740			)
3741		} else if const {
3742			core::mem::size_of::<S::c32s>()
3743				== core::mem::size_of::<Complex<f32>>()
3744		} {
3745			assert!(
3746				const {
3747					core::mem::size_of::<S::m32s>()
3748						== core::mem::size_of::<bool>()
3749				}
3750			);
3751			let lhs: Complex<f32> = bytemuck::cast(real_lhs);
3752			let rhs: Complex<f32> = bytemuck::cast(real_rhs);
3753			unsafe { core::mem::transmute_copy(&(lhs.re > rhs.re)) }
3754		} else {
3755			panic!();
3756		}
3757	}
3758
3759	#[inline(always)]
3760	fn simd_greater_than_or_equal<S: Simd>(
3761		ctx: &Self::SimdCtx<S>,
3762		real_lhs: Self::SimdVec<S>,
3763		real_rhs: Self::SimdVec<S>,
3764	) -> Self::SimdMask<S> {
3765		if const {
3766			core::mem::size_of::<S::c32s>() == core::mem::size_of::<S::f32s>()
3767		} {
3768			ctx.greater_than_or_equal_f32s(
3769				bytemuck::cast(real_lhs),
3770				bytemuck::cast(real_rhs),
3771			)
3772		} else if const {
3773			core::mem::size_of::<S::c32s>()
3774				== core::mem::size_of::<Complex<f32>>()
3775		} {
3776			assert!(
3777				const {
3778					core::mem::size_of::<S::m32s>()
3779						== core::mem::size_of::<bool>()
3780				}
3781			);
3782			let lhs: Complex<f32> = bytemuck::cast(real_lhs);
3783			let rhs: Complex<f32> = bytemuck::cast(real_rhs);
3784			unsafe { core::mem::transmute_copy(&(lhs.re >= rhs.re)) }
3785		} else {
3786			panic!();
3787		}
3788	}
3789
3790	#[inline(always)]
3791	fn simd_select<S: Simd>(
3792		ctx: &Self::SimdCtx<S>,
3793		mask: Self::SimdMask<S>,
3794		lhs: Self::SimdVec<S>,
3795		rhs: Self::SimdVec<S>,
3796	) -> Self::SimdVec<S> {
3797		if const {
3798			core::mem::size_of::<S::c32s>() == core::mem::size_of::<S::f32s>()
3799		} {
3800			bytemuck::cast(ctx.select_f32s(
3801				mask,
3802				bytemuck::cast(lhs),
3803				bytemuck::cast(rhs),
3804			))
3805		} else if const {
3806			core::mem::size_of::<S::c32s>()
3807				== core::mem::size_of::<Complex<f32>>()
3808		} {
3809			assert!(
3810				const {
3811					core::mem::size_of::<S::m32s>()
3812						== core::mem::size_of::<bool>()
3813				}
3814			);
3815			let mask: bool = unsafe { core::mem::transmute_copy(&mask) };
3816			let lhs: Complex<f32> = bytemuck::cast(lhs);
3817			let rhs: Complex<f32> = bytemuck::cast(rhs);
3818			bytemuck::cast(if mask { lhs } else { rhs })
3819		} else {
3820			panic!();
3821		}
3822	}
3823
3824	#[inline(always)]
3825	fn simd_index_select<S: Simd>(
3826		ctx: &Self::SimdCtx<S>,
3827		mask: Self::SimdMask<S>,
3828		lhs: Self::SimdIndex<S>,
3829		rhs: Self::SimdIndex<S>,
3830	) -> Self::SimdIndex<S> {
3831		f32::simd_index_select(ctx, mask, lhs, rhs)
3832	}
3833
3834	#[inline(always)]
3835	fn simd_index_splat<S: Simd>(
3836		ctx: &Self::SimdCtx<S>,
3837		value: Self::Index,
3838	) -> Self::SimdIndex<S> {
3839		f32::simd_index_splat(ctx, value)
3840	}
3841
3842	#[inline(always)]
3843	fn simd_index_add<S: Simd>(
3844		ctx: &Self::SimdCtx<S>,
3845		lhs: Self::SimdIndex<S>,
3846		rhs: Self::SimdIndex<S>,
3847	) -> Self::SimdIndex<S> {
3848		f32::simd_index_add(ctx, lhs, rhs)
3849	}
3850
3851	#[inline(always)]
3852	fn simd_index_less_than<S: Simd>(
3853		ctx: &Self::SimdCtx<S>,
3854		lhs: Self::SimdIndex<S>,
3855		rhs: Self::SimdIndex<S>,
3856	) -> Self::SimdMask<S> {
3857		f32::simd_index_less_than(ctx, lhs, rhs)
3858	}
3859
3860	#[inline(always)]
3861	fn simd_and_mask<S: Simd>(
3862		ctx: &Self::SimdCtx<S>,
3863		lhs: Self::SimdMask<S>,
3864		rhs: Self::SimdMask<S>,
3865	) -> Self::SimdMask<S> {
3866		f32::simd_and_mask(ctx, lhs, rhs)
3867	}
3868
3869	#[inline(always)]
3870	fn simd_or_mask<S: Simd>(
3871		ctx: &Self::SimdCtx<S>,
3872		lhs: Self::SimdMask<S>,
3873		rhs: Self::SimdMask<S>,
3874	) -> Self::SimdMask<S> {
3875		f32::simd_or_mask(ctx, lhs, rhs)
3876	}
3877
3878	#[inline(always)]
3879	fn simd_not_mask<S: Simd>(
3880		ctx: &Self::SimdCtx<S>,
3881		mask: Self::SimdMask<S>,
3882	) -> Self::SimdMask<S> {
3883		f32::simd_not_mask(ctx, mask)
3884	}
3885
3886	#[inline(always)]
3887	fn simd_first_true_mask<S: Simd>(
3888		ctx: &Self::SimdCtx<S>,
3889		value: Self::SimdMask<S>,
3890	) -> usize {
3891		f32::simd_first_true_mask(ctx, value)
3892	}
3893
3894	#[inline(always)]
3895	fn simd_mem_mask_between<S: Simd>(
3896		ctx: &Self::SimdCtx<S>,
3897		start: Self::Index,
3898		end: Self::Index,
3899	) -> Self::SimdMemMask<S> {
3900		ctx.mask_between_m32s((2 * start) as _, (2 * end) as _)
3901	}
3902
3903	#[inline(always)]
3904	fn simd_mask_between<S: Simd>(
3905		ctx: &Self::SimdCtx<S>,
3906		start: Self::Index,
3907		end: Self::Index,
3908	) -> Self::SimdMask<S> {
3909		ctx.mask_between_m32s((2 * start) as _, (2 * end) as _)
3910			.mask()
3911	}
3912
3913	#[inline(always)]
3914	unsafe fn simd_mask_load_raw<S: Simd>(
3915		ctx: &Self::SimdCtx<S>,
3916		mask: Self::SimdMemMask<S>,
3917		ptr: *const Self::SimdVec<S>,
3918	) -> Self::SimdVec<S> {
3919		ctx.mask_load_ptr_c32s(mask, ptr as _)
3920	}
3921
3922	#[inline(always)]
3923	unsafe fn simd_mask_store_raw<S: Simd>(
3924		ctx: &Self::SimdCtx<S>,
3925		mask: Self::SimdMemMask<S>,
3926		ptr: *mut Self::SimdVec<S>,
3927		values: Self::SimdVec<S>,
3928	) {
3929		ctx.mask_store_ptr_c32s(mask, ptr as _, values);
3930	}
3931}
3932impl ComplexField for ComplexImpl<f64> {
3933	type Arch = pulp::Arch;
3934	type Index = u64;
3935	type Real = f64;
3936	type SimdCtx<S: Simd> = S;
3937	type SimdIndex<S: Simd> = S::u64s;
3938	type SimdMask<S: Simd> = S::m64s;
3939	type SimdMemMask<S: Simd> = pulp::MemMask<S::m64s>;
3940	type SimdVec<S: Simd> = S::c64s;
3941	type Unit = f64;
3942
3943	const IS_NATIVE_C64: bool = true;
3944	const IS_REAL: bool = false;
3945	const SIMD_ABS_SPLIT_REAL_IMAG: bool = true;
3946	const SIMD_CAPABILITIES: SimdCapabilities = SimdCapabilities::Simd;
3947
3948	#[inline]
3949	fn zero_impl() -> Self {
3950		Complex {
3951			re: f64::zero_impl(),
3952			im: f64::zero_impl(),
3953		}
3954		.into()
3955	}
3956
3957	#[inline]
3958	fn one_impl() -> Self {
3959		Complex {
3960			re: f64::one_impl(),
3961			im: f64::zero_impl(),
3962		}
3963		.into()
3964	}
3965
3966	#[inline]
3967	fn nan_impl() -> Self {
3968		Complex {
3969			re: f64::nan_impl(),
3970			im: f64::nan_impl(),
3971		}
3972		.into()
3973	}
3974
3975	#[inline]
3976	fn infinity_impl() -> Self {
3977		Complex {
3978			re: f64::infinity_impl(),
3979			im: f64::infinity_impl(),
3980		}
3981		.into()
3982	}
3983
3984	#[inline]
3985	fn from_real_impl(real: &Self::Real) -> Self {
3986		Complex {
3987			re: real.clone(),
3988			im: f64::zero_impl(),
3989		}
3990		.into()
3991	}
3992
3993	#[inline]
3994	fn from_f64_impl(real: f64) -> Self {
3995		Complex {
3996			re: f64::from_f64_impl(real),
3997			im: f64::zero_impl(),
3998		}
3999		.into()
4000	}
4001
4002	#[inline]
4003	fn real_part_impl(value: &Self) -> Self::Real {
4004		value.0.re.clone()
4005	}
4006
4007	#[inline]
4008	fn imag_part_impl(value: &Self) -> Self::Real {
4009		value.0.im.clone()
4010	}
4011
4012	#[inline]
4013	fn copy_impl(value: &Self) -> Self {
4014		value.clone()
4015	}
4016
4017	#[inline]
4018	fn conj_impl(value: &Self) -> Self {
4019		Complex {
4020			re: value.0.re.clone(),
4021			im: value.0.im.neg_by_ref(),
4022		}
4023		.into()
4024	}
4025
4026	#[inline]
4027	fn recip_impl(value: &Self) -> Self {
4028		let (re, im) = recip_impl(value.0.re.clone(), value.0.im.clone());
4029		Complex { re, im }.into()
4030	}
4031
4032	#[inline]
4033	fn sqrt_impl(value: &Self) -> Self {
4034		let (re, im) = sqrt_impl(value.0.re.clone(), value.0.im.clone());
4035		Complex { re, im }.into()
4036	}
4037
4038	#[inline]
4039	fn abs_impl(value: &Self) -> Self::Real {
4040		abs_impl(value.0.re.clone(), value.0.im.clone())
4041	}
4042
4043	#[inline]
4044	fn abs1_impl(value: &Self) -> Self::Real {
4045		use crate::ext::*;
4046		value.0.re.abs1() + value.0.im.abs1()
4047	}
4048
4049	#[inline]
4050	fn abs2_impl(value: &Self) -> Self::Real {
4051		use crate::ext::*;
4052		value.0.re.abs2() + value.0.im.abs2()
4053	}
4054
4055	#[inline]
4056	fn mul_real_impl(lhs: &Self, rhs: &Self::Real) -> Self {
4057		Complex {
4058			re: lhs.0.re * rhs,
4059			im: lhs.0.im * rhs,
4060		}
4061		.into()
4062	}
4063
4064	#[inline]
4065	fn mul_pow2_impl(lhs: &Self, rhs: &Self::Real) -> Self {
4066		use crate::ext::*;
4067		Complex {
4068			re: lhs.0.re.mul_pow2(rhs),
4069			im: lhs.0.im.mul_pow2(rhs),
4070		}
4071		.into()
4072	}
4073
4074	#[inline]
4075	fn is_finite_impl(value: &Self) -> bool {
4076		value.0.re.is_finite() && value.0.im.is_finite()
4077	}
4078
4079	#[inline(always)]
4080	fn simd_ctx<S: Simd>(simd: S) -> Self::SimdCtx<S> {
4081		f64::simd_ctx(simd)
4082	}
4083
4084	#[inline(always)]
4085	fn ctx_from_simd<S: Simd>(ctx: &Self::SimdCtx<S>) -> S {
4086		f64::ctx_from_simd(ctx)
4087	}
4088
4089	#[inline(always)]
4090	fn simd_splat<S: Simd>(
4091		ctx: &Self::SimdCtx<S>,
4092		value: &Self,
4093	) -> Self::SimdVec<S> {
4094		ctx.splat_c64s(value.0)
4095	}
4096
4097	#[inline(always)]
4098	fn simd_splat_real<S: Simd>(
4099		ctx: &Self::SimdCtx<S>,
4100		value: &Self::Real,
4101	) -> Self::SimdVec<S> {
4102		ctx.splat_c64s(Complex {
4103			re: *value,
4104			im: *value,
4105		})
4106	}
4107
4108	#[inline(always)]
4109	fn simd_add<S: Simd>(
4110		ctx: &Self::SimdCtx<S>,
4111		lhs: Self::SimdVec<S>,
4112		rhs: Self::SimdVec<S>,
4113	) -> Self::SimdVec<S> {
4114		ctx.add_c64s(lhs, rhs)
4115	}
4116
4117	#[inline(always)]
4118	fn simd_sub<S: Simd>(
4119		ctx: &Self::SimdCtx<S>,
4120		lhs: Self::SimdVec<S>,
4121		rhs: Self::SimdVec<S>,
4122	) -> Self::SimdVec<S> {
4123		ctx.sub_c64s(lhs, rhs)
4124	}
4125
4126	#[inline(always)]
4127	fn simd_neg<S: Simd>(
4128		ctx: &Self::SimdCtx<S>,
4129		value: Self::SimdVec<S>,
4130	) -> Self::SimdVec<S> {
4131		ctx.neg_c64s(value)
4132	}
4133
4134	#[inline(always)]
4135	fn simd_conj<S: Simd>(
4136		ctx: &Self::SimdCtx<S>,
4137		value: Self::SimdVec<S>,
4138	) -> Self::SimdVec<S> {
4139		ctx.conj_c64s(value)
4140	}
4141
4142	#[inline(always)]
4143	fn simd_abs1<S: Simd>(
4144		ctx: &Self::SimdCtx<S>,
4145		value: Self::SimdVec<S>,
4146	) -> Self::SimdVec<S> {
4147		if const {
4148			core::mem::size_of::<S::c64s>() == core::mem::size_of::<S::f64s>()
4149		} {
4150			bytemuck::cast(ctx.abs_f64s(bytemuck::cast(value)))
4151		} else if const {
4152			core::mem::size_of::<S::c64s>()
4153				== core::mem::size_of::<Complex<f64>>()
4154		} {
4155			let value: Complex<f64> = bytemuck::cast(value);
4156			let v = value.re.abs() + value.im.abs();
4157			bytemuck::cast(Complex { re: v, im: v })
4158		} else {
4159			panic!();
4160		}
4161	}
4162
4163	#[inline(always)]
4164	fn simd_abs_max<S: Simd>(
4165		ctx: &Self::SimdCtx<S>,
4166		value: Self::SimdVec<S>,
4167	) -> Self::SimdVec<S> {
4168		if const {
4169			core::mem::size_of::<S::c64s>() == core::mem::size_of::<S::f64s>()
4170		} {
4171			bytemuck::cast(ctx.abs_f64s(bytemuck::cast(value)))
4172		} else if const {
4173			core::mem::size_of::<S::c64s>()
4174				== core::mem::size_of::<Complex<f64>>()
4175		} {
4176			let value: Complex<f64> = bytemuck::cast(value);
4177			let re = value.re.abs();
4178			let im = value.im.abs();
4179			let v = if re > im { re } else { im };
4180			bytemuck::cast(Complex { re: v, im: v })
4181		} else {
4182			panic!();
4183		}
4184	}
4185
4186	#[inline(always)]
4187	fn simd_mul_real<S: Simd>(
4188		ctx: &Self::SimdCtx<S>,
4189		lhs: Self::SimdVec<S>,
4190		real_rhs: Self::SimdVec<S>,
4191	) -> Self::SimdVec<S> {
4192		if const {
4193			core::mem::size_of::<S::c64s>() == core::mem::size_of::<S::f64s>()
4194		} {
4195			bytemuck::cast(
4196				ctx.mul_f64s(bytemuck::cast(lhs), bytemuck::cast(real_rhs)),
4197			)
4198		} else if const {
4199			core::mem::size_of::<S::c64s>()
4200				== core::mem::size_of::<Complex<f64>>()
4201		} {
4202			let mut lhs: Complex<f64> = bytemuck::cast(lhs);
4203			let rhs: Complex<f64> = bytemuck::cast(real_rhs);
4204			lhs *= rhs.re;
4205			bytemuck::cast(lhs)
4206		} else {
4207			panic!();
4208		}
4209	}
4210
4211	#[inline(always)]
4212	fn simd_mul_pow2<S: Simd>(
4213		ctx: &Self::SimdCtx<S>,
4214		lhs: Self::SimdVec<S>,
4215		real_rhs: Self::SimdVec<S>,
4216	) -> Self::SimdVec<S> {
4217		Self::simd_mul_real(ctx, lhs, real_rhs)
4218	}
4219
4220	#[inline(always)]
4221	fn simd_mul<S: Simd>(
4222		ctx: &Self::SimdCtx<S>,
4223		lhs: Self::SimdVec<S>,
4224		rhs: Self::SimdVec<S>,
4225	) -> Self::SimdVec<S> {
4226		ctx.mul_e_c64s(lhs, rhs)
4227	}
4228
4229	#[inline(always)]
4230	fn simd_conj_mul<S: Simd>(
4231		ctx: &Self::SimdCtx<S>,
4232		lhs: Self::SimdVec<S>,
4233		rhs: Self::SimdVec<S>,
4234	) -> Self::SimdVec<S> {
4235		ctx.conj_mul_e_c64s(lhs, rhs)
4236	}
4237
4238	#[inline(always)]
4239	fn simd_mul_add<S: Simd>(
4240		ctx: &Self::SimdCtx<S>,
4241		lhs: Self::SimdVec<S>,
4242		rhs: Self::SimdVec<S>,
4243		acc: Self::SimdVec<S>,
4244	) -> Self::SimdVec<S> {
4245		ctx.mul_add_e_c64s(lhs, rhs, acc)
4246	}
4247
4248	#[inline(always)]
4249	fn simd_conj_mul_add<S: Simd>(
4250		ctx: &Self::SimdCtx<S>,
4251		lhs: Self::SimdVec<S>,
4252		rhs: Self::SimdVec<S>,
4253		acc: Self::SimdVec<S>,
4254	) -> Self::SimdVec<S> {
4255		ctx.conj_mul_add_e_c64s(lhs, rhs, acc)
4256	}
4257
4258	#[inline(always)]
4259	fn simd_abs2<S: Simd>(
4260		ctx: &Self::SimdCtx<S>,
4261		value: Self::SimdVec<S>,
4262	) -> Self::SimdVec<S> {
4263		if const {
4264			core::mem::size_of::<S::c64s>() == core::mem::size_of::<S::f64s>()
4265		} {
4266			bytemuck::cast(
4267				ctx.mul_f64s(bytemuck::cast(value), bytemuck::cast(value)),
4268			)
4269		} else if const {
4270			core::mem::size_of::<S::c64s>()
4271				== core::mem::size_of::<Complex<f64>>()
4272		} {
4273			let value: Complex<f64> = bytemuck::cast(value);
4274			let v = value.re * value.re + value.im * value.im;
4275			bytemuck::cast(Complex { re: v, im: v })
4276		} else {
4277			panic!();
4278		}
4279	}
4280
4281	#[inline(always)]
4282	fn simd_abs2_add<S: Simd>(
4283		ctx: &Self::SimdCtx<S>,
4284		value: Self::SimdVec<S>,
4285		acc: Self::SimdVec<S>,
4286	) -> Self::SimdVec<S> {
4287		if const {
4288			core::mem::size_of::<S::c64s>() == core::mem::size_of::<S::f64s>()
4289		} {
4290			bytemuck::cast(ctx.mul_add_f64s(
4291				bytemuck::cast(value),
4292				bytemuck::cast(value),
4293				bytemuck::cast(acc),
4294			))
4295		} else if const {
4296			core::mem::size_of::<S::c64s>()
4297				== core::mem::size_of::<Complex<f64>>()
4298		} {
4299			let value: Complex<f64> = bytemuck::cast(value);
4300			let acc: Complex<f64> = bytemuck::cast(acc);
4301			let v = value.re * value.re + value.im * value.im + acc.re;
4302			bytemuck::cast(Complex { re: v, im: v })
4303		} else {
4304			panic!();
4305		}
4306	}
4307
4308	#[inline(always)]
4309	fn simd_reduce_sum<S: Simd>(
4310		ctx: &Self::SimdCtx<S>,
4311		value: Self::SimdVec<S>,
4312	) -> Self {
4313		ctx.reduce_sum_c64s(value).into()
4314	}
4315
4316	#[inline(always)]
4317	fn simd_reduce_max<S: Simd>(
4318		ctx: &Self::SimdCtx<S>,
4319		value: Self::SimdVec<S>,
4320	) -> Self {
4321		ctx.reduce_max_c64s(value).into()
4322	}
4323
4324	#[inline(always)]
4325	fn simd_equal<S: Simd>(
4326		_: &Self::SimdCtx<S>,
4327		_: Self::SimdVec<S>,
4328		_: Self::SimdVec<S>,
4329	) -> Self::SimdMask<S> {
4330		panic!()
4331	}
4332
4333	#[inline(always)]
4334	fn simd_less_than<S: Simd>(
4335		ctx: &Self::SimdCtx<S>,
4336		real_lhs: Self::SimdVec<S>,
4337		real_rhs: Self::SimdVec<S>,
4338	) -> Self::SimdMask<S> {
4339		if const {
4340			core::mem::size_of::<S::c64s>() == core::mem::size_of::<S::f64s>()
4341		} {
4342			ctx.less_than_f64s(
4343				bytemuck::cast(real_lhs),
4344				bytemuck::cast(real_rhs),
4345			)
4346		} else if const {
4347			core::mem::size_of::<S::c64s>()
4348				== core::mem::size_of::<Complex<f64>>()
4349		} {
4350			assert!(
4351				const {
4352					core::mem::size_of::<S::m64s>()
4353						== core::mem::size_of::<bool>()
4354				}
4355			);
4356			let lhs: Complex<f64> = bytemuck::cast(real_lhs);
4357			let rhs: Complex<f64> = bytemuck::cast(real_rhs);
4358			unsafe { core::mem::transmute_copy(&(lhs.re < rhs.re)) }
4359		} else {
4360			panic!();
4361		}
4362	}
4363
4364	#[inline(always)]
4365	fn simd_less_than_or_equal<S: Simd>(
4366		ctx: &Self::SimdCtx<S>,
4367		real_lhs: Self::SimdVec<S>,
4368		real_rhs: Self::SimdVec<S>,
4369	) -> Self::SimdMask<S> {
4370		if const {
4371			core::mem::size_of::<S::c64s>() == core::mem::size_of::<S::f64s>()
4372		} {
4373			ctx.less_than_or_equal_f64s(
4374				bytemuck::cast(real_lhs),
4375				bytemuck::cast(real_rhs),
4376			)
4377		} else if const {
4378			core::mem::size_of::<S::c64s>()
4379				== core::mem::size_of::<Complex<f64>>()
4380		} {
4381			assert!(
4382				const {
4383					core::mem::size_of::<S::m64s>()
4384						== core::mem::size_of::<bool>()
4385				}
4386			);
4387			let lhs: Complex<f64> = bytemuck::cast(real_lhs);
4388			let rhs: Complex<f64> = bytemuck::cast(real_rhs);
4389			unsafe { core::mem::transmute_copy(&(lhs.re <= rhs.re)) }
4390		} else {
4391			panic!();
4392		}
4393	}
4394
4395	#[inline(always)]
4396	fn simd_greater_than<S: Simd>(
4397		ctx: &Self::SimdCtx<S>,
4398		real_lhs: Self::SimdVec<S>,
4399		real_rhs: Self::SimdVec<S>,
4400	) -> Self::SimdMask<S> {
4401		if const {
4402			core::mem::size_of::<S::c64s>() == core::mem::size_of::<S::f64s>()
4403		} {
4404			ctx.greater_than_f64s(
4405				bytemuck::cast(real_lhs),
4406				bytemuck::cast(real_rhs),
4407			)
4408		} else if const {
4409			core::mem::size_of::<S::c64s>()
4410				== core::mem::size_of::<Complex<f64>>()
4411		} {
4412			assert!(
4413				const {
4414					core::mem::size_of::<S::m64s>()
4415						== core::mem::size_of::<bool>()
4416				}
4417			);
4418			let lhs: Complex<f64> = bytemuck::cast(real_lhs);
4419			let rhs: Complex<f64> = bytemuck::cast(real_rhs);
4420			unsafe { core::mem::transmute_copy(&(lhs.re > rhs.re)) }
4421		} else {
4422			panic!();
4423		}
4424	}
4425
4426	#[inline(always)]
4427	fn simd_greater_than_or_equal<S: Simd>(
4428		ctx: &Self::SimdCtx<S>,
4429		real_lhs: Self::SimdVec<S>,
4430		real_rhs: Self::SimdVec<S>,
4431	) -> Self::SimdMask<S> {
4432		if const {
4433			core::mem::size_of::<S::c64s>() == core::mem::size_of::<S::f64s>()
4434		} {
4435			ctx.greater_than_or_equal_f64s(
4436				bytemuck::cast(real_lhs),
4437				bytemuck::cast(real_rhs),
4438			)
4439		} else if const {
4440			core::mem::size_of::<S::c64s>()
4441				== core::mem::size_of::<Complex<f64>>()
4442		} {
4443			assert!(
4444				const {
4445					core::mem::size_of::<S::m64s>()
4446						== core::mem::size_of::<bool>()
4447				}
4448			);
4449			let lhs: Complex<f64> = bytemuck::cast(real_lhs);
4450			let rhs: Complex<f64> = bytemuck::cast(real_rhs);
4451			unsafe { core::mem::transmute_copy(&(lhs.re >= rhs.re)) }
4452		} else {
4453			panic!();
4454		}
4455	}
4456
4457	#[inline(always)]
4458	fn simd_select<S: Simd>(
4459		ctx: &Self::SimdCtx<S>,
4460		mask: Self::SimdMask<S>,
4461		lhs: Self::SimdVec<S>,
4462		rhs: Self::SimdVec<S>,
4463	) -> Self::SimdVec<S> {
4464		if const {
4465			core::mem::size_of::<S::c64s>() == core::mem::size_of::<S::f64s>()
4466		} {
4467			bytemuck::cast(ctx.select_f64s(
4468				mask,
4469				bytemuck::cast(lhs),
4470				bytemuck::cast(rhs),
4471			))
4472		} else if const {
4473			core::mem::size_of::<S::c64s>()
4474				== core::mem::size_of::<Complex<f64>>()
4475		} {
4476			assert!(
4477				const {
4478					core::mem::size_of::<S::m64s>()
4479						== core::mem::size_of::<bool>()
4480				}
4481			);
4482			let mask: bool = unsafe { core::mem::transmute_copy(&mask) };
4483			let lhs: Complex<f64> = bytemuck::cast(lhs);
4484			let rhs: Complex<f64> = bytemuck::cast(rhs);
4485			bytemuck::cast(if mask { lhs } else { rhs })
4486		} else {
4487			panic!();
4488		}
4489	}
4490
4491	#[inline(always)]
4492	fn simd_index_select<S: Simd>(
4493		ctx: &Self::SimdCtx<S>,
4494		mask: Self::SimdMask<S>,
4495		lhs: Self::SimdIndex<S>,
4496		rhs: Self::SimdIndex<S>,
4497	) -> Self::SimdIndex<S> {
4498		f64::simd_index_select(ctx, mask, lhs, rhs)
4499	}
4500
4501	#[inline(always)]
4502	fn simd_index_splat<S: Simd>(
4503		ctx: &Self::SimdCtx<S>,
4504		value: Self::Index,
4505	) -> Self::SimdIndex<S> {
4506		f64::simd_index_splat(ctx, value)
4507	}
4508
4509	#[inline(always)]
4510	fn simd_index_add<S: Simd>(
4511		ctx: &Self::SimdCtx<S>,
4512		lhs: Self::SimdIndex<S>,
4513		rhs: Self::SimdIndex<S>,
4514	) -> Self::SimdIndex<S> {
4515		f64::simd_index_add(ctx, lhs, rhs)
4516	}
4517
4518	#[inline(always)]
4519	fn simd_index_less_than<S: Simd>(
4520		ctx: &Self::SimdCtx<S>,
4521		lhs: Self::SimdIndex<S>,
4522		rhs: Self::SimdIndex<S>,
4523	) -> Self::SimdMask<S> {
4524		f64::simd_index_less_than(ctx, lhs, rhs)
4525	}
4526
4527	#[inline(always)]
4528	fn simd_and_mask<S: Simd>(
4529		ctx: &Self::SimdCtx<S>,
4530		lhs: Self::SimdMask<S>,
4531		rhs: Self::SimdMask<S>,
4532	) -> Self::SimdMask<S> {
4533		f64::simd_and_mask(ctx, lhs, rhs)
4534	}
4535
4536	#[inline(always)]
4537	fn simd_or_mask<S: Simd>(
4538		ctx: &Self::SimdCtx<S>,
4539		lhs: Self::SimdMask<S>,
4540		rhs: Self::SimdMask<S>,
4541	) -> Self::SimdMask<S> {
4542		f64::simd_or_mask(ctx, lhs, rhs)
4543	}
4544
4545	#[inline(always)]
4546	fn simd_not_mask<S: Simd>(
4547		ctx: &Self::SimdCtx<S>,
4548		mask: Self::SimdMask<S>,
4549	) -> Self::SimdMask<S> {
4550		f64::simd_not_mask(ctx, mask)
4551	}
4552
4553	#[inline(always)]
4554	fn simd_first_true_mask<S: Simd>(
4555		ctx: &Self::SimdCtx<S>,
4556		value: Self::SimdMask<S>,
4557	) -> usize {
4558		f64::simd_first_true_mask(ctx, value)
4559	}
4560
4561	#[inline(always)]
4562	fn simd_mem_mask_between<S: Simd>(
4563		ctx: &Self::SimdCtx<S>,
4564		start: Self::Index,
4565		end: Self::Index,
4566	) -> Self::SimdMemMask<S> {
4567		ctx.mask_between_m64s((2 * start) as _, (2 * end) as _)
4568	}
4569
4570	#[inline(always)]
4571	fn simd_mask_between<S: Simd>(
4572		ctx: &Self::SimdCtx<S>,
4573		start: Self::Index,
4574		end: Self::Index,
4575	) -> Self::SimdMask<S> {
4576		ctx.mask_between_m64s((2 * start) as _, (2 * end) as _)
4577			.mask()
4578	}
4579
4580	#[inline(always)]
4581	unsafe fn simd_mask_load_raw<S: Simd>(
4582		ctx: &Self::SimdCtx<S>,
4583		mask: Self::SimdMemMask<S>,
4584		ptr: *const Self::SimdVec<S>,
4585	) -> Self::SimdVec<S> {
4586		ctx.mask_load_ptr_c64s(mask, ptr as _)
4587	}
4588
4589	#[inline(always)]
4590	unsafe fn simd_mask_store_raw<S: Simd>(
4591		ctx: &Self::SimdCtx<S>,
4592		mask: Self::SimdMemMask<S>,
4593		ptr: *mut Self::SimdVec<S>,
4594		values: Self::SimdVec<S>,
4595	) {
4596		ctx.mask_store_ptr_c64s(mask, ptr as _, values);
4597	}
4598}
4599#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
4600pub struct Symbolic;
4601impl_op!({
4602	impl Add for Symbolic {
4603		fn add(self, rhs: Self) -> Self::Output {
4604			_ = rhs;
4605			Symbolic
4606		}
4607	}
4608	impl Sub for Symbolic {
4609		fn sub(self, rhs: Self) -> Self::Output {
4610			_ = rhs;
4611			Symbolic
4612		}
4613	}
4614	impl Mul for Symbolic {
4615		fn mul(self, rhs: Self) -> Self::Output {
4616			_ = rhs;
4617			Symbolic
4618		}
4619	}
4620	impl Div for Symbolic {
4621		fn div(self, rhs: Self) -> Self::Output {
4622			_ = rhs;
4623			Symbolic
4624		}
4625	}
4626	impl Rem for Symbolic {
4627		fn rem(self, rhs: Self) -> Self::Output {
4628			_ = rhs;
4629			Symbolic
4630		}
4631	}
4632});
4633impl_assign_op!({
4634	impl AddAssign for Symbolic {
4635		fn add_assign(&mut self, rhs: Self) {
4636			_ = rhs;
4637		}
4638	}
4639	impl SubAssign for Symbolic {
4640		fn sub_assign(&mut self, rhs: Self) {
4641			_ = rhs;
4642		}
4643	}
4644	impl MulAssign for Symbolic {
4645		fn mul_assign(&mut self, rhs: Self) {
4646			_ = rhs;
4647		}
4648	}
4649	impl DivAssign for Symbolic {
4650		fn div_assign(&mut self, rhs: Self) {
4651			_ = rhs;
4652		}
4653	}
4654	impl RemAssign for Symbolic {
4655		fn rem_assign(&mut self, rhs: Self) {
4656			_ = rhs;
4657		}
4658	}
4659});
4660impl core::ops::Neg for Symbolic {
4661	type Output = Self;
4662
4663	fn neg(self) -> Self {
4664		Self
4665	}
4666}
4667impl core::ops::Neg for &Symbolic {
4668	type Output = Symbolic;
4669
4670	fn neg(self) -> Symbolic {
4671		Symbolic
4672	}
4673}
4674impl num_traits::Zero for Symbolic {
4675	fn zero() -> Self {
4676		Self
4677	}
4678
4679	fn is_zero(&self) -> bool {
4680		true
4681	}
4682}
4683impl num_traits::One for Symbolic {
4684	fn one() -> Self {
4685		Self
4686	}
4687
4688	fn is_one(&self) -> bool {
4689		true
4690	}
4691}
4692impl num_traits::Num for Symbolic {
4693	type FromStrRadixErr = core::convert::Infallible;
4694
4695	fn from_str_radix(_: &str, _: u32) -> Result<Self, Self::FromStrRadixErr> {
4696		Ok(Self)
4697	}
4698}
4699impl Symbolic {
4700	#[inline]
4701	pub fn materialize(len: usize) -> &'static mut [Self] {
4702		unsafe {
4703			core::slice::from_raw_parts_mut(
4704				core::ptr::NonNull::dangling().as_ptr(),
4705				len,
4706			)
4707		}
4708	}
4709}
4710impl RealField for Symbolic {
4711	fn epsilon_impl() -> Self {
4712		Self
4713	}
4714
4715	fn nbits_impl() -> usize {
4716		0
4717	}
4718
4719	fn min_positive_impl() -> Self {
4720		Self
4721	}
4722
4723	fn max_positive_impl() -> Self {
4724		Self
4725	}
4726
4727	fn sqrt_min_positive_impl() -> Self {
4728		Self
4729	}
4730
4731	fn sqrt_max_positive_impl() -> Self {
4732		Self
4733	}
4734}
4735impl ComplexField for Symbolic {
4736	type Arch = pulp::Scalar;
4737	type Index = usize;
4738	type Real = Self;
4739	type SimdCtx<S: pulp::Simd> = S;
4740	type SimdIndex<S: pulp::Simd> = ();
4741	type SimdMask<S: pulp::Simd> = ();
4742	type SimdMemMask<S: pulp::Simd> = ();
4743	type SimdVec<S: pulp::Simd> = ();
4744	type Unit = Self;
4745
4746	const IS_REAL: bool = true;
4747	const SIMD_CAPABILITIES: SimdCapabilities = SimdCapabilities::Copy;
4748
4749	fn zero_impl() -> Self {
4750		Self
4751	}
4752
4753	fn one_impl() -> Self {
4754		Self
4755	}
4756
4757	fn nan_impl() -> Self {
4758		Self
4759	}
4760
4761	fn infinity_impl() -> Self {
4762		Self
4763	}
4764
4765	fn from_real_impl(_: &Self::Real) -> Self {
4766		Self
4767	}
4768
4769	fn from_f64_impl(_: f64) -> Self {
4770		Self
4771	}
4772
4773	fn real_part_impl(_: &Self) -> Self::Real {
4774		Self
4775	}
4776
4777	fn imag_part_impl(_: &Self) -> Self::Real {
4778		Self
4779	}
4780
4781	fn copy_impl(_: &Self) -> Self {
4782		Self
4783	}
4784
4785	fn conj_impl(_: &Self) -> Self {
4786		Self
4787	}
4788
4789	fn recip_impl(_: &Self) -> Self {
4790		Self
4791	}
4792
4793	fn sqrt_impl(_: &Self) -> Self {
4794		Self
4795	}
4796
4797	fn abs_impl(_: &Self) -> Self::Real {
4798		Self
4799	}
4800
4801	fn abs1_impl(_: &Self) -> Self::Real {
4802		Self
4803	}
4804
4805	fn abs2_impl(_: &Self) -> Self::Real {
4806		Self
4807	}
4808
4809	fn mul_real_impl(_: &Self, _: &Self::Real) -> Self {
4810		Self
4811	}
4812
4813	fn mul_pow2_impl(_: &Self, _: &Self::Real) -> Self {
4814		Self
4815	}
4816
4817	fn is_finite_impl(_: &Self) -> bool {
4818		true
4819	}
4820
4821	fn simd_ctx<S: pulp::Simd>(simd: S) -> Self::SimdCtx<S> {
4822		simd
4823	}
4824
4825	fn ctx_from_simd<S: pulp::Simd>(simd: &Self::SimdCtx<S>) -> S {
4826		*simd
4827	}
4828
4829	fn simd_mem_mask_between<S: pulp::Simd>(
4830		_: &Self::SimdCtx<S>,
4831		_: Self::Index,
4832		_: Self::Index,
4833	) -> Self::SimdMemMask<S> {
4834		()
4835	}
4836
4837	unsafe fn simd_mask_load_raw<S: pulp::Simd>(
4838		_: &Self::SimdCtx<S>,
4839		_: Self::SimdMemMask<S>,
4840		_: *const Self::SimdVec<S>,
4841	) -> Self::SimdVec<S> {
4842		()
4843	}
4844
4845	unsafe fn simd_mask_store_raw<S: pulp::Simd>(
4846		_: &Self::SimdCtx<S>,
4847		_: Self::SimdMemMask<S>,
4848		_: *mut Self::SimdVec<S>,
4849		_: Self::SimdVec<S>,
4850	) {
4851		()
4852	}
4853
4854	fn simd_splat<S: pulp::Simd>(
4855		_: &Self::SimdCtx<S>,
4856		_: &Self,
4857	) -> Self::SimdVec<S> {
4858		()
4859	}
4860
4861	fn simd_splat_real<S: pulp::Simd>(
4862		_: &Self::SimdCtx<S>,
4863		_: &Self::Real,
4864	) -> Self::SimdVec<S> {
4865		()
4866	}
4867
4868	fn simd_add<S: pulp::Simd>(
4869		_: &Self::SimdCtx<S>,
4870		_: Self::SimdVec<S>,
4871		_: Self::SimdVec<S>,
4872	) -> Self::SimdVec<S> {
4873		()
4874	}
4875
4876	fn simd_sub<S: pulp::Simd>(
4877		_: &Self::SimdCtx<S>,
4878		_: Self::SimdVec<S>,
4879		_: Self::SimdVec<S>,
4880	) -> Self::SimdVec<S> {
4881		()
4882	}
4883
4884	fn simd_neg<S: pulp::Simd>(
4885		_: &Self::SimdCtx<S>,
4886		_: Self::SimdVec<S>,
4887	) -> Self::SimdVec<S> {
4888		()
4889	}
4890
4891	fn simd_conj<S: pulp::Simd>(
4892		_: &Self::SimdCtx<S>,
4893		_: Self::SimdVec<S>,
4894	) -> Self::SimdVec<S> {
4895		()
4896	}
4897
4898	fn simd_abs1<S: pulp::Simd>(
4899		_: &Self::SimdCtx<S>,
4900		_: Self::SimdVec<S>,
4901	) -> Self::SimdVec<S> {
4902		()
4903	}
4904
4905	fn simd_abs_max<S: pulp::Simd>(
4906		_: &Self::SimdCtx<S>,
4907		_: Self::SimdVec<S>,
4908	) -> Self::SimdVec<S> {
4909		()
4910	}
4911
4912	fn simd_mul_real<S: pulp::Simd>(
4913		_: &Self::SimdCtx<S>,
4914		_: Self::SimdVec<S>,
4915		_: Self::SimdVec<S>,
4916	) -> Self::SimdVec<S> {
4917		()
4918	}
4919
4920	fn simd_mul_pow2<S: pulp::Simd>(
4921		_: &Self::SimdCtx<S>,
4922		_: Self::SimdVec<S>,
4923		_: Self::SimdVec<S>,
4924	) -> Self::SimdVec<S> {
4925		()
4926	}
4927
4928	fn simd_mul<S: pulp::Simd>(
4929		_: &Self::SimdCtx<S>,
4930		_: Self::SimdVec<S>,
4931		_: Self::SimdVec<S>,
4932	) -> Self::SimdVec<S> {
4933		()
4934	}
4935
4936	fn simd_conj_mul<S: pulp::Simd>(
4937		_: &Self::SimdCtx<S>,
4938		_: Self::SimdVec<S>,
4939		_: Self::SimdVec<S>,
4940	) -> Self::SimdVec<S> {
4941		()
4942	}
4943
4944	fn simd_mul_add<S: pulp::Simd>(
4945		_: &Self::SimdCtx<S>,
4946		_: Self::SimdVec<S>,
4947		_: Self::SimdVec<S>,
4948		_: Self::SimdVec<S>,
4949	) -> Self::SimdVec<S> {
4950		()
4951	}
4952
4953	fn simd_conj_mul_add<S: pulp::Simd>(
4954		_: &Self::SimdCtx<S>,
4955		_: Self::SimdVec<S>,
4956		_: Self::SimdVec<S>,
4957		_: Self::SimdVec<S>,
4958	) -> Self::SimdVec<S> {
4959		()
4960	}
4961
4962	fn simd_abs2<S: pulp::Simd>(
4963		_: &Self::SimdCtx<S>,
4964		_: Self::SimdVec<S>,
4965	) -> Self::SimdVec<S> {
4966		()
4967	}
4968
4969	fn simd_abs2_add<S: pulp::Simd>(
4970		_: &Self::SimdCtx<S>,
4971		_: Self::SimdVec<S>,
4972		_: Self::SimdVec<S>,
4973	) -> Self::SimdVec<S> {
4974		()
4975	}
4976
4977	fn simd_reduce_sum<S: pulp::Simd>(
4978		_: &Self::SimdCtx<S>,
4979		_: Self::SimdVec<S>,
4980	) -> Self {
4981		Self
4982	}
4983
4984	fn simd_reduce_max<S: pulp::Simd>(
4985		_: &Self::SimdCtx<S>,
4986		_: Self::SimdVec<S>,
4987	) -> Self {
4988		Self
4989	}
4990
4991	fn simd_equal<S: pulp::Simd>(
4992		_: &Self::SimdCtx<S>,
4993		_: Self::SimdVec<S>,
4994		_: Self::SimdVec<S>,
4995	) -> Self::SimdMask<S> {
4996		()
4997	}
4998
4999	fn simd_less_than<S: pulp::Simd>(
5000		_: &Self::SimdCtx<S>,
5001		_: Self::SimdVec<S>,
5002		_: Self::SimdVec<S>,
5003	) -> Self::SimdMask<S> {
5004		()
5005	}
5006
5007	fn simd_less_than_or_equal<S: pulp::Simd>(
5008		_: &Self::SimdCtx<S>,
5009		_: Self::SimdVec<S>,
5010		_: Self::SimdVec<S>,
5011	) -> Self::SimdMask<S> {
5012		()
5013	}
5014
5015	fn simd_greater_than<S: pulp::Simd>(
5016		_: &Self::SimdCtx<S>,
5017		_: Self::SimdVec<S>,
5018		_: Self::SimdVec<S>,
5019	) -> Self::SimdMask<S> {
5020		()
5021	}
5022
5023	fn simd_greater_than_or_equal<S: pulp::Simd>(
5024		_: &Self::SimdCtx<S>,
5025		_: Self::SimdVec<S>,
5026		_: Self::SimdVec<S>,
5027	) -> Self::SimdMask<S> {
5028		()
5029	}
5030
5031	fn simd_select<S: pulp::Simd>(
5032		_: &Self::SimdCtx<S>,
5033		_: Self::SimdMask<S>,
5034		_: Self::SimdVec<S>,
5035		_: Self::SimdVec<S>,
5036	) -> Self::SimdVec<S> {
5037		()
5038	}
5039
5040	fn simd_index_select<S: pulp::Simd>(
5041		_: &Self::SimdCtx<S>,
5042		_: Self::SimdMask<S>,
5043		_: Self::SimdIndex<S>,
5044		_: Self::SimdIndex<S>,
5045	) -> Self::SimdIndex<S> {
5046		()
5047	}
5048
5049	fn simd_index_splat<S: pulp::Simd>(
5050		_: &Self::SimdCtx<S>,
5051		_: Self::Index,
5052	) -> Self::SimdIndex<S> {
5053		()
5054	}
5055
5056	fn simd_index_add<S: pulp::Simd>(
5057		_: &Self::SimdCtx<S>,
5058		_: Self::SimdIndex<S>,
5059		_: Self::SimdIndex<S>,
5060	) -> Self::SimdIndex<S> {
5061		()
5062	}
5063
5064	fn simd_and_mask<S: pulp::Simd>(
5065		_: &Self::SimdCtx<S>,
5066		_: Self::SimdMask<S>,
5067		_: Self::SimdMask<S>,
5068	) -> Self::SimdMask<S> {
5069		()
5070	}
5071
5072	fn simd_or_mask<S: pulp::Simd>(
5073		_: &Self::SimdCtx<S>,
5074		_: Self::SimdMask<S>,
5075		_: Self::SimdMask<S>,
5076	) -> Self::SimdMask<S> {
5077		()
5078	}
5079
5080	fn simd_not_mask<S: Simd>(
5081		_: &Self::SimdCtx<S>,
5082		_: Self::SimdMask<S>,
5083	) -> Self::SimdMask<S> {
5084		()
5085	}
5086
5087	fn simd_first_true_mask<S: pulp::Simd>(
5088		_: &Self::SimdCtx<S>,
5089		_: Self::SimdMask<S>,
5090	) -> usize {
5091		0
5092	}
5093
5094	fn simd_mask_between<S: Simd>(
5095		_: &Self::SimdCtx<S>,
5096		_: Self::Index,
5097		_: Self::Index,
5098	) -> Self::SimdMask<S> {
5099		()
5100	}
5101
5102	fn simd_index_less_than<S: Simd>(
5103		_: &Self::SimdCtx<S>,
5104		_: Self::SimdIndex<S>,
5105		_: Self::SimdIndex<S>,
5106	) -> Self::SimdMask<S> {
5107		()
5108	}
5109}
5110pub type c64 = Complex<f64>;
5111pub type c32 = Complex<f32>;
5112pub type fx128 = qd::Quad;
5113pub type cx128 = Complex<fx128>;
5114pub extern crate num_traits;
5115pub extern crate pulp;
5116impl ComplexField for fx128 {
5117	type Arch = pulp::Arch;
5118	type Index = u64;
5119	type Real = Self;
5120	type SimdCtx<S: Simd> = S;
5121	type SimdIndex<S: Simd> = S::u64s;
5122	type SimdMask<S: Simd> = S::m64s;
5123	type SimdMemMask<S: Simd> = Quad<pulp::MemMask<S::m64s>>;
5124	type SimdVec<S: Simd> = Quad<S::f64s>;
5125	type Unit = f64;
5126
5127	const IS_REAL: bool = true;
5128	const SIMD_CAPABILITIES: SimdCapabilities = SimdCapabilities::Simd;
5129
5130	#[inline(always)]
5131	fn zero_impl() -> Self {
5132		Self::ZERO
5133	}
5134
5135	#[inline(always)]
5136	fn one_impl() -> Self {
5137		Quad(1.0, 0.0)
5138	}
5139
5140	#[inline(always)]
5141	fn nan_impl() -> Self {
5142		Self::NAN
5143	}
5144
5145	#[inline(always)]
5146	fn infinity_impl() -> Self {
5147		Self::INFINITY
5148	}
5149
5150	#[inline(always)]
5151	fn from_real_impl(real: &Self::Real) -> Self {
5152		*real
5153	}
5154
5155	#[inline(always)]
5156	fn from_f64_impl(real: f64) -> Self {
5157		real.into()
5158	}
5159
5160	#[inline(always)]
5161	fn real_part_impl(value: &Self) -> Self::Real {
5162		*value
5163	}
5164
5165	#[inline(always)]
5166	fn imag_part_impl(_: &Self) -> Self::Real {
5167		Self::ZERO
5168	}
5169
5170	#[inline(always)]
5171	fn copy_impl(value: &Self) -> Self {
5172		*value
5173	}
5174
5175	#[inline(always)]
5176	fn conj_impl(value: &Self) -> Self {
5177		*value
5178	}
5179
5180	#[inline(always)]
5181	fn recip_impl(value: &Self) -> Self {
5182		if value.0.abs() == f64::INFINITY {
5183			Quad::ZERO
5184		} else {
5185			Quad::from(1.0) / *value
5186		}
5187	}
5188
5189	#[inline(always)]
5190	fn sqrt_impl(value: &Self) -> Self {
5191		value.sqrt()
5192	}
5193
5194	#[inline(always)]
5195	fn abs_impl(value: &Self) -> Self::Real {
5196		value.abs()
5197	}
5198
5199	#[inline(always)]
5200	fn abs1_impl(value: &Self) -> Self::Real {
5201		value.abs()
5202	}
5203
5204	#[inline(always)]
5205	fn abs2_impl(value: &Self) -> Self::Real {
5206		value * value
5207	}
5208
5209	#[inline(always)]
5210	fn mul_real_impl(lhs: &Self, rhs: &Self::Real) -> Self {
5211		lhs * rhs
5212	}
5213
5214	#[inline(always)]
5215	fn mul_pow2_impl(lhs: &Self, rhs: &Self::Real) -> Self {
5216		lhs * rhs
5217	}
5218
5219	#[inline(always)]
5220	fn is_finite_impl(value: &Self) -> bool {
5221		value.0.is_finite() && value.1.is_finite()
5222	}
5223
5224	#[inline(always)]
5225	fn simd_ctx<S: Simd>(simd: S) -> Self::SimdCtx<S> {
5226		simd
5227	}
5228
5229	#[inline(always)]
5230	fn ctx_from_simd<S: Simd>(ctx: &Self::SimdCtx<S>) -> S {
5231		*ctx
5232	}
5233
5234	#[inline(always)]
5235	fn simd_mask_between<S: Simd>(
5236		ctx: &Self::SimdCtx<S>,
5237		start: Self::Index,
5238		end: Self::Index,
5239	) -> Self::SimdMask<S> {
5240		ctx.mask_between_m64s(start as _, end as _).mask()
5241	}
5242
5243	#[inline(always)]
5244	fn simd_mem_mask_between<S: Simd>(
5245		ctx: &Self::SimdCtx<S>,
5246		start: Self::Index,
5247		end: Self::Index,
5248	) -> Self::SimdMemMask<S> {
5249		let n = (core::mem::size_of::<Self::SimdVec<S>>()
5250			/ core::mem::size_of::<Self>()) as u64;
5251		let start = start * 2;
5252		let end = end * 2;
5253		let mut sa = start.min(n);
5254		let mut ea = end.min(n);
5255		let mut sb = start.max(n) - n;
5256		let mut eb = end.max(n) - n;
5257		if sa == ea {
5258			sa = 0;
5259			ea = 0;
5260		}
5261		if sb == eb {
5262			sb = 0;
5263			eb = 0;
5264		}
5265		let a = f64::simd_mem_mask_between(ctx, sa, ea);
5266		let b = f64::simd_mem_mask_between(ctx, sb, eb);
5267		Quad(a, b)
5268	}
5269
5270	#[inline(always)]
5271	unsafe fn simd_mask_load_raw<S: Simd>(
5272		ctx: &Self::SimdCtx<S>,
5273		mask: Self::SimdMemMask<S>,
5274		ptr: *const Self::SimdVec<S>,
5275	) -> Self::SimdVec<S> {
5276		unsafe {
5277			Quad(
5278				f64::simd_mask_load_raw(ctx, mask.0, &raw const (*ptr).0),
5279				f64::simd_mask_load_raw(ctx, mask.1, &raw const (*ptr).1),
5280			)
5281		}
5282	}
5283
5284	#[inline(always)]
5285	unsafe fn simd_mask_store_raw<S: Simd>(
5286		ctx: &Self::SimdCtx<S>,
5287		mask: Self::SimdMemMask<S>,
5288		ptr: *mut Self::SimdVec<S>,
5289		values: Self::SimdVec<S>,
5290	) {
5291		unsafe {
5292			Quad(
5293				f64::simd_mask_store_raw(
5294					ctx,
5295					mask.0,
5296					&raw mut (*ptr).0,
5297					values.0,
5298				),
5299				f64::simd_mask_store_raw(
5300					ctx,
5301					mask.1,
5302					&raw mut (*ptr).1,
5303					values.1,
5304				),
5305			);
5306		}
5307	}
5308
5309	#[inline(always)]
5310	fn simd_splat<S: Simd>(
5311		ctx: &Self::SimdCtx<S>,
5312		value: &Self,
5313	) -> Self::SimdVec<S> {
5314		Quad(ctx.splat_f64s(value.0), ctx.splat_f64s(value.1))
5315	}
5316
5317	#[inline(always)]
5318	fn simd_splat_real<S: Simd>(
5319		ctx: &Self::SimdCtx<S>,
5320		value: &Self::Real,
5321	) -> Self::SimdVec<S> {
5322		Quad(ctx.splat_f64s(value.0), ctx.splat_f64s(value.1))
5323	}
5324
5325	#[inline(always)]
5326	fn simd_add<S: Simd>(
5327		ctx: &Self::SimdCtx<S>,
5328		lhs: Self::SimdVec<S>,
5329		rhs: Self::SimdVec<S>,
5330	) -> Self::SimdVec<S> {
5331		qd::simd::add_estimate(*ctx, lhs, rhs)
5332	}
5333
5334	#[inline(always)]
5335	fn simd_sub<S: Simd>(
5336		ctx: &Self::SimdCtx<S>,
5337		lhs: Self::SimdVec<S>,
5338		rhs: Self::SimdVec<S>,
5339	) -> Self::SimdVec<S> {
5340		qd::simd::sub_estimate(*ctx, lhs, rhs)
5341	}
5342
5343	#[inline(always)]
5344	fn simd_neg<S: Simd>(
5345		ctx: &Self::SimdCtx<S>,
5346		value: Self::SimdVec<S>,
5347	) -> Self::SimdVec<S> {
5348		qd::simd::neg(*ctx, value)
5349	}
5350
5351	#[inline(always)]
5352	fn simd_conj<S: Simd>(
5353		_: &Self::SimdCtx<S>,
5354		value: Self::SimdVec<S>,
5355	) -> Self::SimdVec<S> {
5356		value
5357	}
5358
5359	#[inline(always)]
5360	fn simd_abs1<S: Simd>(
5361		ctx: &Self::SimdCtx<S>,
5362		value: Self::SimdVec<S>,
5363	) -> Self::SimdVec<S> {
5364		qd::simd::abs(*ctx, value)
5365	}
5366
5367	#[inline(always)]
5368	fn simd_abs_max<S: Simd>(
5369		ctx: &Self::SimdCtx<S>,
5370		value: Self::SimdVec<S>,
5371	) -> Self::SimdVec<S> {
5372		qd::simd::abs(*ctx, value)
5373	}
5374
5375	#[inline(always)]
5376	fn simd_mul_real<S: Simd>(
5377		ctx: &Self::SimdCtx<S>,
5378		lhs: Self::SimdVec<S>,
5379		real_rhs: Self::SimdVec<S>,
5380	) -> Self::SimdVec<S> {
5381		qd::simd::mul(*ctx, lhs, real_rhs)
5382	}
5383
5384	#[inline(always)]
5385	fn simd_mul_pow2<S: Simd>(
5386		ctx: &Self::SimdCtx<S>,
5387		lhs: Self::SimdVec<S>,
5388		real_rhs: Self::SimdVec<S>,
5389	) -> Self::SimdVec<S> {
5390		qd::simd::mul(*ctx, lhs, real_rhs)
5391	}
5392
5393	#[inline(always)]
5394	fn simd_mul<S: Simd>(
5395		ctx: &Self::SimdCtx<S>,
5396		lhs: Self::SimdVec<S>,
5397		rhs: Self::SimdVec<S>,
5398	) -> Self::SimdVec<S> {
5399		qd::simd::mul(*ctx, lhs, rhs)
5400	}
5401
5402	#[inline(always)]
5403	fn simd_conj_mul<S: Simd>(
5404		ctx: &Self::SimdCtx<S>,
5405		lhs: Self::SimdVec<S>,
5406		rhs: Self::SimdVec<S>,
5407	) -> Self::SimdVec<S> {
5408		qd::simd::mul(*ctx, lhs, rhs)
5409	}
5410
5411	#[inline(always)]
5412	fn simd_mul_add<S: Simd>(
5413		ctx: &Self::SimdCtx<S>,
5414		lhs: Self::SimdVec<S>,
5415		rhs: Self::SimdVec<S>,
5416		acc: Self::SimdVec<S>,
5417	) -> Self::SimdVec<S> {
5418		qd::simd::add_estimate(*ctx, qd::simd::mul(*ctx, lhs, rhs), acc)
5419	}
5420
5421	#[inline(always)]
5422	fn simd_conj_mul_add<S: Simd>(
5423		ctx: &Self::SimdCtx<S>,
5424		lhs: Self::SimdVec<S>,
5425		rhs: Self::SimdVec<S>,
5426		acc: Self::SimdVec<S>,
5427	) -> Self::SimdVec<S> {
5428		qd::simd::add_estimate(*ctx, qd::simd::mul(*ctx, lhs, rhs), acc)
5429	}
5430
5431	#[inline(always)]
5432	fn simd_abs2<S: Simd>(
5433		ctx: &Self::SimdCtx<S>,
5434		value: Self::SimdVec<S>,
5435	) -> Self::SimdVec<S> {
5436		qd::simd::mul(*ctx, value, value)
5437	}
5438
5439	#[inline(always)]
5440	fn simd_abs2_add<S: Simd>(
5441		ctx: &Self::SimdCtx<S>,
5442		value: Self::SimdVec<S>,
5443		acc: Self::SimdVec<S>,
5444	) -> Self::SimdVec<S> {
5445		qd::simd::add_estimate(*ctx, qd::simd::mul(*ctx, value, value), acc)
5446	}
5447
5448	#[inline(always)]
5449	fn simd_reduce_sum<S: Simd>(
5450		_: &Self::SimdCtx<S>,
5451		value: Self::SimdVec<S>,
5452	) -> Self {
5453		let a = value.0;
5454		let b = value.1;
5455		let a: &[f64] = bytemuck::cast_slice(core::slice::from_ref(&a));
5456		let b: &[f64] = bytemuck::cast_slice(core::slice::from_ref(&b));
5457		let mut acc = Quad::ZERO;
5458		for (&a, &b) in core::iter::zip(a, b) {
5459			acc += Quad(a, b);
5460		}
5461		acc
5462	}
5463
5464	#[inline(always)]
5465	fn simd_reduce_max<S: Simd>(
5466		_: &Self::SimdCtx<S>,
5467		value: Self::SimdVec<S>,
5468	) -> Self {
5469		let a = value.0;
5470		let b = value.1;
5471		let a: &[f64] = bytemuck::cast_slice(core::slice::from_ref(&a));
5472		let b: &[f64] = bytemuck::cast_slice(core::slice::from_ref(&b));
5473		let mut acc = Quad::NEG_INFINITY;
5474		for (&a, &b) in core::iter::zip(a, b) {
5475			let val = Quad(a, b);
5476			if val > acc {
5477				acc = val
5478			}
5479		}
5480		acc
5481	}
5482
5483	#[inline(always)]
5484	fn simd_equal<S: Simd>(
5485		ctx: &Self::SimdCtx<S>,
5486		real_lhs: Self::SimdVec<S>,
5487		real_rhs: Self::SimdVec<S>,
5488	) -> Self::SimdMask<S> {
5489		qd::simd::eq(*ctx, real_lhs, real_rhs)
5490	}
5491
5492	#[inline(always)]
5493	fn simd_less_than<S: Simd>(
5494		ctx: &Self::SimdCtx<S>,
5495		real_lhs: Self::SimdVec<S>,
5496		real_rhs: Self::SimdVec<S>,
5497	) -> Self::SimdMask<S> {
5498		qd::simd::less_than(*ctx, real_lhs, real_rhs)
5499	}
5500
5501	#[inline(always)]
5502	fn simd_less_than_or_equal<S: Simd>(
5503		ctx: &Self::SimdCtx<S>,
5504		real_lhs: Self::SimdVec<S>,
5505		real_rhs: Self::SimdVec<S>,
5506	) -> Self::SimdMask<S> {
5507		qd::simd::less_than_or_equal(*ctx, real_lhs, real_rhs)
5508	}
5509
5510	#[inline(always)]
5511	fn simd_greater_than<S: Simd>(
5512		ctx: &Self::SimdCtx<S>,
5513		real_lhs: Self::SimdVec<S>,
5514		real_rhs: Self::SimdVec<S>,
5515	) -> Self::SimdMask<S> {
5516		qd::simd::greater_than(*ctx, real_lhs, real_rhs)
5517	}
5518
5519	#[inline(always)]
5520	fn simd_greater_than_or_equal<S: Simd>(
5521		ctx: &Self::SimdCtx<S>,
5522		real_lhs: Self::SimdVec<S>,
5523		real_rhs: Self::SimdVec<S>,
5524	) -> Self::SimdMask<S> {
5525		qd::simd::greater_than_or_equal(*ctx, real_lhs, real_rhs)
5526	}
5527
5528	#[inline(always)]
5529	fn simd_select<S: Simd>(
5530		ctx: &Self::SimdCtx<S>,
5531		mask: Self::SimdMask<S>,
5532		lhs: Self::SimdVec<S>,
5533		rhs: Self::SimdVec<S>,
5534	) -> Self::SimdVec<S> {
5535		Quad(
5536			ctx.select_f64s(mask, lhs.0, rhs.0),
5537			ctx.select_f64s(mask, lhs.1, rhs.1),
5538		)
5539	}
5540
5541	#[inline(always)]
5542	fn simd_index_select<S: Simd>(
5543		ctx: &Self::SimdCtx<S>,
5544		mask: Self::SimdMask<S>,
5545		lhs: Self::SimdIndex<S>,
5546		rhs: Self::SimdIndex<S>,
5547	) -> Self::SimdIndex<S> {
5548		ctx.select_u64s(mask, lhs, rhs)
5549	}
5550
5551	#[inline(always)]
5552	fn simd_index_splat<S: Simd>(
5553		ctx: &Self::SimdCtx<S>,
5554		value: Self::Index,
5555	) -> Self::SimdIndex<S> {
5556		ctx.splat_u64s(value as u64)
5557	}
5558
5559	#[inline(always)]
5560	fn simd_index_add<S: Simd>(
5561		ctx: &Self::SimdCtx<S>,
5562		lhs: Self::SimdIndex<S>,
5563		rhs: Self::SimdIndex<S>,
5564	) -> Self::SimdIndex<S> {
5565		ctx.add_u64s(lhs, rhs)
5566	}
5567
5568	#[inline(always)]
5569	fn simd_index_less_than<S: Simd>(
5570		ctx: &Self::SimdCtx<S>,
5571		lhs: Self::SimdIndex<S>,
5572		rhs: Self::SimdIndex<S>,
5573	) -> Self::SimdMask<S> {
5574		ctx.less_than_u64s(lhs, rhs)
5575	}
5576
5577	#[inline(always)]
5578	fn simd_and_mask<S: Simd>(
5579		ctx: &Self::SimdCtx<S>,
5580		lhs: Self::SimdMask<S>,
5581		rhs: Self::SimdMask<S>,
5582	) -> Self::SimdMask<S> {
5583		ctx.and_m64s(lhs, rhs)
5584	}
5585
5586	#[inline(always)]
5587	fn simd_or_mask<S: Simd>(
5588		ctx: &Self::SimdCtx<S>,
5589		lhs: Self::SimdMask<S>,
5590		rhs: Self::SimdMask<S>,
5591	) -> Self::SimdMask<S> {
5592		ctx.or_m64s(lhs, rhs)
5593	}
5594
5595	#[inline(always)]
5596	fn simd_not_mask<S: Simd>(
5597		ctx: &Self::SimdCtx<S>,
5598		mask: Self::SimdMask<S>,
5599	) -> Self::SimdMask<S> {
5600		ctx.not_m64s(mask)
5601	}
5602
5603	#[inline(always)]
5604	fn simd_first_true_mask<S: Simd>(
5605		ctx: &Self::SimdCtx<S>,
5606		value: Self::SimdMask<S>,
5607	) -> usize {
5608		ctx.first_true_m64s(value)
5609	}
5610}
5611impl RealField for fx128 {
5612	#[inline(always)]
5613	fn epsilon_impl() -> Self {
5614		let mut x = Quad::EPSILON;
5615		x.0 *= 8.0;
5616		x.1 *= 8.0;
5617		x
5618	}
5619
5620	#[inline(always)]
5621	fn nbits_impl() -> usize {
5622		100
5623	}
5624
5625	#[inline(always)]
5626	fn min_positive_impl() -> Self {
5627		Quad::MIN_POSITIVE
5628	}
5629
5630	#[inline(always)]
5631	fn max_positive_impl() -> Self {
5632		Quad::MIN_POSITIVE.recip()
5633	}
5634
5635	#[inline(always)]
5636	fn sqrt_min_positive_impl() -> Self {
5637		Quad::MIN_POSITIVE.sqrt()
5638	}
5639
5640	#[inline(always)]
5641	fn sqrt_max_positive_impl() -> Self {
5642		Quad::MIN_POSITIVE.recip().sqrt()
5643	}
5644}
5645pub mod ext {
5646	use super::*;
5647	pub use super::{ComplexField, RealField};
5648	pub trait ComplexFieldExt: ComplexField {
5649		#[inline(always)]
5650		#[must_use]
5651		fn nbits() -> usize {
5652			Self::Real::nbits_impl()
5653		}
5654		#[inline(always)]
5655		#[must_use]
5656		fn zero() -> Self {
5657			Self::zero_impl()
5658		}
5659		#[inline(always)]
5660		#[must_use]
5661		fn one() -> Self {
5662			Self::one_impl()
5663		}
5664		#[inline(always)]
5665		#[must_use]
5666		fn nan() -> Self {
5667			Self::nan_impl()
5668		}
5669		#[inline(always)]
5670		#[must_use]
5671		fn infinity() -> Self {
5672			Self::infinity_impl()
5673		}
5674		#[inline(always)]
5675		#[must_use]
5676		fn as_real(&self) -> Self {
5677			Self::from_real_impl(&Self::real_part_impl(self))
5678		}
5679		#[inline(always)]
5680		#[must_use]
5681		fn real(&self) -> Self::Real {
5682			Self::real_part_impl(self)
5683		}
5684		#[inline(always)]
5685		#[must_use]
5686		fn imag(&self) -> Self::Real {
5687			Self::imag_part_impl(self)
5688		}
5689		#[inline(always)]
5690		#[must_use]
5691		fn copy(&self) -> Self {
5692			Self::copy_impl(self)
5693		}
5694		#[inline(always)]
5695		#[must_use]
5696		fn conj(&self) -> Self {
5697			Self::conj_impl(self)
5698		}
5699		#[inline(always)]
5700		#[must_use]
5701		fn mul_real(&self, rhs: impl ByRef<Self::Real>) -> Self {
5702			Self::mul_real_impl(self, rhs.by_ref())
5703		}
5704		#[inline(always)]
5705		#[must_use]
5706		fn mul_pow2(&self, rhs: impl ByRef<Self::Real>) -> Self {
5707			Self::mul_real_impl(self, rhs.by_ref())
5708		}
5709		#[inline(always)]
5710		#[must_use]
5711		fn abs1(&self) -> Self::Real {
5712			Self::abs1_impl(self)
5713		}
5714		#[inline(always)]
5715		#[must_use]
5716		fn absmax(&self) -> Self::Real {
5717			if const { Self::IS_REAL } {
5718				Self::abs1_impl(self)
5719			} else {
5720				&Self::Real::abs1_impl(&real(self))
5721					+ &Self::Real::abs1_impl(&imag(self))
5722			}
5723		}
5724		#[inline(always)]
5725		#[must_use]
5726		fn abs(&self) -> Self::Real {
5727			Self::abs_impl(self)
5728		}
5729		#[inline(always)]
5730		#[must_use]
5731		fn abs2(&self) -> Self::Real {
5732			Self::abs2_impl(self)
5733		}
5734		#[inline(always)]
5735		#[must_use]
5736		fn is_nan(&self) -> bool {
5737			Self::is_nan_impl(self)
5738		}
5739		#[inline(always)]
5740		#[must_use]
5741		fn is_finite(&self) -> bool {
5742			Self::is_finite_impl(self)
5743		}
5744		#[inline(always)]
5745		#[must_use]
5746		fn sqrt(&self) -> Self {
5747			Self::sqrt_impl(self)
5748		}
5749		#[inline(always)]
5750		#[must_use]
5751		fn recip(&self) -> Self {
5752			Self::recip_impl(self)
5753		}
5754		#[inline(always)]
5755		#[must_use]
5756		fn from_f64(value: f64) -> Self {
5757			Self::from_f64_impl(value)
5758		}
5759	}
5760	pub trait RealFieldExt: RealField {
5761		#[inline(always)]
5762		#[must_use]
5763		fn eps<T: RealField>() -> T {
5764			T::Real::epsilon_impl()
5765		}
5766		#[inline(always)]
5767		#[must_use]
5768		fn nbits<T: ComplexField>() -> usize {
5769			T::Real::nbits_impl()
5770		}
5771		#[inline(always)]
5772		#[must_use]
5773		fn min_positive<T: RealField>() -> T {
5774			T::min_positive_impl()
5775		}
5776		#[inline(always)]
5777		#[must_use]
5778		fn max_positive<T: RealField>() -> T {
5779			T::max_positive_impl()
5780		}
5781		#[inline(always)]
5782		#[must_use]
5783		fn sqrt_min_positive<T: RealField>() -> T {
5784			T::sqrt_min_positive_impl()
5785		}
5786		#[inline(always)]
5787		#[must_use]
5788		fn sqrt_max_positive<T: RealField>() -> T {
5789			T::sqrt_max_positive_impl()
5790		}
5791		#[inline(always)]
5792		#[must_use]
5793		fn to_cplx<T: ComplexField<Real = Self>>(&self) -> T {
5794			T::from_real_impl(self)
5795		}
5796		#[inline(always)]
5797		#[must_use]
5798		fn fmax(&self, rhs: impl ByRef<Self>) -> Self {
5799			math_utils::max(self, rhs.by_ref())
5800		}
5801		#[inline(always)]
5802		#[must_use]
5803		fn fmin(&self, rhs: impl ByRef<Self>) -> Self {
5804			math_utils::min(self, rhs.by_ref())
5805		}
5806		#[inline(always)]
5807		#[must_use]
5808		fn hypot(&self, rhs: impl ByRef<Self>) -> Self {
5809			math_utils::hypot(self, rhs.by_ref())
5810		}
5811	}
5812	impl<T: ComplexField> ComplexFieldExt for T {}
5813	impl<T: RealField> RealFieldExt for T {}
5814}