Other functions
Error handling · Debugging · Floating point · Quantities · Chemical elements · Mixed unit conversion · Temperature conversion · Speed of sound · Color format conversion · Celestial calculations
Error handling
Defined in: core::error
error
Throw an error with the specified message. Stops the execution of the program.
Debugging
Defined in: core::debug
inspect
Print the value (and type) of the argument and return it. Useful for debugging.
Floating point
Defined in: core::numbers
is_nan
Returns true if the input is NaN.
More information here.
is_infinite
Returns true if the input is positive infinity or negative infinity. More information here.
is_finite
Returns true if the input is neither infinite nor NaN.
is_zero
Returns true if the input is 0 (zero).
is_nonzero
Returns true unless the input is 0 (zero).
is_integer
Returns true if the input is an integer.
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.
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.
base_unit_of
Extract the base unit of a quantity without prefixes (e.g., base_unit_of(5 km) returns m instead of km). This can be useful for normalizing values. Returns an error if the quantity is zero.
has_unit
Returns true if quantity has the same unit as unit_query, or if quantity evaluates to zero.
is_dimensionless
Returns true if quantity is dimensionless, or if quantity is zero.
unit_name
Returns a string representation of the unit of quantity. Returns an empty string if quantity is dimensionless.
quantity_cast
Unsafe function that returns the quantity from unmodified with the target dimension To. This can be useful in generic code, but should generally be avoided otherwise.
Chemical elements
Defined in: chemistry::elements
element (Chemical element)
Get properties of a chemical element by its symbol or name (case-insensitive).
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.
Run this exampleMixed unit conversion
Defined in: units::mixed
unit_list (Unit list)
Convert a value to a mixed representation using the provided units.
Example
Run this exampleDMS (Degrees, minutes, seconds)
Convert an angle to a mixed degrees, (arc)minutes, and (arc)seconds representation. Also called sexagesimal degree notation. More information here.
DM (Degrees, decimal minutes)
Convert an angle to a mixed degrees and decimal minutes representation. More information here.
feet_and_inches (Feet and inches)
Convert a length to a mixed feet and inches representation. More information here.
pounds_and_ounces (Pounds and ounces)
Convert a mass to a mixed pounds and ounces representation. More information here.
Temperature conversion
Defined in: physics::temperature_conversion
from_celsius
°C
Converts from Kelvin to degree Celsius (°C). Can be used on the right hand side of a conversion operator. More information here.
celsius
An alias for °C.
degree_celsius
An alias for °C.
from_fahrenheit
°F
Converts from Kelvin to degree Fahrenheit (°F). Can be used on the right hand side of a conversion operator. More information here.
fahrenheit
An alias for °F.
degree_fahrenheit
An alias for °F.
Speed of sound
Defined in: physics::speed_of_sound
speed_of_sound (Speed of sound in dry air)
Calculate the speed of sound in dry air as a function of air temperature. More information here.
Color format conversion
Defined in: extra::color
rgb
Create a Color from RGB (red, green, blue) values in the range \( [0, 256) \).
Example
Run this examplecolor
Create a Color from a (hexadecimal) value.
Example
Run this examplecolor_rgb
Convert a color to its RGB representation.
color_rgb_float
Convert a color to its RGB floating point representation.
Example
Run this examplecolor_hex
Convert a color to its hexadecimal representation.
Celestial calculations
Defined in: extra::celestial
sunrise_sunset (Sunrise and sunset)
Compute sunrise, solar noon (transit), and sunset times for a given location and date.
Example
use extra::celestial
sunrise_sunset(Position { lat: 40.713°, lon: -74.006° }, datetime("2023-03-21 12:00:00 America/New_York"))
= SunTimes { sunrise: 2023-03-21 10:57:38 UTC, transit: 2023-03-21 17:03:09 UTC, sunset: 2023-03-21 23:08:40 UTC } [SunTimes]
moon_phase (Moon phase)
Compute the moon phase for a given date and time. Returns the phase from 0 to 1 lunar_cycle, where 0 is a new moon and 0.5 lunar_cycle is a full moon.
Example
use extra::celestial
datetime("2026-01-30 12:00:00 UTC") -> moon_phase
= 0.402656 lunar_cycle [LunarCycle]
moon_phase_name (Moon phase name)
Convert a moon phase to its name and Unicode symbol (e.g., "🌘 Waning Crescent").
Example
use extra::celestial
datetime("2026-01-30 12:00:00 UTC") -> moon_phase -> moon_phase_name
= "🌔 Waxing Gibbous" [String]