pub struct Rational(/* private fields */);Expand description
任意精度有理数,规范形见模块文档。
Implementations§
Source§impl Rational
impl Rational
pub fn zero() -> Rational
pub fn one() -> Rational
pub fn from_integer(v: &Integer) -> Rational
pub fn is_zero(&self) -> bool
pub fn is_one(&self) -> bool
pub fn is_negative(&self) -> bool
pub fn sign(&self) -> i32
pub fn num(&self) -> Integer
pub fn den(&self) -> Integer
pub fn neg(&self) -> Rational
pub fn abs(&self) -> Rational
pub fn add(&self, other: &Rational) -> Rational
pub fn sub(&self, other: &Rational) -> Rational
pub fn mul(&self, other: &Rational) -> Rational
Sourcepub fn pow_reduced(&self, exp: u32) -> Rational
pub fn pow_reduced(&self, exp: u32) -> Rational
非负整数幂(快速路径):既约有理数的幂仍既约——gcd(num,den)^m = 1,
无需再跑 gcd。大幂折叠产生几万比特常数时 gcd 是平方级瓶颈
(perf_probe case 1431 实测),此路径跳过它。
落位判定必须与 from_big_parts 一致:分母按 u64 判(不是 i64), 否则同值出现两种表示,破坏“规范形与表示无关“(29^13 案例实测)。
Sourcepub fn inv_reduced(&self) -> Option<Rational>
pub fn inv_reduced(&self) -> Option<Rational>
乘法逆元(快速路径,前提:自身既约——Rational 规范形保证);零无逆元。 逆元的既约性继承自原数,跳过 gcd。
Sourcepub fn cmp_integer(&self, o: &Integer) -> Ordering
pub fn cmp_integer(&self, o: &Integer) -> Ordering
与整数比较:self - o 的符号。
Trait Implementations§
impl Eq for Rational
Source§impl Ord for Rational
impl Ord for Rational
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for Rational
impl PartialOrd for Rational
Source§impl Ring for Rational
impl Ring for Rational
fn zero() -> Rational
fn one() -> Rational
Source§fn from_i64_coeff(v: i64) -> Rational
fn from_i64_coeff(v: i64) -> Rational
由 i64 构造系数(poly 偏导的指数乘子等用途)。
fn add(&self, other: &Rational) -> Rational
fn sub(&self, other: &Rational) -> Rational
fn mul(&self, other: &Rational) -> Rational
fn neg(&self) -> Rational
fn is_zero(&self) -> bool
fn is_one(&self) -> bool
impl StructuralPartialEq for Rational
Auto Trait Implementations§
impl Freeze for Rational
impl RefUnwindSafe for Rational
impl Send for Rational
impl Sync for Rational
impl Unpin for Rational
impl UnsafeUnpin for Rational
impl UnwindSafe for Rational
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more