pub struct LogosRational(pub Rational);Expand description
Exact rational number for compiled LOGOS programs — the AOT counterpart of the
interpreter’s RuntimeValue::Rational.
Wraps the always-reduced logicaffeine_base::Rational (a BigInt numerator over a
positive BigInt denominator) so a Let x: Rational be 7 / 2 compiles to an exact
7/2 instead of flooring to 3. The type-directed resolve_divisions pass only ever
produces these in a Rational-typed context, so the integer floor default is untouched.
Display reduces a whole value to a bare integer (6 / 2 → "3"), matching the interpreter.
Tuple Fields§
§0: RationalImplementations§
Source§impl LogosRational
impl LogosRational
Sourcepub fn from_ratio(n: i64, d: i64) -> Self
pub fn from_ratio(n: i64, d: i64) -> Self
The exact quotient n / d. Panics on a zero denominator, mirroring integer / 0.
pub fn add(&self, other: &LogosRational) -> LogosRational
pub fn sub(&self, other: &LogosRational) -> LogosRational
pub fn mul(&self, other: &LogosRational) -> LogosRational
Sourcepub fn div_exact(&self, other: &LogosRational) -> LogosRational
pub fn div_exact(&self, other: &LogosRational) -> LogosRational
Exact division. Panics on a zero divisor, mirroring integer / 0.
Sourcepub fn abs(&self) -> LogosRational
pub fn abs(&self) -> LogosRational
The exact absolute value (a rational stays a rational: |-7/2| = 7/2).
Sourcepub fn floor(&self) -> i64
pub fn floor(&self) -> i64
The greatest integer ≤ this rational (toward −∞), computed EXACTLY on the
BigInt numerator/denominator — never through a lossy f64.
Sourcepub fn round(&self) -> i64
pub fn round(&self) -> i64
The nearest integer, ties away from zero (matching f64::round), computed exactly.
Sourcepub fn quotient(&self, other: &LogosRational) -> LogosRational
pub fn quotient(&self, other: &LogosRational) -> LogosRational
self / other: two whole values truncate as integers do, and otherwise the quotient is exact.
Sourcepub fn remainder(&self, other: &LogosRational) -> LogosRational
pub fn remainder(&self, other: &LogosRational) -> LogosRational
self % other: the remainder of two whole values, its sign the dividend’s; a fraction has none.
Sourcepub fn floor_quotient(&self, other: &LogosRational) -> LogosRational
pub fn floor_quotient(&self, other: &LogosRational) -> LogosRational
self // other: the floor of the exact quotient.
Sourcepub fn power(&self, other: &LogosRational) -> LogosRational
pub fn power(&self, other: &LogosRational) -> LogosRational
self ** other: a whole base takes an integer’s power, a fraction a rational’s.
Sourcepub fn bit_and(&self, other: &LogosRational) -> i64
pub fn bit_and(&self, other: &LogosRational) -> i64
self & other of two whole values.
Sourcepub fn bit_or(&self, other: &LogosRational) -> i64
pub fn bit_or(&self, other: &LogosRational) -> i64
self | other of two whole values.
Sourcepub fn bit_xor(&self, other: &LogosRational) -> i64
pub fn bit_xor(&self, other: &LogosRational) -> i64
self ^ other of two whole values.
Sourcepub fn shl(&self, other: &LogosRational) -> i64
pub fn shl(&self, other: &LogosRational) -> i64
self << other of two whole values.
Sourcepub fn shr(&self, other: &LogosRational) -> i64
pub fn shr(&self, other: &LogosRational) -> i64
self >> other of two whole values.
Sourcepub fn order_real(&self, other: f64) -> Option<Ordering>
pub fn order_real(&self, other: f64) -> Option<Ordering>
How this compares with the real other, by that real’s exact value; None against NaN.
Trait Implementations§
Source§impl Add for LogosRational
impl Add for LogosRational
Source§type Output = LogosRational
type Output = LogosRational
+ operator.Source§fn add(self, other: LogosRational) -> LogosRational
fn add(self, other: LogosRational) -> LogosRational
+ operation. Read moreSource§impl Clone for LogosRational
impl Clone for LogosRational
Source§fn clone(&self) -> LogosRational
fn clone(&self) -> LogosRational
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LogosRational
impl Debug for LogosRational
Source§impl Default for LogosRational
The placeholder #[derive(Default)] on a record needs. The language holds nothing in a rational field a record is
built without, which a LogosRational cannot hold, so a compiled construction that leaves one unset is refused
and this value is never observed.
impl Default for LogosRational
The placeholder #[derive(Default)] on a record needs. The language holds nothing in a rational field a record is
built without, which a LogosRational cannot hold, so a compiled construction that leaves one unset is refused
and this value is never observed.
Source§impl Display for LogosRational
impl Display for LogosRational
Source§impl Div for LogosRational
impl Div for LogosRational
Source§type Output = LogosRational
type Output = LogosRational
/ operator.Source§fn div(self, other: LogosRational) -> LogosRational
fn div(self, other: LogosRational) -> LogosRational
/ operation. Read moreSource§impl From<LogosInt> for LogosRational
impl From<LogosInt> for LogosRational
Source§impl From<LogosRational> for LogosValue
impl From<LogosRational> for LogosValue
Source§fn from(r: LogosRational) -> Self
fn from(r: LogosRational) -> Self
Source§impl From<i64> for LogosRational
impl From<i64> for LogosRational
Source§impl Hash for LogosRational
impl Hash for LogosRational
Source§impl Mul for LogosRational
impl Mul for LogosRational
Source§type Output = LogosRational
type Output = LogosRational
* operator.Source§fn mul(self, other: LogosRational) -> LogosRational
fn mul(self, other: LogosRational) -> LogosRational
* operation. Read moreSource§impl Ord for LogosRational
impl Ord for LogosRational
Source§fn cmp(&self, other: &LogosRational) -> Ordering
fn cmp(&self, other: &LogosRational) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for LogosRational
impl PartialEq for LogosRational
Source§impl PartialOrd for LogosRational
impl PartialOrd for LogosRational
Source§impl Sub for LogosRational
impl Sub for LogosRational
Source§type Output = LogosRational
type Output = LogosRational
- operator.Source§fn sub(self, other: LogosRational) -> LogosRational
fn sub(self, other: LogosRational) -> LogosRational
- operation. Read moreSource§impl ToRationals for LogosRational
impl ToRationals for LogosRational
Source§type Rationals = LogosRational
type Rationals = LogosRational
fn to_rationals(&self) -> LogosRational
impl Eq for LogosRational
impl StructuralPartialEq for LogosRational
Auto Trait Implementations§
impl Freeze for LogosRational
impl RefUnwindSafe for LogosRational
impl Send for LogosRational
impl Sync for LogosRational
impl Unpin for LogosRational
impl UnsafeUnpin for LogosRational
impl UnwindSafe for LogosRational
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.