Skip to main content

Rational

Struct Rational 

Source
pub struct Rational(/* private fields */);
Expand description

任意精度有理数,规范形见模块文档。

Implementations§

Source§

impl Rational

Source

pub fn zero() -> Rational

Source

pub fn one() -> Rational

Source

pub fn from_integer(v: &Integer) -> Rational

Source

pub fn from_ints(n: &Integer, d: &Integer) -> Option<Rational>

由整数分子分母构造并规范化;d = 0 返回 None

Source

pub fn is_zero(&self) -> bool

Source

pub fn is_one(&self) -> bool

Source

pub fn is_negative(&self) -> bool

Source

pub fn sign(&self) -> i32

Source

pub fn num(&self) -> Integer

Source

pub fn den(&self) -> Integer

Source

pub fn neg(&self) -> Rational

Source

pub fn abs(&self) -> Rational

Source

pub fn inv(&self) -> Option<Rational>

乘法逆元;零无逆元。

Source

pub fn add(&self, other: &Rational) -> Rational

Source

pub fn sub(&self, other: &Rational) -> Rational

Source

pub fn mul(&self, other: &Rational) -> Rational

Source

pub fn div(&self, other: &Rational) -> Option<Rational>

有理数相除;除零返回 None

Source

pub fn pow(&self, exp: u32) -> Rational

非负整数幂。规模守卫由调用方(expr 层)负责。

Source

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 案例实测)。

Source

pub fn to_f64(&self) -> f64

f64 近似(数值交叉验证路径;大数经十进制字符串中转,精度为 f64 语义)。

Source

pub fn inv_reduced(&self) -> Option<Rational>

乘法逆元(快速路径,前提:自身既约——Rational 规范形保证);零无逆元。 逆元的既约性继承自原数,跳过 gcd。

Source

pub fn cmp_integer(&self, o: &Integer) -> Ordering

与整数比较:self - o 的符号。

Trait Implementations§

Source§

impl Clone for Rational

Source§

fn clone(&self) -> Rational

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rational

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for Rational

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for Rational

Source§

impl Field for Rational

Source§

impl Hash for Rational

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Rational

Source§

fn cmp(&self, other: &Rational) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Rational

Source§

fn eq(&self, other: &Rational) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Rational

Source§

fn partial_cmp(&self, other: &Rational) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Ring for Rational

Source§

fn zero() -> Rational

Source§

fn one() -> Rational

Source§

fn from_i64_coeff(v: i64) -> Rational

由 i64 构造系数(poly 偏导的指数乘子等用途)。
Source§

fn add(&self, other: &Rational) -> Rational

Source§

fn sub(&self, other: &Rational) -> Rational

Source§

fn mul(&self, other: &Rational) -> Rational

Source§

fn neg(&self) -> Rational

Source§

fn is_zero(&self) -> bool

Source§

fn is_one(&self) -> bool

Source§

fn pow_u32(&self, e: u32) -> Rational

非负整数幂;默认重复乘,实现方可覆写快速路径。
Source§

impl StructuralPartialEq for Rational

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.