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