{"record":{"id":"e405dd56590a56f0","repo":"apple/pkl","slug":"cannotconvertlargefloat-e405dd","errorCode":null,"errorMessage":"cannotConvertLargeFloat","messagePattern":"cannotConvertLargeFloat","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/base/FloatNodes.java","lineNumber":214,"sourceCode":"      return StrictMath.rint(self);\n    }\n  }\n\n  public abstract static class truncate extends ExternalMethod0Node {\n    @Specialization\n    protected double eval(double self) {\n      return VmSafeMath.truncate(self);\n    }\n  }\n\n  public abstract static class toInt extends ExternalMethod0Node {\n    @Specialization\n    protected long eval(double self) {\n      try {\n        return MathUtils.roundToLong(self, RoundingMode.DOWN);\n      } catch (ArithmeticException e) {\n        CompilerDirectives.transferToInterpreter();\n        throw exceptionBuilder()\n            .evalError(\n                Double.isFinite(self) ? \"cannotConvertLargeFloat\" : \"cannotConvertNonFiniteFloat\",\n                new ProgramValue(\"Float\", self))\n            .build();\n      }\n    }\n  }\n\n  public abstract static class toFloat extends ExternalMethod0Node {\n    @Specialization\n    protected double eval(double self) {\n      return self;\n    }\n  }\n\n  public abstract static class toString extends ExternalMethod0Node {\n    @Specialization\n    @TruffleBoundary","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/base/FloatNodes.java#L196-L232","documentation":"FloatNodes' round-to-long specialization (Float.prototype.round with DOWN/ truncate-style semantics) converts a double to a long via MathUtils.roundToLong, which throws ArithmeticException when the value exceeds long range. Pkl then throws `cannotConvertLargeFloat` for finite out-of-range floats (or `cannotConvertNonFiniteFloat` for NaN/Infinity), embedding the offending value as a ProgramValue.","triggerScenarios":"Calling `.round(...)`/integer truncation on a double whose magnitude exceeds Long.MAX_VALUE (~9.22e18), e.g. `1e20.round()` or `(1.0/0.0)` — thrown at FloatNodes.java:214 when MathUtils.roundToLong raises ArithmeticException and Double.isFinite(self) is true.","commonSituations":"Unbounded float math (exponentiation, products of large values) feeding into integer conversion, or computed values from user config that were assumed to stay small.","solutions":["Range-check the float (`v >= -9.22e18 && v <= 9.22e18`) before converting to Int.","Work with Int arithmetic instead of Float if the values are inherently integral.","Clamp or rescale the computation producing the huge float.","Handle non-finite values separately (check `v.isFinite()`) before rounding."],"exampleFix":"// before\ni = 1e20.round()  // cannotConvertLargeFloat\n// after\ni = if (v.isFinite() && v.abs() < 9.22e18) v.round() else throw(\"value too large\")","handlingStrategy":"validation","validationCode":"function roundableToInt(v) {\n  return v.isFinite && v >= -9223372036854775808 && v <= 9223372036854775807;\n}","typeGuard":"function isSafeInt(v) {\n  return typeof v === \"number\" && Number.isFinite(v) && Math.abs(v) < 9.22e18;\n}","tryCatchPattern":null,"preventionTips":["Range-check floats before integer conversion","Prefer Int arithmetic for integral values","Clamp upstream computations that can overflow"],"tags":["pkl","float","integer-conversion","overflow"],"backgroundTag":"value-out-of-range","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}