File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed
Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -42,10 +42,31 @@ impl Scalar for f64 {}
4242impl Scalar for c32 { }
4343impl Scalar for c64 { }
4444
45- pub trait RealScalar : Scalar + Float + Sum { }
45+ pub trait RealScalar : Scalar + Float + Sum {
46+ fn from_f64 ( f64 ) -> Self ;
47+ }
48+
49+ impl RealScalar for f32 {
50+ fn from_f64 ( f : f64 ) -> Self {
51+ f as f32
52+ }
53+ }
54+ impl RealScalar for f64 {
55+ fn from_f64 ( f : f64 ) -> Self {
56+ f
57+ }
58+ }
4659
47- impl RealScalar for f32 { }
48- impl RealScalar for f64 { }
60+ /// Convert `f64` into `RealScalar`
61+ ///
62+ /// ```rust
63+ /// fn mult2<A: RealScalar>(a: A) -> A {
64+ /// a * into_real(2.0);
65+ /// }
66+ /// ```
67+ pub fn into_real < T : RealScalar > ( f : f64 ) -> T {
68+ T :: from_f64 ( f)
69+ }
4970
5071/// Define associating real float type
5172pub trait AssociatedReal : Sized {
You can’t perform that action at this time.
0 commit comments