{"record":{"id":"8900cc23a9249035","repo":"louthy/language-ext","slug":"less-than-absolute-zero","errorCode":null,"errorMessage":"Less than absolute zero","messagePattern":"Less than absolute zero","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Units of Measure/Temperature.cs","lineNumber":29,"sourceCode":"{\n    internal enum UnitType\n    {\n        K, C, F\n    }\n\n    readonly UnitType Type;\n    readonly double Value;\n\n    public static Temperature AbsoluteZero = default;\n    public static Temperature ZeroCelsius = new (UnitType.C, 0.0);\n    public static Temperature ZeroFahrenheit = new (UnitType.F, 0.0);\n\n    internal Temperature(UnitType type, double value)\n    {\n        Type  = type;\n        Value = value;\n\n        if (this < AbsoluteZero) throw new ArgumentOutOfRangeException(nameof(value), $\"{value} [{type}]\", \"Less than absolute zero\");\n    }\n    \n    public static Temperature FromCelcius(double value) =>\n        new (UnitType.C, value);\n    \n    public static Temperature FromFahrenheit(double value) =>\n        new (UnitType.F, value);\n    \n    public static Temperature FromKelvin(double value) =>\n        new (UnitType.K, value);\n\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    static double CtoK(double x) => x + 273.15;\n\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    static double KtoC(double x) => x - 273.15;\n\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Units of Measure/Temperature.cs#L11-L47","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Validate the raw input against the unit's floor before constructing (K >= 0, C >= -273.15, F >= -459.67).","Fix unit confusion: confirm whether the source value is C, F, or K and call the matching From* factory.","Catch ArgumentOutOfRangeException at the boundary and surface a domain validation error to the caller.","Use Temperature arithmetic (operator- returning a difference) rather than raw double subtraction to avoid invalid results."],"exampleFix":"// before\nvar t = Temperature.FromKelvin(-5); // ArgumentOutOfRangeException\n// after\nif (kelvin < 0) throw new ArgumentException(\"Kelvin cannot be negative\");\nvar t = Temperature.FromKelvin(kelvin);","handlingStrategy":"validation","validationCode":"static bool IsValidTemp(double v, UnitType u) => u switch\n{\n    UnitType.K => v >= 0,\n    UnitType.C => v >= -273.15,\n    UnitType.F => v >= -459.67,\n    _ => false\n};","typeGuard":"static bool IsPhysicallyValid(Temperature t) => t.KValue >= 0;","tryCatchPattern":"try { var t = Temperature.FromCelcius(c); }\ncatch (ArgumentOutOfRangeException ex) { /* reject: below absolute zero */ }","preventionTips":["Clamp/validate inputs against unit-specific floors before constructing","Watch for unit confusion between C, F, and K at API boundaries","Use Temperature operators for arithmetic instead of raw doubles"],"tags":["argument-out-of-range","units-of-measure","temperature","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"2f0e3628242889774d4141960a35671a0280051f","analyzedAt":"2026-09-15T03:31:55.716Z","contentChangedAt":"2026-09-15T03:31:55.716Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}