Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scalar::{one, zero} #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//! ```

use num_complex::Complex;
use num_traits::{Float, FromPrimitive, NumAssign, NumCast, NumOps, ToPrimitive, Zero};
use num_traits::{Float, FromPrimitive, NumAssign, NumCast, NumOps, One, ToPrimitive, Zero};
use rand::{distributions::Standard, prelude::*};
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display, LowerExp, UpperExp};
Expand All @@ -52,6 +52,8 @@ pub trait Scalar:
NumAssign
+ FromPrimitive
+ NumCast
+ One
+ Zero
+ Neg<Output = Self>
+ Copy
+ Clone
Expand All @@ -72,6 +74,14 @@ pub trait Scalar:
+ NumOps<Self::Real, Self::Complex>
+ NumOps<Self::Complex, Self::Complex>;

fn zero() -> Self {
Zero::zero()
}

fn one() -> Self {
One::one()
}

/// Create a new real number
fn real<T: ToPrimitive>(re: T) -> Self::Real;
/// Create a new complex number
Expand Down