Skip to main content

number

Struct number 

Source
pub struct number;
Expand description

The type of numeric values.

The number type uses two internal representations, or subtypes: integer (64-bit) and float (double-precision). Lua converts between them automatically as needed, and math.type reveals the subtype of a value. Integer literals like 3 create integers; literals with a decimal point or exponent like 3.0 or 1e2 create floats.

print(3 / 2)    --> 1.5      (division always produces a float)
print(3 // 2)   --> 1        (floor division)
print(2^10)     --> 1024.0   (exponentiation produces a float)

Trait Implementations§

Source§

impl arithmetic for number

Source§

fn __add(&self, other: any) -> any

The addition (+) operation. Read more
Source§

fn __sub(&self, other: any) -> any

The subtraction (-) operation. Read more
Source§

fn __mul(&self, other: any) -> any

The multiplication (*) operation. Read more
Source§

fn __div(&self, other: any) -> any

The division (/) operation. Read more
Source§

fn __mod(&self, other: any) -> any

The modulo (%) operation. Read more
Source§

fn __pow(&self, other: any) -> any

The exponentiation (^) operation. Read more
Source§

fn __unm(&self) -> any

The negation (unary -) operation. Read more
Source§

fn __idiv(&self, other: any) -> any

The floor division (//) operation. Read more
Source§

impl bitwise for number

Source§

fn __band(&self, other: any) -> any

The bitwise AND (&) operation. Read more
Source§

fn __bor(&self, other: any) -> any

The bitwise OR (|) operation. Read more
Source§

fn __bxor(&self, other: any) -> any

The bitwise exclusive OR (~) operation. Read more
Source§

fn __bnot(&self) -> any

The bitwise NOT (unary ~) operation. Read more
Source§

fn __shl(&self, other: any) -> any

The bitwise left shift (<<) operation. Read more
Source§

fn __shr(&self, other: any) -> any

The bitwise right shift (>>) operation. Read more
Source§

impl comparison for number

Source§

fn __eq(&self, other: any) -> boolean

The equal (==) operation. Only invoked when the values being compared are both tables or both full userdata and they are not primitively equal. The result is always converted to a boolean. Read more
Source§

fn __lt(&self, other: any) -> boolean

The less than (<) operation. Read more
Source§

fn __le(&self, other: any) -> boolean

The less equal (<=) operation. Read more
Source§

impl tostring for number

Source§

fn __tostring(&self) -> string

Invoked by tostring() (and therefore by print) to convert the value to a string. Read more
Source§

fn __name(&self) -> string

A string naming the type of the value, used in error messages and by tostring when __tostring is absent. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.