Skip to content

Commit 6deeec5

Browse files
author
sigurd4
committed
Fix complex specialization
1 parent 6166764 commit 6deeec5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/spec/square.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::ops::Mul;
22

33
pub trait Square: Mul + Copy
44
{
5-
type Output: Sized + From<<Self as Mul>::Output>;
5+
type Output: Sized;
66

77
fn square(&self) -> <Self as Square>::Output;
88
}
@@ -15,19 +15,23 @@ where
1515

1616
default fn square(&self) -> <Self as Square>::Output
1717
{
18-
(*self**self).into()
18+
unsafe {
19+
core::intrinsics::transmute_unchecked(*self**self)
20+
}
1921
}
2022
}
2123

2224
#[cfg(feature = "num")]
2325
impl<T> Square for T
2426
where
25-
T: num_complex::ComplexFloat<Real: From<T>>
27+
T: num_complex::ComplexFloat
2628
{
2729
type Output = T::Real;
2830

2931
fn square(&self) -> <Self as Square>::Output
3032
{
31-
(*self*self.conj()).into()
33+
let re = self.re();
34+
let im = self.im();
35+
re*re + im*im
3236
}
3337
}

0 commit comments

Comments
 (0)