Other functions

Error handling · Floating point · Quantities · Chemical elements · Mixed unit conversion · Temperature conversion · Color format conversion

Error handling

Defined in: core::error

error

Throw an error with the specified message. Stops the execution of the program.

fn error<T>(message: String) -> T

Floating point

Defined in: core::numbers

is_nan

Returns true if the input is NaN. More information here.

fn is_nan<T: Dim>(n: T) -> Bool
Examples
is_nan(37) = false [Bool]
is_nan(NaN) = true [Bool]

is_infinite

Returns true if the input is positive infinity or negative infinity. More information here.

fn is_infinite<T: Dim>(n: T) -> Bool
Examples
is_infinite(37) = false [Bool]
is_infinite(-inf) = true [Bool]

is_finite

Returns true if the input is neither infinite nor NaN.

fn is_finite<T: Dim>(n: T) -> Bool
Examples
is_finite(37) = true [Bool]
is_finite(-inf) = false [Bool]

is_zero

Returns true if the input is 0 (zero).

fn is_zero<D: Dim>(value: D) -> Bool
Examples
is_zero(37) = false [Bool]
is_zero(0) = true [Bool]

is_nonzero

Returns true unless the input is 0 (zero).

fn is_nonzero<D: Dim>(value: D) -> Bool
Examples
is_nonzero(37) = true [Bool]
is_nonzero(0) = false [Bool]

Quantities

Defined in: core::quantities

value_of

Extract the plain value of a quantity (the 20 in 20 km/h). This can be useful in generic code, but should generally be avoided otherwise.

fn value_of<T: Dim>(x: T) -> Scalar
Examples
value_of(20 km/h) = 20

unit_of

Extract the unit of a quantity (the km/h in 20 km/h). This can be useful in generic code, but should generally be avoided otherwise. Returns an error if the quantity is zero.

fn unit_of<T: Dim>(x: T) -> T
Examples
unit_of(20 km/h) = 1 km/h [Velocity]

Chemical elements

Defined in: chemistry::elements

element (Chemical element)

Get properties of a chemical element by its symbol or name (case-insensitive).

fn element(pattern: String) -> ChemicalElement
Examples

Get the entire element struct for hydrogen.

element("H") = ChemicalElement { symbol: "H", name: "Hydrogen", atomic_number: 1, group: 1, group_name: "Alkali metals", period: 1, melting_point: 13.99 K, boiling_point: 20.271 K, density: 0.00008988 g/cm³, electron_affinity: 0.754 eV, ionization_energy: 13.598 eV, vaporization_heat: 0.904 kJ/mol } [ChemicalElement]

Get the ionization energy of hydrogen.

element("hydrogen").ionization_energy = 13.598 eV [Energy or Torque]

Mixed unit conversion

Defined in: units::mixed

unit_list (Unit list)

Convert a value to a mixed representation using the provided units.

fn unit_list<D: Dim>(units: List<D>, value: D) -> List<D>
Examples
5500 m |> unit_list([miles, yards, feet, inches]) = [3 mi, 734 yd, 2 ft, 7.43307 in] [List]

DMS (Degrees, minutes, seconds)

Convert an angle to a mixed degrees, (arc)minutes, and (arc)seconds representation. Also called sexagesimal degree notation. More information here.

fn DMS(alpha: Angle) -> List<Angle>
Examples
46.5858° -> DMS = [46°, 35′, 8.88″] [List]

DM (Degrees, decimal minutes)

Convert an angle to a mixed degrees and decimal minutes representation. More information here.

fn DM(alpha: Angle) -> List<Angle>
Examples
46.5858° -> DM = [46°, 35.148′] [List]

feet_and_inches (Feet and inches)

Convert a length to a mixed feet and inches representation. More information here.

fn feet_and_inches(length: Length) -> List<Length>
Examples
180 cm -> feet_and_inches = [5 ft, 10.8661 in] [List]

pounds_and_ounces (Pounds and ounces)

Convert a mass to a mixed pounds and ounces representation. More information here.

fn pounds_and_ounces(mass: Mass) -> List<Mass>
Examples
1 kg -> pounds_and_ounces = [2 lb, 3.27396 oz] [List]

Temperature conversion

Defined in: physics::temperature_conversion

from_celsius

Converts from degree Celsius (°C) to Kelvin. More information here.

fn from_celsius(t_celsius: Scalar) -> Temperature
Examples

300 °C in Kelvin.

from_celsius(300) = 573.15 K [Temperature]

celsius

Converts from Kelvin to degree Celcius (°C). This can be used on the right hand side of a conversion operator: 200 K -> celsius. More information here.

fn celsius(t_kelvin: Temperature) -> Scalar
Examples

300 K in degree Celsius.

300K -> celsius = 26.85

from_fahrenheit

Converts from degree Fahrenheit (°F) to Kelvin. More information here.

fn from_fahrenheit(t_fahrenheit: Scalar) -> Temperature
Examples

300 °F in Kelvin.

from_fahrenheit(300) = 422.039 K [Temperature]

fahrenheit

Converts from Kelvin to degree Fahrenheit (°F). This can be used on the right hand side of a conversion operator: 200 K -> fahrenheit. More information here.

fn fahrenheit(t_kelvin: Temperature) -> Scalar
Examples

300 K in degree Fahrenheit.

300K -> fahrenheit = 80.33

Color format conversion

Defined in: extra::color

rgb

Create a Color from RGB (red, green, blue) values in the range \( [0, 256) \).

fn rgb(red: Scalar, green: Scalar, blue: Scalar) -> Color
Examples
use extra::color rgb(125, 128, 218) = Color { red: 125, green: 128, blue: 218 } [Color]

color

Create a Color from a (hexadecimal) value.

fn color(rgb_hex: Scalar) -> Color
Examples
use extra::color color(0xff7700) = Color { red: 255, green: 119, blue: 0 } [Color]

color_rgb

Convert a color to its RGB representation.

fn color_rgb(color: Color) -> String
Examples
use extra::color cyan -> color_rgb = "rgb(0, 255, 255)" [String]

color_rgb_float

Convert a color to its RGB floating point representation.

fn color_rgb_float(color: Color) -> String
Examples
use extra::color cyan -> color_rgb_float = "rgb(0.000, 1.000, 1.000)" [String]

color_hex

Convert a color to its hexadecimal representation.

fn color_hex(color: Color) -> String
Examples
use extra::color rgb(225, 36, 143) -> color_hex = "#e1248f" [String]