{"record":{"id":"48e7a35d31c64021","repo":"TheAlgorithms/Java","slug":"value-should-be-between-0-and-1","errorCode":null,"errorMessage":"value should be between 0 and 1","messagePattern":"value should be between 0 and 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/conversions/RgbHsvConversion.java","lineNumber":68,"sourceCode":"    /**\n     * Conversion from the HSV-representation to the RGB-representation.\n     *\n     * @param hue Hue of the color.\n     * @param saturation Saturation of the color.\n     * @param value Brightness-value of the color.\n     * @return The tuple of RGB-components.\n     */\n    public static int[] hsvToRgb(double hue, double saturation, double value) {\n        if (hue < 0 || hue > 360) {\n            throw new IllegalArgumentException(\"hue should be between 0 and 360\");\n        }\n\n        if (saturation < 0 || saturation > 1) {\n            throw new IllegalArgumentException(\"saturation should be between 0 and 1\");\n        }\n\n        if (value < 0 || value > 1) {\n            throw new IllegalArgumentException(\"value should be between 0 and 1\");\n        }\n\n        double chroma = value * saturation;\n        double hueSection = hue / 60;\n        double secondLargestComponent = chroma * (1 - Math.abs(hueSection % 2 - 1));\n        double matchValue = value - chroma;\n\n        return getRgbBySection(hueSection, chroma, matchValue, secondLargestComponent);\n    }\n\n    /**\n     * Conversion from the RGB-representation to the HSV-representation.\n     *\n     * @param red Red-component of the color.\n     * @param green Green-component of the color.\n     * @param blue Blue-component of the color.\n     * @return The tuple of HSV-components.\n     */","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/conversions/RgbHsvConversion.java#L50-L86","documentation":"Thrown by RgbHsvConversion.hsvToRgb when the value (brightness) parameter is less than 0 or greater than 1. Value represents brightness as a ratio (0% = black, 100% = full brightness); values outside [0, 1] are invalid for the chroma and match-value calculations.","triggerScenarios":"Passing value as a percentage (0–100) instead of a ratio (0.0–1.0). Supplying a negative value from an incorrect computation. Using a raw byte value (0–255) without normalizing to the 0–1 range.","commonSituations":"Confusing percentage and fraction scales. Integrating with libraries that use 0–255 for brightness. User input where value/brightness is entered as an integer.","solutions":["If your input is a percentage 0–100, divide by 100.0 before calling hsvToRgb.","Clamp value to [0, 1] using Math.max(0.0, Math.min(1.0, value)).","Add a unit comment at the call site clarifying the expected 0–1 range."],"exampleFix":"// before\nint[] rgb = RgbHsvConversion.hsvToRgb(hue, sat, value); // value is 0-100\n\n// after\ndouble val = value / 100.0;\nval = Math.max(0.0, Math.min(1.0, val));\nint[] rgb = RgbHsvConversion.hsvToRgb(hue, sat, val);","handlingStrategy":"validation","validationCode":"value = Math.max(0.0, Math.min(1.0, value));\nint[] rgb = RgbHsvConversion.hsvToRgb(hue, saturation, value);","typeGuard":"static boolean isValidValue(double v) {\n    return v >= 0.0 && v <= 1.0;\n}","tryCatchPattern":"try {\n    int[] rgb = RgbHsvConversion.hsvToRgb(hue, saturation, value);\n} catch (IllegalArgumentException e) {\n    // value out of range; clamp and retry\n    value = Math.max(0.0, Math.min(1.0, value));\n    int[] rgb = RgbHsvConversion.hsvToRgb(hue, saturation, value);\n}","preventionTips":["If the source uses percentages (0–100), divide by 100.0 before calling.","Clamp value/brightness to [0, 1] defensively when the scale is uncertain.","Document the 0–1 fraction range expectation alongside the call."],"tags":["color-conversion","input-validation","hsv","range-check"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}