@@ -92,11 +92,42 @@ pub struct Complex<T> {
92
92
pub im : T ,
93
93
}
94
94
95
+ /// Alias for a [`Complex<f32>`]
95
96
pub type Complex32 = Complex < f32 > ;
97
+
98
+ /// Create a new [`Complex<f32>`] with arguments that can convert [`Into<f32>`].
99
+ ///
100
+ /// ```
101
+ /// use num_complex::{c32, Complex32};
102
+ /// assert_eq!(c32(1u8, 2), Complex32::new(1.0, 2.0));
103
+ /// ```
104
+ ///
105
+ /// Note: ambiguous integer literals in Rust will [default] to `i32`, which does **not** implement
106
+ /// `Into<f32>`, so a call like `c32(1, 2)` will result in a type error. The example above uses a
107
+ /// suffixed `1u8` to set its type, and then the `2` can be inferred as the same type.
108
+ ///
109
+ /// [default]: https://doc.rust-lang.org/reference/expressions/literal-expr.html#integer-literal-expressions
110
+ #[ inline]
111
+ pub fn c32 < T : Into < f32 > > ( re : T , im : T ) -> Complex32 {
112
+ Complex :: new ( re. into ( ) , im. into ( ) )
113
+ }
114
+
115
+ /// Alias for a [`Complex<f64>`]
96
116
pub type Complex64 = Complex < f64 > ;
97
117
118
+ /// Create a new [`Complex<f64>`] with arguments that can convert [`Into<f64>`].
119
+ ///
120
+ /// ```
121
+ /// use num_complex::{c64, Complex64};
122
+ /// assert_eq!(c64(1, 2), Complex64::new(1.0, 2.0));
123
+ /// ```
124
+ #[ inline]
125
+ pub fn c64 < T : Into < f64 > > ( re : T , im : T ) -> Complex64 {
126
+ Complex :: new ( re. into ( ) , im. into ( ) )
127
+ }
128
+
98
129
impl < T > Complex < T > {
99
- /// Create a new Complex
130
+ /// Create a new ` Complex`
100
131
#[ inline]
101
132
pub const fn new ( re : T , im : T ) -> Self {
102
133
Complex { re, im }
0 commit comments