{"record":{"id":"01ac52a6a14d4b3d","repo":"karatelabs/karate","slug":"value-must-be-1","errorCode":null,"errorMessage":"value must be >= 1","messagePattern":"value must be >= 1","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsMath.java","lineNumber":67,"sourceCode":"    private static final byte METHOD_ATTRS = WRITABLE | CONFIGURABLE | PropertySlot.INTRINSIC;\n\n    JsMath() {\n        // Constants — ES §21.3.1.\n        defineOwn(\"E\", Math.E, CONSTANT_ATTRS);\n        defineOwn(\"LN10\", Math.log(10), CONSTANT_ATTRS);\n        defineOwn(\"LN2\", Math.log(2), CONSTANT_ATTRS);\n        defineOwn(\"LOG2E\", 1 / Math.log(2), CONSTANT_ATTRS);\n        defineOwn(\"LOG10E\", 1 / Math.log(10), CONSTANT_ATTRS);\n        defineOwn(\"PI\", Math.PI, CONSTANT_ATTRS);\n        defineOwn(\"SQRT1_2\", Math.sqrt(0.5), CONSTANT_ATTRS);\n        defineOwn(\"SQRT2\", Math.sqrt(2), CONSTANT_ATTRS);\n\n        // Methods — ES §21.3.2.\n        installMethod(\"abs\", 1, math(Math::abs));\n        installMethod(\"acos\", 1, math(Math::acos));\n        installMethod(\"acosh\", 1, math(x -> {\n            if (x < 1) {\n                throw JsErrorException.rangeError(\"value must be >= 1\");\n            }\n            return Math.log(x + Math.sqrt(x * x - 1));\n        }));\n        installMethod(\"asin\", 1, math(Math::asin));\n        installMethod(\"asinh\", 1, math(x -> {\n            // Spec §21.3.2.5: ±0 / ±Inf / NaN return the argument unchanged.\n            // The naive `log(x + sqrt(x*x + 1))` form yields NaN for -Inf\n            // (Inf + (-Inf)) and loses the sign of zero.\n            if (Double.isNaN(x) || x == 0 || Double.isInfinite(x)) return x;\n            return Math.log(x + Math.sqrt(x * x + 1));\n        }));\n        installMethod(\"atan\", 1, math(Math::atan));\n        installMethod(\"atan2\", 2, math(Math::atan2));\n        installMethod(\"atanh\", 1, math(x -> {\n            // Spec §21.3.2.7: ±1 → ±Infinity; |x| > 1 → NaN; ±0 preserved.\n            if (Double.isNaN(x)) return Double.NaN;\n            if (x > 1 || x < -1) return Double.NaN;\n            if (x == 1) return Double.POSITIVE_INFINITY;","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsMath.java#L49-L85","documentation":"Range validation in a JsMath method that requires a lower bound of 1 for its numeric argument (input too small would be mathematically invalid or out of domain). Fires when the argument is below 1; pass a value >= 1.","triggerScenarios":"`Math.acosh(0)`, `Math.acosh(0.5)`, `Math.acosh(-3)`; arguments computed from other expressions that dip below 1; NaN-producing input pipelines feeding acosh with sub-1 values.","commonSituations":"Inverse-hyperbolic math on physical quantities that can be 0 or negative (distances, temperatures as deltas); interpolation/normalization code producing values in (0,1); unit conversion mistakes.","solutions":["Clamp the input: `Math.acosh(Math.max(1, x))`","Guard the call: `x >= 1 ? Math.acosh(x) : NaN` (matching the IEEE NaN result)","Re-examine the formula — if values below 1 are expected, you likely want Math.log(x + Math.sqrt(x*x + 1)) i.e. Math.asinh, or Math.acosh(1 + x)","Fix upstream calculations that should produce values >= 1"],"exampleFix":"// before\nconst r = Math.acosh(x); // RangeError when x < 1\n// after\nconst r = x >= 1 ? Math.acosh(x) : NaN; // IEEE-consistent fallback","handlingStrategy":"validation","validationCode":"if (!(x >= 1)) { throw new Error('Math.acosh requires x >= 1, got ' + x); }","typeGuard":"function acoshSafe(x) { return (typeof x === 'number' && x >= 1) ? Math.acosh(x) : NaN; }","tryCatchPattern":"try {\n  r = Math.acosh(x);\n} catch (e) {\n  if (String(e.message).includes('value must be >= 1')) {\n    r = NaN; // IEEE NaN semantics\n  } else throw e;\n}","preventionTips":["Clamp inputs: Math.max(1, x)","Confirm you didn't mean Math.asinh for sub-1 inputs","Range-check computed inputs before inverse-hyperbolic calls"],"tags":["javascript","math","rangeerror","acosh"],"backgroundTag":"value-out-of-range","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}