pub struct HalfInteger { /* private fields */ }Expand description
Half-integer: numbers of the form n/2 where n ∈ ℤ
E₈ root coordinates are half-integers (elements of ℤ ∪ ½ℤ).
This type represents them exactly as numerator / 2.
§Invariant
The denominator is always 2 (enforced by construction).
§Examples
use atlas_embeddings::arithmetic::HalfInteger;
let x = HalfInteger::new(1); // 1/2
let y = HalfInteger::new(3); // 3/2
let sum = x + y; // 2 = 4/2
assert_eq!(sum.numerator(), 4);Implementations§
Source§impl HalfInteger
impl HalfInteger
Sourcepub const fn new(numerator: i64) -> Self
pub const fn new(numerator: i64) -> Self
Create a half-integer from a numerator (denominator is always 2)
§Examples
use atlas_embeddings::arithmetic::HalfInteger;
let half = HalfInteger::new(1); // 1/2
let one = HalfInteger::new(2); // 2/2 = 1
let neg_half = HalfInteger::new(-1); // -1/2Sourcepub const fn from_integer(n: i64) -> Self
pub const fn from_integer(n: i64) -> Self
Create from an integer (multiply by 2 internally)
§Examples
use atlas_embeddings::arithmetic::HalfInteger;
let two = HalfInteger::from_integer(1); // 2/2 = 1
assert_eq!(two.numerator(), 2);Sourcepub fn to_rational(self) -> Rational
pub fn to_rational(self) -> Rational
Convert to rational number
Sourcepub fn from_rational(r: Rational) -> Self
pub fn from_rational(r: Rational) -> Self
Sourcepub const fn is_integer(self) -> bool
pub const fn is_integer(self) -> bool
Check if this is an integer (numerator is even)
Sourcepub const fn as_integer(self) -> Option<i64>
pub const fn as_integer(self) -> Option<i64>
Get as integer if possible
Trait Implementations§
Source§impl Add for HalfInteger
impl Add for HalfInteger
Source§impl Clone for HalfInteger
impl Clone for HalfInteger
Source§fn clone(&self) -> HalfInteger
fn clone(&self) -> HalfInteger
Returns a duplicate of the value. Read more
1.0.0 · 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 HalfInteger
impl Debug for HalfInteger
Source§impl Display for HalfInteger
impl Display for HalfInteger
Source§impl Hash for HalfInteger
impl Hash for HalfInteger
Source§impl Mul for HalfInteger
impl Mul for HalfInteger
Source§impl Neg for HalfInteger
impl Neg for HalfInteger
Source§impl Ord for HalfInteger
impl Ord for HalfInteger
Source§fn cmp(&self, other: &HalfInteger) -> Ordering
fn cmp(&self, other: &HalfInteger) -> Ordering
1.21.0 · 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 HalfInteger
impl PartialEq for HalfInteger
Source§impl PartialOrd for HalfInteger
impl PartialOrd for HalfInteger
Source§impl Sub for HalfInteger
impl Sub for HalfInteger
Source§impl Zero for HalfInteger
impl Zero for HalfInteger
impl Copy for HalfInteger
impl Eq for HalfInteger
impl StructuralPartialEq for HalfInteger
Auto Trait Implementations§
impl Freeze for HalfInteger
impl RefUnwindSafe for HalfInteger
impl Send for HalfInteger
impl Sync for HalfInteger
impl Unpin for HalfInteger
impl UnwindSafe for HalfInteger
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