Struct TemperatureUnit
Encapsulates a temperature, stored internally in degrees Celsius (°C), and provides properties that allow for conversions and interactions between Kelvin (with metric prefixes), Fahrenheit, and Rankine.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Units
Assembly: ScyllaCore.dll
Syntax
public struct TemperatureUnit : IEquatable<TemperatureUnit>
Remarks
The canonical internal representation is degrees Celsius (°C) stored as a double.
All property getters and setters convert to and from this value. Kelvin-based properties
apply the exact offset of 273.15 K during conversion. Assigning any non-finite value
(NaN or infinity) to any property or constructor parameter throws an
ArgumentOutOfRangeException via NumberUtil.EnsureFinite.
Equality comparisons (==, !=, Equals(TemperatureUnit)) use
approximate floating-point equality via NumberUtil.Approximately rather than
exact bit-for-bit comparison, avoiding false inequality from accumulated floating-point
rounding during unit conversions.
ToString() automatically selects the most human-readable unit for the stored value. For typical temperatures it uses °C. For temperatures very close to absolute zero (Kelvin magnitude below 1 K) it uses sub-Kelvin SI prefix units (mK, µK, nK, pK, fK, aK). For extreme magnitudes (|°C| >= 1000) it uses upper-range Kelvin prefix units (daK, hK, kK, MK, GK).
Arithmetic operators (+, -, *, /) operate directly on
the raw Celsius values. Note that adding or multiplying temperatures is physically
meaningful only for temperature differences (offsets), not absolute temperatures.
Constructors
TemperatureUnit(double)
Creates a new TemperatureUnit instance from a degrees Celsius (°C) value.
Declaration
public TemperatureUnit(double celsius = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| double | celsius | The temperature in degrees Celsius (°C). Must be a finite value; NaN and infinity are rejected with an ArgumentOutOfRangeException. Defaults to 0. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
Properties
Attokelvin
The temperature in attokelvin (aK), where 1 aK = 10^-18 K.
Declaration
public double Attokelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Celsius
The temperature in degrees Celsius (°C). This is the canonical internal unit; getting and setting this property directly avoids any conversion arithmetic.
Declaration
public double Celsius { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Decakelvin
The temperature in decakelvin (daK), where 1 daK = 10 K.
Declaration
public double Decakelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Fahrenheit
The temperature in degrees Fahrenheit (°F). The conversion formula is
°F = °C * (9/5) + 32, using the exact scale factors defined by
the International System of Units.
Declaration
public double Fahrenheit { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Femtokelvin
The temperature in femtokelvin (fK), where 1 fK = 10^-15 K.
Declaration
public double Femtokelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Gigakelvin
The temperature in gigakelvin (GK), where 1 GK = 10^9 K.
Declaration
public double Gigakelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Hectokelvin
The temperature in hectokelvin (hK), where 1 hK = 100 K.
Declaration
public double Hectokelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Kelvin
The temperature in Kelvin (K), the SI base unit of thermodynamic temperature. A value
of 0 K represents absolute zero (-273.15 °C). The conversion applies the exact offset
of 273.15 K: K = °C + 273.15.
Declaration
public double Kelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Kilokelvin
The temperature in kilokelvin (kK), where 1 kK = 10^3 K.
Declaration
public double Kilokelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Megakelvin
The temperature in megakelvin (MK), where 1 MK = 10^6 K.
Declaration
public double Megakelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Microkelvin
The temperature in microkelvin (µK), where 1 µK = 10^-6 K.
Declaration
public double Microkelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Millikelvin
The temperature in millikelvin (mK), where 1 mK = 10^-3 K.
Declaration
public double Millikelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Nanokelvin
The temperature in nanokelvin (nK), where 1 nK = 10^-9 K.
Declaration
public double Nanokelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Picokelvin
The temperature in picokelvin (pK), where 1 pK = 10^-12 K.
Declaration
public double Picokelvin { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Rankine
The temperature in degrees Rankine (°R), an absolute thermodynamic scale that uses the
Fahrenheit degree size. A temperature of 0 °R equals absolute zero (0 K). The conversion
formula is °R = K * (9/5).
Declaration
public double Rankine { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Methods
Equals(TemperatureUnit)
Determines whether the specified TemperatureUnit is approximately equal to
this instance by comparing internal Celsius values via NumberUtil.Approximately.
This tolerates small rounding errors that can accumulate during unit conversions.
Declaration
public bool Equals(TemperatureUnit other)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | other | The TemperatureUnit to compare with this instance. |
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(object)
Determines whether the specified object is equal to this TemperatureUnit instance. Uses approximate floating-point equality via Equals(TemperatureUnit).
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 Celsius 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 temperature 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 symbol, such as
The unit selection follows these priorities:
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 +(TemperatureUnit, TemperatureUnit)
Adds two TemperatureUnit values together by summing their internal Celsius representations. This is most meaningful for temperature differences (offsets) rather than absolute temperatures.
Declaration
public static TemperatureUnit operator +(TemperatureUnit left, TemperatureUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The first operand. |
| TemperatureUnit | right | The second operand. |
Returns
| Type | Description |
|---|---|
| TemperatureUnit | A new TemperatureUnit whose value equals |
operator /(TemperatureUnit, TemperatureUnit)
Divides one TemperatureUnit value by another, returning the dimensionless ratio of their raw Celsius values as a double-precision floating-point number.
Declaration
public static double operator /(TemperatureUnit left, TemperatureUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The dividend temperature. |
| TemperatureUnit | right | The divisor temperature. Must be non-zero. |
Returns
| Type | Description |
|---|---|
| double | The ratio of |
Exceptions
| Type | Condition |
|---|---|
| DivideByZeroException | Thrown when |
operator /(TemperatureUnit, double)
Divides a TemperatureUnit value by a double-precision floating-point scalar, reducing the raw Celsius value by the given divisor.
Declaration
public static TemperatureUnit operator /(TemperatureUnit left, double right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The temperature 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 |
|---|---|
| TemperatureUnit | A new TemperatureUnit equal to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
| DivideByZeroException | Thrown when |
operator /(TemperatureUnit, int)
Divides a TemperatureUnit value by an integer scalar, reducing the raw Celsius value by the given divisor.
Declaration
public static TemperatureUnit operator /(TemperatureUnit left, int right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The temperature to divide. |
| int | right | The integer divisor. Must be non-zero. |
Returns
| Type | Description |
|---|---|
| TemperatureUnit | A new TemperatureUnit equal to |
Exceptions
| Type | Condition |
|---|---|
| DivideByZeroException | Thrown when |
operator ==(TemperatureUnit, TemperatureUnit)
Determines whether two TemperatureUnit values are approximately equal by
comparing their internal Celsius values using NumberUtil.Approximately,
which tolerates small floating-point rounding errors from unit conversions.
Declaration
public static bool operator ==(TemperatureUnit left, TemperatureUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The first value to compare. |
| TemperatureUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator >(TemperatureUnit, TemperatureUnit)
Determines whether one TemperatureUnit value is strictly greater than another, comparing their internal Celsius representations.
Declaration
public static bool operator >(TemperatureUnit left, TemperatureUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The first value to compare. |
| TemperatureUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator >=(TemperatureUnit, TemperatureUnit)
Determines whether one TemperatureUnit value is greater than or equal to another, comparing their internal Celsius representations.
Declaration
public static bool operator >=(TemperatureUnit left, TemperatureUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The first value to compare. |
| TemperatureUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(TemperatureUnit, TemperatureUnit)
Determines whether two TemperatureUnit values are not approximately equal
by comparing their internal Celsius values using NumberUtil.Approximately.
Declaration
public static bool operator !=(TemperatureUnit left, TemperatureUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The first value to compare. |
| TemperatureUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator <(TemperatureUnit, TemperatureUnit)
Determines whether one TemperatureUnit value is strictly less than another, comparing their internal Celsius representations.
Declaration
public static bool operator <(TemperatureUnit left, TemperatureUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The first value to compare. |
| TemperatureUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator <=(TemperatureUnit, TemperatureUnit)
Determines whether one TemperatureUnit value is less than or equal to another, comparing their internal Celsius representations.
Declaration
public static bool operator <=(TemperatureUnit left, TemperatureUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The first value to compare. |
| TemperatureUnit | right | The second value to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator *(TemperatureUnit, double)
Multiplies a TemperatureUnit value by a double-precision floating-point scalar, scaling the raw Celsius value by the given factor.
Declaration
public static TemperatureUnit operator *(TemperatureUnit left, double right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The temperature to scale. |
| double | right | The scalar multiplier. Must be a finite value; NaN and infinity are rejected. |
Returns
| Type | Description |
|---|---|
| TemperatureUnit | A new TemperatureUnit equal to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
operator *(TemperatureUnit, int)
Multiplies a TemperatureUnit value by an integer scalar, scaling the raw Celsius value by the given factor.
Declaration
public static TemperatureUnit operator *(TemperatureUnit left, int right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The temperature to scale. |
| int | right | The integer scalar multiplier. |
Returns
| Type | Description |
|---|---|
| TemperatureUnit | A new TemperatureUnit equal to |
operator *(double, TemperatureUnit)
Multiplies a double-precision floating-point scalar by a TemperatureUnit value, scaling the raw Celsius value by the given factor.
Declaration
public static TemperatureUnit operator *(double left, TemperatureUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| double | left | The scalar multiplier. Must be a finite value; NaN and infinity are rejected. |
| TemperatureUnit | right | The temperature to scale. |
Returns
| Type | Description |
|---|---|
| TemperatureUnit | A new TemperatureUnit equal to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
operator *(int, TemperatureUnit)
Multiplies an integer scalar by a TemperatureUnit value, scaling the raw Celsius value by the given factor.
Declaration
public static TemperatureUnit operator *(int left, TemperatureUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| int | left | The integer scalar multiplier. |
| TemperatureUnit | right | The temperature to scale. |
Returns
| Type | Description |
|---|---|
| TemperatureUnit | A new TemperatureUnit equal to |
operator -(TemperatureUnit, TemperatureUnit)
Subtracts one TemperatureUnit value from another by subtracting their internal Celsius representations. This is most meaningful for computing temperature differences.
Declaration
public static TemperatureUnit operator -(TemperatureUnit left, TemperatureUnit right)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | left | The minuend. |
| TemperatureUnit | right | The subtrahend. |
Returns
| Type | Description |
|---|---|
| TemperatureUnit | A new TemperatureUnit whose value equals |
operator -(TemperatureUnit)
Negates a TemperatureUnit value, producing a temperature whose Celsius value is the arithmetic negation of the original.
Declaration
public static TemperatureUnit operator -(TemperatureUnit value)
Parameters
| Type | Name | Description |
|---|---|---|
| TemperatureUnit | value | The value to negate. |
Returns
| Type | Description |
|---|---|
| TemperatureUnit | A new TemperatureUnit whose internal °C value is the arithmetic negation of |