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).
Trait Implementations§
Source§impl Clone for LogosRational
impl Clone for LogosRational
Source§fn clone(&self) -> LogosRational
fn clone(&self) -> LogosRational
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LogosRational
impl Debug for LogosRational
Source§impl Display for LogosRational
impl Display for LogosRational
Source§impl From<i64> for LogosRational
impl From<i64> for LogosRational
Source§impl Hash for LogosRational
impl Hash for LogosRational
Source§impl Ord for LogosRational
impl Ord for LogosRational
Source§fn cmp(&self, other: &LogosRational) -> Ordering
fn cmp(&self, other: &LogosRational) -> Ordering
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
Source§impl PartialEq for LogosRational
impl PartialEq for LogosRational
Source§fn eq(&self, other: &LogosRational) -> bool
fn eq(&self, other: &LogosRational) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl PartialOrd for LogosRational
impl PartialOrd for 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
Mutably borrows from an owned value. Read more
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
Checks if this value is equivalent to the given key. Read more
§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
Compare self to
key and return true if they are equal.