louthy/language-ext · error · ArgumentOutOfRangeException

Less than absolute zero

Error message

Less than absolute zero

What it means

The internal Temperature constructor validates that the constructed temperature is not below absolute zero and throws ArgumentOutOfRangeException("Less than absolute zero") with the value and unit in the message. Absolute zero (0 K, -273.15 °C, -459.67 °F) is a physical floor; LanguageExt enforces it so Temperature values remain physically meaningful. Any factory or arithmetic path that produces a sub-absolute-zero value hits this.

Solutions

  1. Validate the raw input against the unit's floor before constructing (K >= 0, C >= -273.15, F >= -459.67).
  2. Fix unit confusion: confirm whether the source value is C, F, or K and call the matching From* factory.
  3. Catch ArgumentOutOfRangeException at the boundary and surface a domain validation error to the caller.
  4. Use Temperature arithmetic (operator- returning a difference) rather than raw double subtraction to avoid invalid results.

Example fix

// before
var t = Temperature.FromKelvin(-5); // ArgumentOutOfRangeException
// after
if (kelvin < 0) throw new ArgumentException("Kelvin cannot be negative");
var t = Temperature.FromKelvin(kelvin);
Defensive patterns

Strategy: validation

Validate before calling

static bool IsValidTemp(double v, UnitType u) => u switch
{
    UnitType.K => v >= 0,
    UnitType.C => v >= -273.15,
    UnitType.F => v >= -459.67,
    _ => false
};

Type guard

static bool IsPhysicallyValid(Temperature t) => t.KValue >= 0;

Try / catch

try { var t = Temperature.FromCelcius(c); }
catch (ArgumentOutOfRangeException ex) { /* reject: below absolute zero */ }

Prevention

When it happens

Trigger: Temperature.FromCelcius(-300), FromFahrenheit(-500), FromKelvin(-1), or subtracting/offsetting temperatures so the result drops below 0 K; also constructing via internal ctor with a value below AbsoluteZero.

Common situations: Bad sensor/config inputs (negative Kelvin from a misconfigured unit); unit confusion — passing a Celsius value to a Kelvin-expecting API (e.g. -50 entered as Kelvin); arithmetic on temperatures using difference formulas incorrectly.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of louthy/language-ext@2f0e362824 (2026-09-15). Data as JSON: /api/errors/8900cc23a9249035. Report an issue: GitHub.

Appendix: source

Thrown at LanguageExt.Core/Units of Measure/Temperature.cs:29

{
    internal enum UnitType
    {
        K, C, F
    }

    readonly UnitType Type;
    readonly double Value;

    public static Temperature AbsoluteZero = default;
    public static Temperature ZeroCelsius = new (UnitType.C, 0.0);
    public static Temperature ZeroFahrenheit = new (UnitType.F, 0.0);

    internal Temperature(UnitType type, double value)
    {
        Type  = type;
        Value = value;

        if (this < AbsoluteZero) throw new ArgumentOutOfRangeException(nameof(value), $"{value} [{type}]", "Less than absolute zero");
    }
    
    public static Temperature FromCelcius(double value) =>
        new (UnitType.C, value);
    
    public static Temperature FromFahrenheit(double value) =>
        new (UnitType.F, value);
    
    public static Temperature FromKelvin(double value) =>
        new (UnitType.K, value);

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static double CtoK(double x) => x + 273.15;

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static double KtoC(double x) => x - 273.15;

    [MethodImpl(MethodImplOptions.AggressiveInlining)]

View on GitHub (pinned to 2f0e362824)