{"record":{"id":"9fb7e07470d0a5a2","repo":"TheAlgorithms/C-Sharp","slug":"nameof-saturation-should-be-between-0-and-1","errorCode":null,"errorMessage":"{nameof(saturation)} should be between 0 and 1","messagePattern":"(.+?) should be between 0 and 1","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Algorithms/Other/RGBHSVConversion.cs","lineNumber":35,"sourceCode":"    ///     Conversion from the HSV-representation to the RGB-representation.\n    /// </summary>\n    /// <param name=\"hue\">Hue of the color.</param>\n    /// <param name=\"saturation\">Saturation of the color.</param>\n    /// <param name=\"value\">Brightness-value of the color.</param>\n    /// <returns>The tuple of RGB-components.</returns>\n    public static (byte Red, byte Green, byte Blue) HsvToRgb(\n        double hue,\n        double saturation,\n        double value)\n    {\n        if (hue < 0 || hue > 360)\n        {\n            throw new ArgumentOutOfRangeException(nameof(hue), $\"{nameof(hue)} should be between 0 and 360\");\n        }\n\n        if (saturation < 0 || saturation > 1)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(saturation),\n                $\"{nameof(saturation)} should be between 0 and 1\");\n        }\n\n        if (value < 0 || value > 1)\n        {\n            throw new ArgumentOutOfRangeException(nameof(value), $\"{nameof(value)} should be between 0 and 1\");\n        }\n\n        var chroma = value * saturation;\n        var hueSection = hue / 60;\n        var secondLargestComponent = chroma * (1 - Math.Abs(hueSection % 2 - 1));\n        var matchValue = value - chroma;\n\n        return GetRgbBySection(hueSection, chroma, matchValue, secondLargestComponent);\n    }\n\n    /// <summary>","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Other/RGBHSVConversion.cs#L17-L53","documentation":"This ArgumentOutOfRangeException is a range guard at the top of HsvToRgb (RGBHSVConversion.cs:35): the caller supplied a saturation outside the mathematically meaningful [0, 1] interval. The conversion multiplies value by saturation to derive chroma, so out-of-range saturation would produce invalid RGB components. It fires whenever HsvToRgb is called with hue in range but saturation < 0 or > 1.","triggerScenarios":"Thrown at Algorithms/Other/RGBHSVConversion.cs:35 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Clamp the saturation into [0, 1] before calling HsvToRgb, e.g. Math.Clamp(saturation, 0, 1).","Fix the upstream computation that produced saturation so it yields a normalized 0-1 value instead of a percentage (0-100) or raw 0-255 scale."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}