pub enum Nums {
Real(f32),
Complex(CNum),
Quaternion(QNum),
}Expand description
Enum for convenient work with different types of numbers
Перечисление для удобной работы с разными видами чисел
Variants§
Implementations§
source§impl Nums
impl Nums
sourcepub fn conj(&self) -> Self
pub fn conj(&self) -> Self
The method for obtaining the conjugate number
Метод для получения сопряженного числа
Example
use tmn::Nums;
use tmn::quaternion::QNum;
let a = Nums::Quaternion(QNum::make_from_r(1_f32, 1_f32, 1_f32, 1_f32));
let b = a.conj();
match b{
Nums::Quaternion(qnum)=>{
assert_eq!((1_f32, -1_f32, -1_f32, -1_f32), qnum.get())
},
_=>panic!("WrongType of Nums")
}use tmn::Nums;
use tmn::complex::CNum;
let a = Nums::Complex(CNum::make(1_f32, 1_f32));
let b = a.conj();
match b{
Nums::Complex(cnum)=>{
assert_eq!((1_f32, -1_f32), cnum.get())
},
_=>panic!("WrongType of Nums")
}sourcepub fn rot(&self, ang: f32, o: (f32, f32, f32)) -> Self
pub fn rot(&self, ang: f32, o: (f32, f32, f32)) -> Self
The method for rotating a number around the axis given by the vector ‘o’ by the angle ‘ang’ (Angle in degrees). The axis of rotation only affects the rotation of the quaternion.
Метод для вращения числа вокруг оси, заданной вектором ‘o’ на угол ‘ang’ (Угол в градусах). Ось вращения влияет только на поворот кватерниона.
Example
use tmn::Nums;
use tmn::quaternion::QNum;
let mut a = Nums::Quaternion(QNum::make_from_r(0_f32, 1_f32, 0_f32, 0_f32));
a = a.rot(90_f32, (0_f32, 0_f32, 1_f32));
match a {
Nums::Quaternion(qnum)=>{
let (r, i, j, k) = qnum.get();//0.0000001 - точность расчетов
//Ожидаемый ответ 0, 0, 1, 0
assert!((r-0_f32).abs() < 0.0000001);
assert!((i-0_f32).abs() < 0.0000001);
assert!((j-1_f32).abs() < 0.0000001);
assert!((k-0_f32).abs() < 0.0000001);
},
_=>panic!("WrongType of Nums")
}sourcepub fn set(&self, c: u8, v: f32) -> Self
pub fn set(&self, c: u8, v: f32) -> Self
The method for setting values to specific coefficients
Метод для установки значений в конкретные коэффициенты
Example
use tmn::{Nums, complex};
use tmn::complex::CNum;
let mut a = Nums::Complex(CNum::make_zero());
a = a.set(complex::R|complex::I, 3_f32);
assert!(Nums::Complex(CNum::make(3_f32, 3_f32))==a);Trait Implementations§
source§impl Add<Nums> for Nums
impl Add<Nums> for Nums
source§fn add(self, rhs: Self) -> Self::Output
fn add(self, rhs: Self) -> Self::Output
The method returns the sum of two Nums elements
Метод возвращает сумму двух элементов Nums
Examples
use tmn::Nums;
use tmn::complex::CNum;
use tmn::quaternion::QNum;
let a = Nums::Quaternion(QNum::make_from_r(0_f32, 0_f32, 1_f32, 1_f32));
let b = Nums::Complex(CNum::make(1_f32, 1_f32));
let c = a+b;
assert!(Nums::Quaternion(QNum::make_from_r(1_f32,1_f32,1_f32,1_f32))==c);source§impl Mul<Nums> for Nums
impl Mul<Nums> for Nums
source§fn mul(self, rhs: Self) -> Self::Output
fn mul(self, rhs: Self) -> Self::Output
The method returns the product of two Nums elements
Метод возвращает произведение двух элементов Nums
Examples
use tmn::Nums;
use tmn::complex::CNum;
use tmn::quaternion::QNum;
let a = Nums::Quaternion(QNum::make_from_r(0_f32, 4_f32, 7_f32, 1_f32));
let b = Nums::Complex(CNum::make(43_f32, 2_f32));
let c = a*b;
assert!(Nums::Quaternion(QNum::make_from_r(-8_f32, 172_f32, 303_f32, 29_f32))==c);source§impl Neg for Nums
impl Neg for Nums
source§fn neg(self) -> Self::Output
fn neg(self) -> Self::Output
Redefined negative operator
Переопределенный оператор отрицательного значения
Example
use tmn::Nums;
use tmn::quaternion::QNum;
let qnum = Nums::Quaternion(-QNum::make_from_r(3_f32, 4_f32, 1_f32, 2_f32));
assert!(qnum== Nums::Quaternion(QNum::make_from_r(-3_f32, -4_f32, -1_f32, -2_f32)));