Refactor cmath constants.
// TODO: Keep track of rust-num/num-complex/issues/2. A common trait could help with duplication
// that exists between cmath and math.
-use crate::{PyObjectRef, VirtualMachine};
-
-pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {
- let module = cmath::make_module(vm);
- let ctx = &vm.ctx;
- extend_module!(vm, module, {
- // Constants:
- "pi" => ctx.new_float(std::f64::consts::PI),
- "e" => ctx.new_float(std::f64::consts::E),
- "tau" => ctx.new_float(2.0 * std::f64::consts::PI),
- "inf" => ctx.new_float(f64::INFINITY),
- "infj" => ctx.new_complex(num_complex::Complex64::new(0., std::f64::INFINITY)),
- "nan" => ctx.new_float(f64::NAN),
- "nanj" => ctx.new_complex(num_complex::Complex64::new(0., std::f64::NAN)),
- });
-
- module
-}
+pub(crate) use cmath::make_module;
/// This module provides access to mathematical functions for complex numbers.
#[pymodule]
@@ -29,6 +12,16 @@ mod cmath {
};
use num_complex::Complex64;
+ // Constants
+ #[pyattr]
+ use std::f64::consts::{E as e, PI as pi, TAU as tau};
+ #[pyattr]
+ use std::f64::{INFINITY as inf, NAN as nan};
+ #[pyattr(name = "infj")]
+ const INFJ: Complex64 = Complex64::new(0., std::f64::INFINITY);
+ #[pyattr(name = "nanj")]
+ const NANJ: Complex64 = Complex64::new(0., std::f64::NAN);
+
/// Return argument, also known as the phase angle, of a complex.
#[pyfunction]
fn phase(z: IntoPyComplex) -> f64 {
