pub struct iBase { /* private fields */ }

Implementations§

Trait Implementations§

source§

impl Add<iBase> for iBase

iBase instances can be added together just like regular numbers unsing the ‘+’ operator. Do note however that the resulting iBase instance will be of the same base as the first term. iBase instances of different bases can be added together without issue.

Example:

    // create the iBase instances
    let number1 = iBase::from_string(20, "-1287");
    assert_eq!(number1.as_decimal(), -8967);

    let number2 = iBase::from_string(15, "1238970");
    assert_eq!(number2.as_decimal(), 13090380);

    // add the numbers
    let res = number1 + number2;
    assert_eq!(res.base(), 20); // because number1 is of base 20, res will also be of base 20

    assert_eq!(res.as_decimal(), -8967 + 13090380);
§

type Output = iBase

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl Clone for iBase

source§

fn clone(&self) -> iBase

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for iBase

source§

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

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

impl Display for iBase

source§

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

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

impl Div<iBase> for iBase

iBase instances can be divided just like normal numbers using the ‘/’ operator. Do note however that the resulting iBase instance will be of the same base as the numerator. iBase instances of different bases can be divided without issue.

This operation works just like regular integer division; that is, the quotient is rounded down to the nearest whole number.

Example:


    // create the iBase instances
    let number1 = iBase::from_string(17, "-AB123");
    assert_eq!(number1.as_decimal(), -889579);

    let number2 = iBase::from_string(7, "456");
    assert_eq!(number2.as_decimal(), 237);

    // divide the numbers
    let res = number1 / number2;

    assert_eq!(res.as_decimal(), -889579 / 237);

Do also note that if the absolute valut of the demomenator is greater than the absolute value of the numerator, the quotient will always be 0 (in whatever base the operation is performed)

Example:

    // --- snip ---

    // divide the numbers (|denomenator| is greater than |numerator|)
    let res = number2 / number1;

    // No matter what base res is, res.display will be "0".
    // Hence res.as_decimal(), res.as_binary(), res.as_octal() etc. will all be 0.
    assert_eq!(res.display(), String::from("0"));
§

type Output = iBase

The resulting type after applying the / operator.
source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
source§

impl Mul<iBase> for iBase

iBase instances can be multiplied just like normal numbers using the ‘*’ operator. Do note however that the resulting iBase instance will be of the same base as the first factor. iBase instances of different bases can be multiplied without issue.

Example:


    // create the iBase instances
    let number1 = iBase::from_string(2, "1001011101101011");
    assert_eq!(number1.as_decimal(), 38763);

    let number2 = iBase::from_string(27, "-ABGL");
    assert_eq!(number2.as_decimal(), -205302);


    // multiply the numbers
    let res = number1 * number2;

    assert_eq!(res.as_decimal(), 38763 * -205302);
§

type Output = iBase

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl NumberBase for iBase

§

type DecimalType = i128

The type being returned when a decimal is to be returned For instance, the as_octal() function returns either an integer or float depending on whether the struct implementing NumberBase only accepts integers
source§

fn base(&self) -> u16

returns the base of the number
source§

fn digits(&self) -> &Vec<u16>

returns the vector containg the digits in base 10
source§

fn convert(&mut self, base: u16) -> Self

converts the number to the inputted number base
source§

fn from_string(base: u16, number: &str) -> Self

creates an instance of Self from a string
source§

fn from_vec(base: u16, number: Vec<u16>) -> Self

creates and instance of Self from a vector
source§

fn greater_than(&self, number: Self) -> bool

returns true if the number is greater than the input for this funciton
source§

fn as_binary(&self) -> Self::DecimalType

returns an instance of self but in binary
source§

fn as_octal(&self) -> Self::DecimalType

returns an instance of self but in octal
source§

fn as_decimal(&self) -> Self::DecimalType

returns an instance of self but in decimal
source§

fn as_hex(&self) -> String

returns an instance of self but in hex
source§

fn display(&self) -> String

returns the value of the number as a string
source§

impl Sub<iBase> for iBase

iBase instances can be subtracted just like regular nubers using the ‘-’ operator. Do note however that the resulting iBase instance will be of the same base as the first term. iBase instances of different bases can be subtracted without issue.

Do also note that the iBase struct does not support negative numbers, so subtracting a larger number from a smaller one will result in a panic!

Example:


    // create the iBase instances
    let number1 = iBase::from_string(20, "1234876");
    assert_eq!(number1.as_decimal(), 70915346);

    let number2 = iBase::from_string(15, "-3245");
    assert_eq!(number2.as_decimal(), -10640);

    // subtract the numbers
    let res = number1 - number2;

    assert_eq!(res.as_decimal(), 70915346 - -10640);
§

type Output = iBase

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for iBase

§

impl Send for iBase

§

impl Sync for iBase

§

impl Unpin for iBase

§

impl UnwindSafe for iBase

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.