{"record":{"id":"4500b5489bef109b","repo":"TheAlgorithms/JavaScript","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":"Error","httpStatus":null,"severity":"error","filePath":"Conversions/RgbHsvConversion.js","lineNumber":29,"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 */\nexport function hsvToRgb(hue, saturation, value) {\n  if (hue < 0 || hue > 360) {\n    throw new Error('hue should be between 0 and 360')\n  }\n\n  if (saturation < 0 || saturation > 1) {\n    throw new Error('saturation should be between 0 and 1')\n  }\n\n  if (value < 0 || value > 1) {\n    throw new Error('value should be between 0 and 1')\n  }\n\n  const chroma = value * saturation\n  const hueSection = hue / 60\n  const secondLargestComponent = chroma * (1 - Math.abs((hueSection % 2) - 1))\n  const 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":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Conversions/RgbHsvConversion.js#L11-L47","documentation":"Thrown by hsvToRgb when value (brightness) is below 0 or above 1. It is the third and last range guard, reached only after hue and saturation pass. Like saturation, value is a fraction in [0,1], not a percentage.","triggerScenarios":"Calling hsvToRgb(180, 0.5, 1.2), hsvToRgb(180, 0.5, -0.1), or hsvToRgb(180, 0.5, 80) where 80 is a percentage passed as a fraction.","commonSituations":"Brightness as a percentage (0-100) from a UI control; values above 1 from gamma/blend math; negative values from a subtractive adjustment.","solutions":["Convert percentages to fractions: value / 100.","Clamp: Math.max(0, Math.min(1, value)).","Validate Number.isFinite(value) && value >= 0 && value <= 1 before calling."],"exampleFix":"// before\nhsvToRgb(180, 0.5, 120)\n// after\nhsvToRgb(180, 0.5, Math.min(1, 120 / 100))","handlingStrategy":"validation","validationCode":"if (!Number.isFinite(value) || value < 0 || value > 1) {\n  throw new Error('value must be a fraction in [0,1]')\n}\nhsvToRgb(hue, saturation, value)","typeGuard":"const isValidFraction = (x) => Number.isFinite(x) && x >= 0 && x <= 1","tryCatchPattern":"try {\n  hsvToRgb(hue, saturation, value)\n} catch (e) {\n  if (/value should be between/.test(e.message)) {\n    return hsvToRgb(hue, saturation, Math.max(0, Math.min(1, value)))\n  }\n  throw e\n}","preventionTips":["Treat brightness as a fraction (0-1), not a percentage.","Clamp value into [0,1] before calling.","Validate all three HSV components together at the boundary."],"tags":["validation","hsv","rgb","color","range-check","conversions"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}