apple/pkl · error · VmException
floatTooLarge
floatTooLarge
Error message
floatTooLarge
What it means
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.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java:730
}
}
@Override
public FloatLiteralNode visitFloatLiteralExpr(FloatLiteralExpr expr) {
var section = createSourceSection(expr);
var text = VmUtils.removeUnderscoresFromNumber(expr.getNumber(), true);
// relies on grammar rule nesting depth, but a breakage won't go unnoticed by tests
if (expr.parent() instanceof UnaryMinusExpr) {
// handle negation here for consistency with visitIntegerLiteral
// also moves negation from runtime to parse time
text = "-" + text;
}
try {
var num = Double.parseDouble(text);
return new FloatLiteralNode(section, num);
} catch (NumberFormatException e) {
throw exceptionBuilder().evalError("floatTooLarge", text).withSourceSection(section).build();
}
}
@Override
public ExpressionNode visitThrowExpr(ThrowExpr expr) {
return ThrowNodeGen.create(createSourceSection(expr), visitExpr(expr.getExpr()));
}
@Override
public TraceNode visitTraceExpr(TraceExpr expr) {
return new TraceNode(createSourceSection(expr), visitExpr(expr.getExpr()));
}
@Override
public AbstractImportNode visitImportExpr(ImportExpr expr) {
var importUriCtx = expr.getImportStr();
return doVisitImport(expr.isGlob(), expr, importUriCtx);
}View on GitHub (pinned to f3efcbfc9b)
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.
Example fix
// before ratio = 1e400 // after ratio = 1.7976931348623157e308
Defensive patterns
Strategy: validation
Validate before calling
// Validate magnitude before writing a Float literal:
function withinDoubleRange(x) {
return Number.isFinite(x) && Math.abs(x) <= Number.MAX_VALUE;
} Type guard
const isPklFloat = (v: number): boolean => Number.isFinite(v) && Math.abs(v) <= 1.7976931348623157e308;
Prevention
- Clamp or re-derive extreme computed constants instead of hard-coding values like 1e400.
- Remember Pkl Floats are IEEE doubles — no arbitrary precision.
When it happens
Trigger: Writing a Float literal like `1e400` (or `1.0e309`) that overflows the double range in `visitFloatLiteralExpr`.
Common situations: Hand-writing extreme values from scientific notation, or copying constants from arbitrary-precision contexts.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- cannotConvertLargeFloat
- `%s` is too large to fit into a Version.
- cannotConvertLargeFloat|cannotConvertNonFiniteFloat (conditi
- cannotRenderValue
- intTooLarge
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/93914b5489bd85b1.
Report an issue: GitHub.