Struct SpeedUnit
Encapsulates a speed, stored internally in meters per second (m/s), and provides properties that allow for conversions and interactions between multiple metric, imperial, nautical, astronomical, and relativistic speed units.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Units
Assembly: ScyllaCore.dll
Syntax
public struct SpeedUnit : IEquatable<SpeedUnit>
Remarks
The canonical internal representation is meters per second (m/s) stored as a
double. All property getters and setters convert to and from this value.
Assigning any non-finite value (NaN or infinity) to any property or constructor
parameter throws an ArgumentOutOfRangeException via
NumberUtil.EnsureFinite.
Equality comparisons (==, !=, Equals(SpeedUnit)) use
approximate floating-point equality via NumberUtil.Approximately rather than
exact bit-for-bit comparison, which avoids false inequality due to accumulated
floating-point rounding during unit conversions.
ToString() automatically selects the most human-readable unit for the stored value, ranging from yoctometers per second (ym/s) for sub-atomic scales up through fractions of the speed of light (c) for relativistic speeds.
Relativistic constants use exact SI values: the speed of light in vacuum is exactly 299,792,458 m/s (CODATA). The Mach number uses the ISA sea-level standard atmosphere definition of 340.29 m/s and is therefore deterministic and environment-independent.
Constructors
SpeedUnit(double)
Creates a new SpeedUnit instance from a meters per second (m/s) value.
Declaration
public SpeedUnit(double metersPerSecond = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| double | metersPerSecond | The speed in meters per second (m/s). Must be a finite value; NaN and infinity are rejected with an ArgumentOutOfRangeException. Defaults to 0. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
Properties
AstronomicalUnitPerDay
The speed in astronomical units per day (AU/day), where 1 AU = 149,597,870,700 m (exact).
Declaration
public double AstronomicalUnitPerDay { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
AstronomicalUnitPerYear
The speed in astronomical units per year (AU/year), using a deterministic Julian year (365.25 days).
Declaration
public double AstronomicalUnitPerYear { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
AtomicUnitOfVelocity
The speed in atomic units of velocity (Bohr velocity), where 1 a.u. = 2.18769126364e6 m/s (CODATA 2022).
Declaration
public double AtomicUnitOfVelocity { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
AttometerPerSecond
The speed in attometers per second (am/s), where 1 am = 10^-18 m.
Declaration
public double AttometerPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
C
The speed as a fraction of the speed of light in vacuum (c), where a value of 1.0 equals exactly c (299,792,458 m/s). This is an alias for FractionOfLightSpeed, providing a concise shorthand consistent with physics notation.
Declaration
public double C { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
CentimeterPerSecond
The speed in centimeters per second (cm/s), where 1 cm = 10^-2 m.
Declaration
public double CentimeterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
DecameterPerSecond
The speed in decameters per second (dam/s), where 1 dam = 10 m.
Declaration
public double DecameterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
DecimeterPerSecond
The speed in decimeters per second (dm/s), where 1 dm = 10^-1 m.
Declaration
public double DecimeterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
ExameterPerSecond
The speed in exameters per second (Em/s), where 1 Em = 10^18 m.
Declaration
public double ExameterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
FemtometerPerSecond
The speed in femtometers per second (fm/s), where 1 fm = 10^-15 m.
Declaration
public double FemtometerPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
FootPerSecond
The speed in feet per second (ft/s), where 1 ft = 0.3048 m (exact).
Declaration
public double FootPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
FractionOfLightSpeed
The speed as a fraction of the speed of light in vacuum (c), where 1 = c.
Declaration
public double FractionOfLightSpeed { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
GigameterPerSecond
The speed in gigameters per second (Gm/s), where 1 Gm = 10^9 m.
Declaration
public double GigameterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
HectometerPerSecond
The speed in hectometers per second (hm/s), where 1 hm = 100 m.
Declaration
public double HectometerPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
KilometerPerHour
The speed in kilometers per hour (km/h).
Declaration
public double KilometerPerHour { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
KilometerPerSecond
The speed in kilometers per second (km/s).
Declaration
public double KilometerPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Knot
The speed in knots (nautical miles per hour), where 1 nmi = 1852 m (exact).
Declaration
public double Knot { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Mach
The speed in Mach, where Mach 1 is defined as the speed of sound at ISA sea-level (15°C): 340.29 m/s.
Declaration
public double Mach { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
MegameterPerSecond
The speed in megameters per second (Mm/s), where 1 Mm = 10^6 m.
Declaration
public double MegameterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
MeterPerHour
The speed in meters per hour (m/h).
Declaration
public double MeterPerHour { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
MeterPerSecond
The speed in meters per second (m/s).
Declaration
public double MeterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
MicrometerPerSecond
The speed in micrometers per second (µm/s), where 1 µm = 10^-6 m.
Declaration
public double MicrometerPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
MilePerHour
The speed in miles per hour (mph), where 1 mi = 1609.344 m (exact).
Declaration
public double MilePerHour { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
MilePerSecond
The speed in miles per second (mi/s).
Declaration
public double MilePerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
MillimeterPerSecond
The speed in millimeters per second (mm/s), where 1 mm = 10^-3 m.
Declaration
public double MillimeterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
NanometerPerSecond
The speed in nanometers per second (nm/s), where 1 nm = 10^-9 m.
Declaration
public double NanometerPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
PetameterPerSecond
The speed in petameters per second (Pm/s), where 1 Pm = 10^15 m.
Declaration
public double PetameterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
PicometerPerSecond
The speed in picometers per second (pm/s), where 1 pm = 10^-12 m.
Declaration
public double PicometerPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
SpeedOfLightInVacuum
The speed as a fraction of the speed of light in vacuum (c), where a value of 1.0 equals exactly c (299,792,458 m/s). This is an alias for FractionOfLightSpeed, providing a more descriptive name for the same quantity.
Declaration
public double SpeedOfLightInVacuum { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
TerameterPerSecond
The speed in terameters per second (Tm/s), where 1 Tm = 10^12 m.
Declaration
public double TerameterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
YoctometerPerSecond
The speed in yoctometers per second (ym/s), where 1 ym = 10^-24 m.
Declaration
public double YoctometerPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
YottameterPerSecond
The speed in yottameters per second (Ym/s), where 1 Ym = 10^24 m.
Declaration
public double YottameterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
ZeptometerPerSecond
The speed in zeptometers per second (zm/s), where 1 zm = 10^-21 m.
Declaration
public double ZeptometerPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
ZettameterPerSecond
The speed in zettameters per second (Zm/s), where 1 Zm = 10^21 m.
Declaration
public double ZettameterPerSecond { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Methods
Equals(SpeedUnit)
Determines whether the specified SpeedUnit is approximately equal to this
instance by comparing internal meters-per-second values via NumberUtil.Approximately.
This tolerates small rounding errors that can accumulate during unit conversions.
Declaration
public bool Equals(SpeedUnit other)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | other | The SpeedUnit to compare with this instance. |
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(object)
Determines whether the specified object is equal to this SpeedUnit instance. Uses approximate floating-point equality via Equals(SpeedUnit).
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with this instance. May be |
Returns
| Type | Description |
|---|---|
| bool |
|
Overrides
GetHashCode()
Returns a hash code for this instance based on the raw internal meters-per-second value.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | An integer hash code derived from the stored |
Overrides
ToString()
Returns a human-readable string representation of this speed using the most appropriate unit selected automatically based on the magnitude of the stored value.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string containing a rounded numeric value followed by a unit abbreviation, such as
The unit selection follows these priorities from highest to lowest magnitude:
Decimal places are automatically reduced for larger numbers: 2 decimals below 10, 1 decimal from 10 to 99, and 0 decimals at 100 or above. Trailing zeros and trailing decimal separators are trimmed. |
Overrides
Operators
operator +(SpeedUnit, SpeedUnit)
Adds two SpeedUnit values together by summing their internal meters-per-second representations.
Declaration
public static SpeedUnit operator +(SpeedUnit left, SpeedUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The first operand. |
| SpeedUnit | right | The second operand. |
Returns
| Type | Description |
|---|---|
| SpeedUnit | A new SpeedUnit whose value equals |
operator /(SpeedUnit, SpeedUnit)
Divides one SpeedUnit value by another, returning the dimensionless ratio of their magnitudes as a double-precision floating-point number.
Declaration
public static double operator /(SpeedUnit left, SpeedUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The dividend speed. |
| SpeedUnit | right | The divisor speed. Must be non-zero. |
Returns
| Type | Description |
|---|---|
| double | The ratio of |
Exceptions
| Type | Condition |
|---|---|
| DivideByZeroException | Thrown when |
operator /(SpeedUnit, double)
Divides a SpeedUnit value by a double-precision floating-point scalar, reducing the speed by the given divisor.
Declaration
public static SpeedUnit operator /(SpeedUnit left, double right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The speed to divide. |
| double | right | The divisor. Must be a finite, non-zero value; NaN and infinity are rejected, and zero causes a DivideByZeroException. |
Returns
| Type | Description |
|---|---|
| SpeedUnit | A new SpeedUnit equal to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
| DivideByZeroException | Thrown when |
operator /(SpeedUnit, int)
Divides a SpeedUnit value by an integer scalar, reducing the speed by the given divisor.
Declaration
public static SpeedUnit operator /(SpeedUnit left, int right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The speed to divide. |
| int | right | The integer divisor. Must be non-zero. |
Returns
| Type | Description |
|---|---|
| SpeedUnit | A new SpeedUnit equal to |
Exceptions
| Type | Condition |
|---|---|
| DivideByZeroException | Thrown when |
operator ==(SpeedUnit, SpeedUnit)
Determines whether two SpeedUnit values are approximately equal by
comparing their internal meters-per-second values using NumberUtil.Approximately,
which tolerates small floating-point rounding errors from unit conversions.
Declaration
public static bool operator ==(SpeedUnit left, SpeedUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The first value to compare. |
| SpeedUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator >(SpeedUnit, SpeedUnit)
Determines whether one SpeedUnit value is strictly greater than another, comparing their internal meters-per-second representations.
Declaration
public static bool operator >(SpeedUnit left, SpeedUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The first value to compare. |
| SpeedUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator >=(SpeedUnit, SpeedUnit)
Determines whether one SpeedUnit value is greater than or equal to another, comparing their internal meters-per-second representations.
Declaration
public static bool operator >=(SpeedUnit left, SpeedUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The first value to compare. |
| SpeedUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(SpeedUnit, SpeedUnit)
Determines whether two SpeedUnit values are not approximately equal by
comparing their internal meters-per-second values using NumberUtil.Approximately.
Declaration
public static bool operator !=(SpeedUnit left, SpeedUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The first value to compare. |
| SpeedUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator <(SpeedUnit, SpeedUnit)
Determines whether one SpeedUnit value is strictly less than another, comparing their internal meters-per-second representations.
Declaration
public static bool operator <(SpeedUnit left, SpeedUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The first value to compare. |
| SpeedUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator <=(SpeedUnit, SpeedUnit)
Determines whether one SpeedUnit value is less than or equal to another, comparing their internal meters-per-second representations.
Declaration
public static bool operator <=(SpeedUnit left, SpeedUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The first value to compare. |
| SpeedUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator *(SpeedUnit, double)
Multiplies a SpeedUnit value by a double-precision floating-point scalar, scaling the speed by the given factor.
Declaration
public static SpeedUnit operator *(SpeedUnit left, double right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The speed to scale. |
| double | right | The scalar multiplier. Must be a finite value; NaN and infinity are rejected. |
Returns
| Type | Description |
|---|---|
| SpeedUnit | A new SpeedUnit equal to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
operator *(SpeedUnit, int)
Multiplies a SpeedUnit value by an integer scalar, scaling the speed by the given factor.
Declaration
public static SpeedUnit operator *(SpeedUnit left, int right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The speed to scale. |
| int | right | The integer scalar multiplier. |
Returns
| Type | Description |
|---|---|
| SpeedUnit | A new SpeedUnit equal to |
operator *(double, SpeedUnit)
Multiplies a double-precision floating-point scalar by a SpeedUnit value, scaling the speed by the given factor.
Declaration
public static SpeedUnit operator *(double left, SpeedUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| double | left | The scalar multiplier. Must be a finite value; NaN and infinity are rejected. |
| SpeedUnit | right | The speed to scale. |
Returns
| Type | Description |
|---|---|
| SpeedUnit | A new SpeedUnit equal to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
operator *(int, SpeedUnit)
Multiplies an integer scalar by a SpeedUnit value, scaling the speed by the given factor.
Declaration
public static SpeedUnit operator *(int left, SpeedUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| int | left | The integer scalar multiplier. |
| SpeedUnit | right | The speed to scale. |
Returns
| Type | Description |
|---|---|
| SpeedUnit | A new SpeedUnit equal to |
operator -(SpeedUnit, SpeedUnit)
Subtracts one SpeedUnit value from another by subtracting their internal meters-per-second representations.
Declaration
public static SpeedUnit operator -(SpeedUnit left, SpeedUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | left | The minuend. |
| SpeedUnit | right | The subtrahend. |
Returns
| Type | Description |
|---|---|
| SpeedUnit | A new SpeedUnit whose value equals |
operator -(SpeedUnit)
Negates a SpeedUnit value, producing a speed of the same magnitude in the opposite direction.
Declaration
public static SpeedUnit operator -(SpeedUnit value)
Parameters
| Type | Name | Description |
|---|---|---|
| SpeedUnit | value | The value to negate. |
Returns
| Type | Description |
|---|---|
| SpeedUnit | A new SpeedUnit whose internal m/s value is the arithmetic negation of |