stanfordnlp/CoreNLP · error · IllegalArgumentException
Cannot handle weird double: " + d
Error message
Cannot handle weird double: " + d
What it means
SloppyMath.segmentDouble() decomposes a double into a mantissa/exponent pair, which is only meaningful for finite numbers. The library throws IllegalArgumentException when the input is infinite or NaN because such values have no finite mantissa/exponent representation.
Solutions
- Check the value with Double.isFinite(d) before calling segmentDouble and handle non-finite input separately
- Trace where the NaN/Infinity originated (usually a division by zero or overflow earlier in the pipeline) and fix the upstream computation
- If non-finite values are expected, clamp or sanitize them before segmenting
Example fix
// before
Triple<Boolean, Long, Integer> t = SloppyMath.segmentDouble(score);
// after
if (!Double.isFinite(score)) {
score = 0.0; // or handle/log the bad value
}
Triple<Boolean, Long, Integer> t = SloppyMath.segmentDouble(score); Defensive patterns
Strategy: validation
Validate before calling
if (!Double.isFinite(d)) { throw new IllegalArgumentException("Expected finite double, got: " + d); } Type guard
boolean isUsableDouble(Object v) { return v instanceof Double && Double.isFinite((Double) v); } Try / catch
try { segmentDouble(d); } catch (IllegalArgumentException e) { /* sanitize d and retry or skip */ } Prevention
- Guard all externally-sourced doubles with Double.isFinite before math helpers
- Enable NaN checks in upstream numeric pipelines
- Unit-test edge inputs (NaN, +/-Infinity, 0.0)
When it happens
Trigger: Calling SloppyMath.segmentDouble(Double.NaN), segmentDouble(Double.POSITIVE_INFINITY), or segmentDouble(Double.NEGATIVE_INFINITY). Also triggered indirectly when an upstream computation overflows to Infinity or produces NaN (e.g. 0.0/0.0) and the result is passed in.
Common situations: Numerical overflow in probability/log computations in NLP pipelines; dividing by zero-size counts; uninitialized fields that default to NaN being passed to math helpers.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Can't normalize an array with sum 0.0 or NaN: " +…
- Can't normalize an array with sum 0.0 or NaN
- Can't normalize an array with sum 0.0 or NaN: " +…
- Can't sample from NaN
- Can't standardize array whose mean is NaN
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/52739ac9db1544bc.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/math/SloppyMath.java:709
/**
* Taken from http://nerds-central.blogspot.com/2011/05/high-speed-parse-double-for-jvm.html
*/
public static double parseDouble(boolean negative, long mantissa, int exponent) {
// Do this with no locals other than the arguments to make it stupid easy
// for the JIT compiler to inline the code.
int e = -16;
return (negative ? -1. : 1.) * (((double)mantissa) * exps[(e + 308)]) * exps[(exponent + 308)];
}
/**
* Segment a double into a mantissa and exponent.
*/
public static Triple<Boolean, Long, Integer> segmentDouble(double d) {
if (Double.isInfinite(d) || Double.isNaN(d)) {
throw new IllegalArgumentException("Cannot handle weird double: " + d);
}
boolean negative = d < 0;
d = Math.abs(d);
int exponent = 0;
while (d >= 10.0) {
exponent += 1;
d = d / 10.;
}
while (d < 1.0) {
exponent -= 1;
d = d * 10.;
}
return Triple.makeTriple(negative, (long) (d * 10000000000000000.), exponent);
}
/**
* From http://nadeausoftware.com/articles/2009/08/java_tip_how_parse_integers_quicklyView on GitHub (pinned to 1b7edd19c4)