pub struct Quantity<F, U> { /* private fields */ }
Expand description

Implementations

Check if the quantity has the same unit as the argument.

Example
let p = 5.0 * NEWTON/METER.powi(2);
assert!(p.has_unit(&BAR));

Return a reference to its value if the quantity is dimensionless.

Example
let p1 = 5.0 * PASCAL;
let p2 = 2.5 * PASCAL;
let ratio = p1 / p2;
assert_relative_eq!(ratio.value()?, &2.0);

Converts to its value if the quantity is dimensionless.

Example
let p1 = 5.0 * PASCAL;
let p2 = 2.5 * PASCAL;
let ratio = p1 / p2;
assert_relative_eq!(ratio.into_value()?, 2.0);

Returns the value of self in a given unit if possible.

Example
let p = 5.0 * BAR;
assert_relative_eq!(p.to_reduced(PASCAL)?, 500000.0);

Calculate the integer power of self.

Example
let x = 5.0 * METER;
assert_relative_eq!(x.powi(2), &(25.0 * METER * METER));

Try to calculate the square root of self.

Example
let x = 25.0 * METER * METER;
assert_relative_eq!(x.sqrt()?, &(5.0 * METER));
assert!(METER.sqrt().is_err());

Try to calculate the cubic root of self.

Example
let x = 125.0 * METER * METER * METER;
assert_relative_eq!(x.cbrt()?, &(5.0 * METER));
assert!(METER.cbrt().is_err());

Try to calculate the integer root of self.

Example
let x = 625.0 * METER * METER * METER * METER;
assert_relative_eq!(x.root(4)?, &(5.0 * METER));
assert!(METER.root(4).is_err());

Return the maximum of self and other if they have the same unit.

Example
let p1 = 110.0 * KILO * PASCAL;
let p2 = BAR;
assert_relative_eq!(p1.max(p2)?, &p1);
assert!(BAR.max(KELVIN).is_err());

Return the minimum of self and other if they have the same unit.

Example
let p1 = 110.0 * KILO * PASCAL;
let p2 = BAR;
assert_relative_eq!(p1.min(p2)?, &p2);
assert!(BAR.min(KELVIN).is_err());

Return the absolute value of self.

Example
let t = -50.0 * KELVIN;
assert_relative_eq!(t.abs(), &(50.0 * KELVIN));

Returns a number that represents the sign of self.

  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
  • NAN if the number is NAN

Returns true if self has a positive sign, including +0.0, NaNs with positive sign bit and positive infinity.

Returns true if self has a negative sign, including -0.0, NaNs with negative sign bit and negative infinity.

Returns true if this value is NaN.

Return the sum of all elements in the array.

Example
let x = arr1(&[1.5, 2.5]) * BAR;
assert_relative_eq!(x.sum(), &(4.0 * BAR));

Return the total number of elements in the array.

Return whether the array has any elements

Return the shape of the array as it’s stored in the array.

Return the shape of the array as a slice.

Return an uniquely owned copy of the array.

Return the element at index.

The Index trait can not be implemented, because a new instance has to be created, when indexing a quantity array. This serves as replacement for it.

Set the element at index to scalar if scalar has the same unit as self.

Returns a view restricted to index along the axis, with the axis removed.

Insert new array axis at axis and return the result.

Return sum along axis.

Return a vector of scalar quantities for each element of self.

Create an array with values created by the function f.

Calculate the integer power of self.

Example
let x = arr1(&[3.0, 5.0]) * METER;
assert_relative_eq!(x.powi(2), &(arr1(&[9.0, 25.0]) * METER * METER));

Try to calculate the square root of self.

Example
let x = arr1(&[9.0, 25.0]) * METER * METER;
assert_relative_eq!(x.sqrt()?, &(arr1(&[3.0, 5.0]) * METER));

Try to calculate the cubic root of self.

Example
let x = arr1(&[27.0, 125.0]) * METER * METER * METER;
assert_relative_eq!(x.cbrt()?, &(arr1(&[3.0, 5.0]) * METER));

Try to calculate the integer root of self.

Example
let x = arr1(&[81.0, 625.0]) * METER * METER * METER * METER;
assert_relative_eq!(x.root(4)?, &(arr1(&[3.0, 5.0]) * METER));

Create a one-dimensional array with n evenly spaced elements from start to end (inclusive) if start and end have the same unit.

Example
let x = SIArray1::linspace(1.0 * METER, 3.0 * METER, 5)?;
assert_relative_eq!(x, &(arr1(&[1.0, 1.5, 2.0, 2.5, 3.0]) * METER));

Create a one-dimensional array with n logarithmically spaced elements from start to end (inclusive) if start and end have the same unit.

Example
let x = SIArray1::logspace(1.0 * METER, 16.0 * METER, 5)?;
assert_relative_eq!(x, &(arr1(&[1.0, 2.0, 4.0, 8.0, 16.0]) * METER));

Create a one-dimensional array from a vector of scalar quantities.

Trait Implementations

Used for specifying relative comparisons.

The default tolerance to use when testing values that are close together. Read more

A test for equality that uses the absolute difference to compute the approximate equality of two numbers. Read more

The inverse of AbsDiffEq::abs_diff_eq.

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Performs the conversion.

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

The default relative tolerance for testing values that are far-apart. Read more

A test for equality that uses a relative comparison if the values are far apart.

The inverse of RelativeEq::relative_eq.

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.