{"record":{"id":"93914b5489bd85b1","repo":"apple/pkl","slug":"floattoolarge","errorCode":"floatTooLarge","errorMessage":"floatTooLarge","messagePattern":"floatTooLarge","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":730,"sourceCode":"    }\n  }\n\n  @Override\n  public FloatLiteralNode visitFloatLiteralExpr(FloatLiteralExpr expr) {\n    var section = createSourceSection(expr);\n    var text = VmUtils.removeUnderscoresFromNumber(expr.getNumber(), true);\n    // relies on grammar rule nesting depth, but a breakage won't go unnoticed by tests\n    if (expr.parent() instanceof UnaryMinusExpr) {\n      // handle negation here for consistency with visitIntegerLiteral\n      // also moves negation from runtime to parse time\n      text = \"-\" + text;\n    }\n\n    try {\n      var num = Double.parseDouble(text);\n      return new FloatLiteralNode(section, num);\n    } catch (NumberFormatException e) {\n      throw exceptionBuilder().evalError(\"floatTooLarge\", text).withSourceSection(section).build();\n    }\n  }\n\n  @Override\n  public ExpressionNode visitThrowExpr(ThrowExpr expr) {\n    return ThrowNodeGen.create(createSourceSection(expr), visitExpr(expr.getExpr()));\n  }\n\n  @Override\n  public TraceNode visitTraceExpr(TraceExpr expr) {\n    return new TraceNode(createSourceSection(expr), visitExpr(expr.getExpr()));\n  }\n\n  @Override\n  public AbstractImportNode visitImportExpr(ImportExpr expr) {\n    var importUriCtx = expr.getImportStr();\n    return doVisitImport(expr.isGlob(), expr, importUriCtx);\n  }","sourceCodeStart":712,"sourceCodeEnd":748,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L712-L748","documentation":"Pkl Float literals are 64-bit IEEE doubles. If `Double.parseDouble` throws NumberFormatException — typically because the literal's magnitude exceeds the double range (~1.8e308) — the builder throws floatTooLarge instead of producing an infinity.","triggerScenarios":"Writing a Float literal like `1e400` (or `1.0e309`) that overflows the double range in `visitFloatLiteralExpr`.","commonSituations":"Hand-writing extreme values from scientific notation, or copying constants from arbitrary-precision contexts.","solutions":["Use a value within ±1.797e308, or clamp the constant.","Compute the value downstream rather than hard-coding an overflow-level literal.","Represent it as a String property if the exact number must be preserved."],"exampleFix":"// before\nratio = 1e400\n// after\nratio = 1.7976931348623157e308","handlingStrategy":"validation","validationCode":"// Validate magnitude before writing a Float literal:\nfunction withinDoubleRange(x) {\n  return Number.isFinite(x) && Math.abs(x) <= Number.MAX_VALUE;\n}","typeGuard":"const isPklFloat = (v: number): boolean =>\n  Number.isFinite(v) && Math.abs(v) <= 1.7976931348623157e308;","tryCatchPattern":null,"preventionTips":["Clamp or re-derive extreme computed constants instead of hard-coding values like 1e400.","Remember Pkl Floats are IEEE doubles — no arbitrary precision."],"tags":["pkl","float","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-14T16:17:12.679Z"}