use std::fmt::{Formatter, Debug};
use std::fmt;
use std::default::Default;
use ffi;
#[doc(hidden)]
pub trait CFFI<T> {
fn wrap(s: T) -> Self;
fn unwrap(self) -> T;
}
#[doc(hidden)]
pub trait FFFI<T> {
fn wrap(self) -> T;
fn unwrap(t: T) -> Self;
}
#[repr(C)]
#[derive(Copy, PartialEq)]
pub struct ComplexF64 {
pub dat: [f64; 2]
}
impl ComplexF64 {
pub fn rect(x: f64, y: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_rect(x, y).wrap() }
}
pub fn polar(r: f64, theta: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_polar(r, theta).wrap() }
}
pub fn arg(&self) -> f64 {
unsafe { ::ffi::gsl_complex_arg(self.unwrap()) }
}
pub fn abs(&self) -> f64 {
unsafe { ::ffi::gsl_complex_abs(self.unwrap()) }
}
pub fn abs2(&self) -> f64 {
unsafe { ::ffi::gsl_complex_abs2(self.unwrap()) }
}
pub fn logabs(&self) -> f64 {
unsafe { ::ffi::gsl_complex_logabs(self.unwrap()) }
}
pub fn add(&self, other: &ComplexF64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_add(self.unwrap(), other.unwrap()).wrap() }
}
pub fn sub(&self, other: &ComplexF64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_sub(self.unwrap(), other.unwrap()).wrap() }
}
pub fn mul(&self, other: &ComplexF64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_mul(self.unwrap(), other.unwrap()).wrap() }
}
pub fn div(&self, other: &ComplexF64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_div(self.unwrap(), other.unwrap()).wrap() }
}
pub fn add_real(&self, x: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_add_real(self.unwrap(), x).wrap() }
}
pub fn sub_real(&self, x: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_sub_real(self.unwrap(), x).wrap() }
}
pub fn mul_real(&self, x: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_mul_real(self.unwrap(), x).wrap() }
}
pub fn div_real(&self, x: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_div_real(self.unwrap(), x).wrap() }
}
pub fn add_imag(&self, x: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_add_imag(self.unwrap(), x).wrap() }
}
pub fn sub_imag(&self, x: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_sub_imag(self.unwrap(), x).wrap() }
}
pub fn mul_imag(&self, x: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_mul_imag(self.unwrap(), x).wrap() }
}
pub fn div_imag(&self, x: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_div_imag(self.unwrap(), x).wrap() }
}
pub fn conjugate(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_conjugate(self.unwrap()).wrap() }
}
pub fn inverse(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_inverse(self.unwrap()).wrap() }
}
pub fn negative(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_negative(self.unwrap()).wrap() }
}
pub fn sqrt(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_sqrt(self.unwrap()).wrap() }
}
pub fn sqrt_real(x: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_sqrt_real(x).wrap() }
}
pub fn pow(&self, other: &ComplexF64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_pow(self.unwrap(), other.unwrap()).wrap() }
}
pub fn pow_real(&self, x: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_pow_real(self.unwrap(), x).wrap() }
}
pub fn exp(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_exp(self.unwrap()).wrap() }
}
pub fn log(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_log(self.unwrap()).wrap() }
}
pub fn log10(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_log10(self.unwrap()).wrap() }
}
pub fn log_b(&self, other: &ComplexF64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_log_b(self.unwrap(), other.unwrap()).wrap() }
}
pub fn sin(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_sin(self.unwrap()).wrap() }
}
pub fn cos(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_cos(self.unwrap()).wrap() }
}
pub fn tan(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_tan(self.unwrap()).wrap() }
}
pub fn sec(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_sec(self.unwrap()).wrap() }
}
pub fn csc(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_csc(self.unwrap()).wrap() }
}
pub fn cot(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_cot(self.unwrap()).wrap() }
}
pub fn arcsin(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arcsin(self.unwrap()).wrap() }
}
pub fn arcsin_real(z: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arcsin_real(z).wrap() }
}
pub fn arccos(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arccos(self.unwrap()).wrap() }
}
pub fn arccos_real(z: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arccos_real(z).wrap() }
}
pub fn arctan(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arctan(self.unwrap()).wrap() }
}
pub fn arcsec(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arcsec(self.unwrap()).wrap() }
}
pub fn arcsec_real(z: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arcsec_real(z).wrap() }
}
pub fn arccsc(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arccsc(self.unwrap()).wrap() }
}
pub fn arccsc_real(z: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arccsc_real(z).wrap() }
}
pub fn arccot(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arccot(self.unwrap()).wrap() }
}
pub fn sinh(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_sinh(self.unwrap()).wrap() }
}
pub fn cosh(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_cosh(self.unwrap()).wrap() }
}
pub fn tanh(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_tanh(self.unwrap()).wrap() }
}
pub fn sech(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_sech(self.unwrap()).wrap() }
}
pub fn csch(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_csch(self.unwrap()).wrap() }
}
pub fn coth(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_coth(self.unwrap()).wrap() }
}
pub fn arcsinh(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arcsinh(self.unwrap()).wrap() }
}
pub fn arccosh(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arccosh(self.unwrap()).wrap() }
}
pub fn arccosh_real(z: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arccosh_real(z).wrap() }
}
pub fn arctanh(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arctanh(self.unwrap()).wrap() }
}
pub fn arctanh_real(z: f64) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arctanh_real(z).wrap() }
}
pub fn arcsech(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arcsech(self.unwrap()).wrap() }
}
pub fn arccsch(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arccsch(self.unwrap()).wrap() }
}
pub fn arccoth(&self) -> ComplexF64 {
unsafe { ::ffi::gsl_complex_arccoth(self.unwrap()).wrap() }
}
}
impl Debug for ComplexF64 {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "[{}, {}]", self.dat[0], self.dat[1])
}
}
impl Clone for ComplexF64 {
fn clone(&self) -> ComplexF64 {
ComplexF64 {
dat: [self.dat[0], self.dat[1]]
}
}
}
impl Default for ComplexF64 {
fn default() -> ComplexF64 {
ComplexF64 {
dat: [0f64, 0f64]
}
}
}
impl CFFI<ffi::gsl_complex> for ComplexF64 {
fn wrap(t: ffi::gsl_complex) -> ComplexF64 {
unsafe { ::std::mem::transmute(t) }
}
fn unwrap(self) -> ffi::gsl_complex {
unsafe { ::std::mem::transmute(self) }
}
}
impl CFFI<ffi::gsl_complex_float> for ComplexF64 {
fn wrap(t: ffi::gsl_complex_float) -> ComplexF64 {
ComplexF64 {
dat: [t.dat[0] as f64, t.dat[1] as f64],
}
}
fn unwrap(self) -> ffi::gsl_complex_float {
ffi::gsl_complex_float {
dat: [self.dat[0] as f32, self.dat[1] as f32],
}
}
}
impl FFFI<ComplexF32> for ffi::gsl_complex {
fn wrap(self) -> ComplexF32 {
ComplexF32 {
dat: [self.dat[0] as f32, self.dat[1] as f32],
}
}
fn unwrap(t: ComplexF32) -> ffi::gsl_complex {
ffi::gsl_complex {
dat: [t.dat[0] as f64, t.dat[1] as f64],
}
}
}
impl FFFI<ComplexF64> for ffi::gsl_complex {
fn wrap(self) -> ComplexF64 {
unsafe { ::std::mem::transmute(self) }
}
fn unwrap(t: ComplexF64) -> ffi::gsl_complex {
unsafe { ::std::mem::transmute(t) }
}
}
#[repr(C)]
#[derive(Copy, PartialEq)]
pub struct ComplexF32 {
pub dat: [f32; 2]
}
impl ComplexF32 {
pub fn rect(x: f32, y: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_rect(x as f64, y as f64).wrap() }
}
pub fn polar(r: f32, theta: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_polar(r as f64, theta as f64).wrap() }
}
pub fn arg(&self) -> f32 {
unsafe { ::ffi::gsl_complex_arg(self.unwrap()) as f32 }
}
pub fn abs(&self) -> f32 {
unsafe { ::ffi::gsl_complex_abs(self.unwrap()) as f32 }
}
pub fn abs2(&self) -> f32 {
unsafe { ::ffi::gsl_complex_abs2(self.unwrap()) as f32 }
}
pub fn logabs(&self) -> f32 {
unsafe { ::ffi::gsl_complex_logabs(self.unwrap()) as f32 }
}
pub fn add(&self, other: &ComplexF32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_add(self.unwrap(), other.unwrap()).wrap() }
}
pub fn sub(&self, other: &ComplexF32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_sub(self.unwrap(), other.unwrap()).wrap() }
}
pub fn mul(&self, other: &ComplexF32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_mul(self.unwrap(), other.unwrap()).wrap() }
}
pub fn div(&self, other: &ComplexF32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_div(self.unwrap(), other.unwrap()).wrap() }
}
pub fn add_real(&self, x: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_add_real(self.unwrap(), x as f64).wrap() }
}
pub fn sub_real(&self, x: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_sub_real(self.unwrap(), x as f64).wrap() }
}
pub fn mul_real(&self, x: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_mul_real(self.unwrap(), x as f64).wrap() }
}
pub fn div_real(&self, x: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_div_real(self.unwrap(), x as f64).wrap() }
}
pub fn add_imag(&self, x: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_add_imag(self.unwrap(), x as f64).wrap() }
}
pub fn sub_imag(&self, x: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_sub_imag(self.unwrap(), x as f64).wrap() }
}
pub fn mul_imag(&self, x: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_mul_imag(self.unwrap(), x as f64).wrap() }
}
pub fn div_imag(&self, x: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_div_imag(self.unwrap(), x as f64).wrap() }
}
pub fn conjugate(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_conjugate(self.unwrap()).wrap() }
}
pub fn inverse(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_inverse(self.unwrap()).wrap() }
}
pub fn negative(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_negative(self.unwrap()).wrap() }
}
pub fn sqrt(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_sqrt(self.unwrap()).wrap() }
}
pub fn sqrt_real(x: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_sqrt_real(x as f64).wrap() }
}
pub fn pow(&self, other: &ComplexF32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_pow(self.unwrap(), other.unwrap()).wrap() }
}
pub fn pow_real(&self, x: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_pow_real(self.unwrap(), x as f64).wrap() }
}
pub fn exp(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_exp(self.unwrap()).wrap() }
}
pub fn log(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_log(self.unwrap()).wrap() }
}
pub fn log10(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_log10(self.unwrap()).wrap() }
}
pub fn log_b(&self, other: &ComplexF32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_log_b(self.unwrap(), other.unwrap()).wrap() }
}
pub fn sin(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_sin(self.unwrap()).wrap() }
}
pub fn cos(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_cos(self.unwrap()).wrap() }
}
pub fn tan(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_tan(self.unwrap()).wrap() }
}
pub fn sec(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_sec(self.unwrap()).wrap() }
}
pub fn csc(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_csc(self.unwrap()).wrap() }
}
pub fn cot(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_cot(self.unwrap()).wrap() }
}
pub fn arcsin(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arcsin(self.unwrap()).wrap() }
}
pub fn arcsin_real(z: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arcsin_real(z as f64).wrap() }
}
pub fn arccos(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arccos(self.unwrap()).wrap() }
}
pub fn arccos_real(z: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arccos_real(z as f64).wrap() }
}
pub fn arctan(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arctan(self.unwrap()).wrap() }
}
pub fn arcsec(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arcsec(self.unwrap()).wrap() }
}
pub fn arcsec_real(z: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arcsec_real(z as f64).wrap() }
}
pub fn arccsc(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arccsc(self.unwrap()).wrap() }
}
pub fn arccsc_real(z: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arccsc_real(z as f64).wrap() }
}
pub fn arccot(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arccot(self.unwrap()).wrap() }
}
pub fn sinh(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_sinh(self.unwrap()).wrap() }
}
pub fn cosh(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_cosh(self.unwrap()).wrap() }
}
pub fn tanh(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_tanh(self.unwrap()).wrap() }
}
pub fn sech(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_sech(self.unwrap()).wrap() }
}
pub fn csch(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_csch(self.unwrap()).wrap() }
}
pub fn coth(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_coth(self.unwrap()).wrap() }
}
pub fn arcsinh(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arcsinh(self.unwrap()).wrap() }
}
pub fn arccosh(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arccosh(self.unwrap()).wrap() }
}
pub fn arccosh_real(z: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arccosh_real(z as f64).wrap() }
}
pub fn arctanh(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arctanh(self.unwrap()).wrap() }
}
pub fn arctanh_real(z: f32) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arctanh_real(z as f64).wrap() }
}
pub fn arcsech(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arcsech(self.unwrap()).wrap() }
}
pub fn arccsch(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arccsch(self.unwrap()).wrap() }
}
pub fn arccoth(&self) -> ComplexF32 {
unsafe { ::ffi::gsl_complex_arccoth(self.unwrap()).wrap() }
}
}
impl Debug for ComplexF32 {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "[{}, {}]", self.dat[0], self.dat[1])
}
}
impl Clone for ComplexF32 {
fn clone(&self) -> ComplexF32 {
ComplexF32 {
dat: [self.dat[0], self.dat[1]]
}
}
}
impl Default for ComplexF32 {
fn default() -> ComplexF32 {
ComplexF32 {
dat: [0f32, 0f32]
}
}
}
impl CFFI<ffi::gsl_complex> for ComplexF32 {
fn wrap(s: ffi::gsl_complex) -> ComplexF32 {
ComplexF32 {
dat: [s.dat[0] as f32, s.dat[1] as f32],
}
}
fn unwrap(self) -> ffi::gsl_complex {
ffi::gsl_complex {
dat: [self.dat[0] as f64, self.dat[1] as f64],
}
}
}
impl CFFI<ffi::gsl_complex_float> for ComplexF32 {
fn wrap(s: ffi::gsl_complex_float) -> ComplexF32 {
unsafe { ::std::mem::transmute(s) }
}
fn unwrap(self) -> ffi::gsl_complex_float {
unsafe { ::std::mem::transmute(self) }
}
}
#[test]
fn complex_f64() {
let v = ComplexF64::rect(10., 10.);
assert_eq!(v, ComplexF64 { dat: [10., 10.] });
let v2 = ComplexF64::rect(1., -1.);
assert_eq!(v2, ComplexF64 { dat: [1., -1.] });
let v = ComplexF64::polar(5., 7.);
assert_eq!(format!("{:.4} {:.4}", v.dat[0], v.dat[1]), "3.7695 3.2849".to_owned());
let arg = v.arg();
assert_eq!(format!("{:.4}", arg), "0.7168".to_owned());
let arg = v.abs();
assert_eq!(format!("{:.3}", arg), "5.000".to_owned());
let arg = v.abs2();
assert_eq!(format!("{:.3}", arg), "25.000".to_owned());
let arg = v.logabs();
assert_eq!(format!("{:.4}", arg), "1.6094".to_owned());
let v3 = v.add(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "4.7695 2.2849".to_owned());
let v3 = v.sub(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.7695 4.2849".to_owned());
let v3 = v.mul(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "7.0544 -0.4846".to_owned());
let v3 = v.div(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2423 3.5272".to_owned());
let v3 = v.add_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "8.7695 3.2849".to_owned());
let v3 = v.sub_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-1.2305 3.2849".to_owned());
let v3 = v.mul_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "18.8476 16.4247".to_owned());
let v3 = v.div_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.7539 0.6570".to_owned());
let v3 = v.add_imag(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 8.2849".to_owned());
let v3 = v.sub_imag(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 -1.7151".to_owned());
let v3 = v.mul_imag(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-16.4247 18.8476".to_owned());
let v3 = v.div_imag(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.6570 -0.7539".to_owned());
let v3 = v.conjugate();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 -3.2849".to_owned());
let v3 = v.inverse();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1508 -0.1314".to_owned());
let v3 = v.negative();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-3.7695 -3.2849".to_owned());
let v3 = v.sqrt();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.0940 0.7844".to_owned());
let v3 = ComplexF64::sqrt_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.2361 0.0000".to_owned());
let v3 = v.pow(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "6.4240 -7.9737".to_owned());
let v3 = v.pow_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-2824.0381 -1338.0708".to_owned());
let v3 = v.exp();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-42.9142 -6.1938".to_owned());
let v3 = v.log();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.6094 0.7168".to_owned());
let v3 = v.log10();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.6990 0.3113".to_owned());
let v3 = v.log_b(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0071 2.0523".to_owned());
let v3 = v.sin();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-7.8557 -10.7913".to_owned());
let v3 = v.cos();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-10.8216 7.8337".to_owned());
let v3 = v.tan();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0027 0.9991".to_owned());
let v3 = v.sec();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0606 -0.0439".to_owned());
let v3 = v.csc();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0441 0.0606".to_owned());
let v3 = v.cot();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0027 -1.0009".to_owned());
let v3 = v.arcsin();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.8440 2.3014".to_owned());
let v3 = ComplexF64::arcsin_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.5708 -2.2924".to_owned());
let v3 = v.arccos();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.7268 -2.3014".to_owned());
let v3 = ComplexF64::arccos_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0000 2.2924".to_owned());
let v3 = v.arctan();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.4186 0.1291".to_owned());
let v3 = v.arcsec();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.4208 0.1325".to_owned());
let v3 = ComplexF64::arcsec_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.3694 0.0000".to_owned());
let v3 = v.arccsc();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1500 -0.1325".to_owned());
let v3 = ComplexF64::arccsc_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2014 0.0000".to_owned());
let v3 = v.arccot();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1522 -0.1291".to_owned());
let v3 = v.sinh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-21.4457 -3.0986".to_owned());
let v3 = v.cosh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-21.4685 -3.0953".to_owned());
let v3 = v.tanh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.9990 0.0003".to_owned());
let v3 = v.sech();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0456 0.0066".to_owned());
let v3 = v.csch();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0457 0.0066".to_owned());
let v3 = v.coth();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.0010 -0.0003".to_owned());
let v3 = v.arcsinh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.3041 0.7070".to_owned());
let v3 = v.arccosh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.3014 0.7268".to_owned());
let v3 = ComplexF64::arccosh_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.2924 0.0000".to_owned());
let v3 = v.arctanh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1493 1.4372".to_owned());
let v3 = ComplexF64::arctanh_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2027 -1.5708".to_owned());
let v3 = v.arcsech();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1325 -1.4208".to_owned());
let v3 = v.arccsch();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1515 -0.1303".to_owned());
let v3 = v.arccoth();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1493 -0.1336".to_owned());
}
#[test]
fn complex_f32() {
let v = ComplexF32::rect(10., 10.);
assert_eq!(v, ComplexF32 { dat: [10., 10.] });
let v2 = ComplexF32::rect(1., -1.);
assert_eq!(v2, ComplexF32 { dat: [1., -1.] });
let v = ComplexF32::polar(5., 7.);
assert_eq!(format!("{:.4} {:.4}", v.dat[0], v.dat[1]), "3.7695 3.2849".to_owned());
let arg = v.arg();
assert_eq!(format!("{:.4}", arg), "0.7168".to_owned());
let arg = v.abs();
assert_eq!(format!("{:.3}", arg), "5.000".to_owned());
let arg = v.abs2();
assert_eq!(format!("{:.3}", arg), "25.000".to_owned());
let arg = v.logabs();
assert_eq!(format!("{:.4}", arg), "1.6094".to_owned());
let v3 = v.add(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "4.7695 2.2849".to_owned());
let v3 = v.sub(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.7695 4.2849".to_owned());
let v3 = v.mul(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "7.0544 -0.4846".to_owned());
let v3 = v.div(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2423 3.5272".to_owned());
let v3 = v.add_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "8.7695 3.2849".to_owned());
let v3 = v.sub_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-1.2305 3.2849".to_owned());
let v3 = v.mul_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "18.8476 16.4247".to_owned());
let v3 = v.div_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.7539 0.6570".to_owned());
let v3 = v.add_imag(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 8.2849".to_owned());
let v3 = v.sub_imag(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 -1.7151".to_owned());
let v3 = v.mul_imag(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-16.4247 18.8476".to_owned());
let v3 = v.div_imag(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.6570 -0.7539".to_owned());
let v3 = v.conjugate();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 -3.2849".to_owned());
let v3 = v.inverse();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1508 -0.1314".to_owned());
let v3 = v.negative();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-3.7695 -3.2849".to_owned());
let v3 = v.sqrt();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.0940 0.7844".to_owned());
let v3 = ComplexF32::sqrt_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.2361 0.0000".to_owned());
let v3 = v.pow(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "6.4240 -7.9737".to_owned());
let v3 = v.pow_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-2824.0381 -1338.0712".to_owned());
let v3 = v.exp();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-42.9142 -6.1938".to_owned());
let v3 = v.log();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.6094 0.7168".to_owned());
let v3 = v.log10();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.6990 0.3113".to_owned());
let v3 = v.log_b(&v2);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0071 2.0523".to_owned());
let v3 = v.sin();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-7.8557 -10.7913".to_owned());
let v3 = v.cos();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-10.8216 7.8337".to_owned());
let v3 = v.tan();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0027 0.9991".to_owned());
let v3 = v.sec();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0606 -0.0439".to_owned());
let v3 = v.csc();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0441 0.0606".to_owned());
let v3 = v.cot();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0027 -1.0009".to_owned());
let v3 = v.arcsin();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.8440 2.3014".to_owned());
let v3 = ComplexF32::arcsin_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.5708 -2.2924".to_owned());
let v3 = v.arccos();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.7268 -2.3014".to_owned());
let v3 = ComplexF32::arccos_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0000 2.2924".to_owned());
let v3 = v.arctan();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.4186 0.1291".to_owned());
let v3 = v.arcsec();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.4208 0.1325".to_owned());
let v3 = ComplexF32::arcsec_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.3694 0.0000".to_owned());
let v3 = v.arccsc();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1500 -0.1325".to_owned());
let v3 = ComplexF32::arccsc_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2014 0.0000".to_owned());
let v3 = v.arccot();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1522 -0.1291".to_owned());
let v3 = v.sinh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-21.4457 -3.0986".to_owned());
let v3 = v.cosh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-21.4685 -3.0953".to_owned());
let v3 = v.tanh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.9990 0.0003".to_owned());
let v3 = v.sech();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0456 0.0066".to_owned());
let v3 = v.csch();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0457 0.0066".to_owned());
let v3 = v.coth();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.0010 -0.0003".to_owned());
let v3 = v.arcsinh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.3041 0.7070".to_owned());
let v3 = v.arccosh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.3014 0.7268".to_owned());
let v3 = ComplexF32::arccosh_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.2924 0.0000".to_owned());
let v3 = v.arctanh();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1493 1.4372".to_owned());
let v3 = ComplexF32::arctanh_real(5.);
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2027 -1.5708".to_owned());
let v3 = v.arcsech();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1325 -1.4208".to_owned());
let v3 = v.arccsch();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1515 -0.1303".to_owned());
let v3 = v.arccoth();
assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1493 -0.1336".to_owned());
}