pub struct HPN { /* private fields */ }
Expand description
Primary struct backing the HPN engine.
Implementations§
Source§impl HPN
impl HPN
Sourcepub fn clear_tape(&mut self)
pub fn clear_tape(&mut self)
Clears the history for this calculator object. Does not alter the stack or memory.
Sourcepub fn evaluate(&mut self, line: &str)
pub fn evaluate(&mut self, line: &str)
Parses and evaluates the given string, applying each change in turn.
use hpn::prelude::*;
let mut hp = HPN::default();
hp.evaluate("4 3 2 1");
println!("{hp}");
// Output:
// 0: [ T: 0.000 | Z: 0.000 | Y: 0.000 | X: 0.000 ] <- 4
// 1: [ T: 0.000 | Z: 0.000 | Y: 0.000 | X: 4.000 ] <- 3
// 2: [ T: 0.000 | Z: 0.000 | Y: 4.000 | X: 3.000 ] <- 2
// 3: [ T: 0.000 | Z: 4.000 | Y: 3.000 | X: 2.000 ] <- 1
// 4: [ T: 4.000 | Z: 3.000 | Y: 2.000 | X: 1.000 ]
Sourcepub fn x(&self) -> &Number
pub fn x(&self) -> &Number
Returns the value of the x
register.
assert_eq!(*hp.x(), Number::zero());
Sourcepub fn y(&self) -> &Number
pub fn y(&self) -> &Number
Returns the value of the y
register.
assert_eq!(*hp.y(), Number::one());
Sourcepub fn z(&self) -> &Number
pub fn z(&self) -> &Number
Returns the value of the z
register.
let hp = HPN::from("3 2 1 0");
assert_eq!(*hp.z(), Number::from(2));
Sourcepub fn t(&self) -> &Number
pub fn t(&self) -> &Number
Returns the value of the t
register.
let hp = HPN::from("3 2 1 0");
assert_eq!(*hp.t(), Number::from(3));
Trait Implementations§
Source§impl Default for HPN
Constructs new HPN instance, with emtpy tape and 0 in each register.
impl Default for HPN
Constructs new HPN instance, with emtpy tape and 0 in each register.
use hpn::prelude::*;
let mut hp = HPN::default();
Auto Trait Implementations§
impl Freeze for HPN
impl RefUnwindSafe for HPN
impl Send for HPN
impl Sync for HPN
impl Unpin for HPN
impl UnwindSafe for HPN
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