From feacf349642ef0b3e946ad6db5dc48c57a55bcb4 Mon Sep 17 00:00:00 2001 From: SabrinaJewson Date: Fri, 25 Jul 2025 23:46:57 +0100 Subject: [PATCH] Add more supertraits to `ComplexFloat` Includes `From` for infallible construction from real numbers, and various operator traits against the real field. --- src/complex_float.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/complex_float.rs b/src/complex_float.rs index 873fe73..6059a5f 100644 --- a/src/complex_float.rs +++ b/src/complex_float.rs @@ -1,7 +1,7 @@ // Keeps us from accidentally creating a recursive impl rather than a real one. #![deny(unconditional_recursion)] -use core::ops::Neg; +use core::ops::{Add, Div, Mul, Neg, Rem, Sub}; use num_traits::{Float, FloatConst, Num, NumCast}; @@ -25,7 +25,19 @@ mod private { /// /// This trait is sealed to prevent it from being implemented by anything other /// than floating point scalars and [Complex] floats. -pub trait ComplexFloat: Num + NumCast + Copy + Neg + private::Seal { +pub trait ComplexFloat: + Num + + NumCast + + Copy + + Neg + + From<::Real> + + Add<::Real, Output = Self> + + Sub<::Real, Output = Self> + + Mul<::Real, Output = Self> + + Div<::Real, Output = Self> + + Rem<::Real, Output = Self> + + private::Seal +{ /// The type used to represent the real coefficients of this complex number. type Real: Float + FloatConst;