{"record":{"id":"41492a1e59d53d04","repo":"prestodb/presto","slug":"value-sb-is-not-a-valid-single-precision-float","errorCode":null,"errorMessage":"Value (%sb) is not a valid single-precision float","messagePattern":"Value \\((.+?)b\\) is not a valid single-precision float","errorType":"exception","errorClass":"GenericInternalException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/RealType.java","lineNumber":80,"sourceCode":"\n    @Override\n    public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)\n    {\n        // WARNING: the correctness of InCodeGenerator is dependent on the implementation of this\n        // function being the equivalence of internal long representation.\n        float leftValue = intBitsToFloat(leftBlock.getInt(leftPosition));\n        float rightValue = intBitsToFloat(rightBlock.getInt(rightPosition));\n        return realCompare(leftValue, rightValue);\n    }\n\n    @Override\n    public void writeLong(BlockBuilder blockBuilder, long value)\n    {\n        try {\n            toIntExact(value);\n        }\n        catch (ArithmeticException e) {\n            throw new GenericInternalException(format(\"Value (%sb) is not a valid single-precision float\", Long.toBinaryString(value).replace(' ', '0')));\n        }\n        blockBuilder.writeInt((int) value).closeEntry();\n    }\n\n    @Override\n    public boolean equals(Object other)\n    {\n        return other instanceof RealType;\n    }\n\n    @Override\n    public int hashCode()\n    {\n        return getClass().hashCode();\n    }\n}\n","sourceCodeStart":62,"sourceCodeEnd":97,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/RealType.java#L62-L97","documentation":"RealType.writeLong expects a long whose low 32 bits are the IEEE-754 float bits (value must fit exactly in an int). If the value does not fit in an int, toIntExact throws ArithmeticException and the code rethrows GenericInternalException \"Value (%sb) is not a valid single-precision float\" with the binary representation of the long. It means the caller passed a long that is not a 32-bit float bit pattern.","triggerScenarios":"Calling RealType.writeLong(blockBuilder, value) with a long outside Integer.MIN_VALUE..Integer.MAX_VALUE — e.g. raw float bits computed into a wider long, or a long value not first converted to float via floatToRawIntBits / floatToIntBits.","commonSituations":"Extension functions writing REAL values using long intermediates; UDFs returning long while the declared sink expects REAL bit patterns; mistakes in custom code that forgot to truncate to 32-bit float representation.","solutions":["Convert the value to float bits first: writeLong(blockBuilder, floatToRawIntBits((float) doubleValue)) within int range.","If you have a double, cast to float then encode with Math/Float.floatToIntBits.","If the long is user data, range-check it fits in 32 bits before passing to RealType.writeLong."],"exampleFix":"// before\nrealType.writeLong(blockBuilder, someLong);\n// after\nrealType.writeLong(blockBuilder, Float.floatToIntBits((float) someDouble));","handlingStrategy":"validation","validationCode":"if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) throw new IllegalArgumentException(\"not a 32-bit float bit pattern\");","typeGuard":"boolean isValidFloatBits(long v) { return v >= Integer.MIN_VALUE && v <= Integer.MAX_VALUE; }","tryCatchPattern":"try { realType.writeLong(blockBuilder, value); } catch (GenericInternalException e) { /* fix encoding to floatToIntBits */ }","preventionTips":["Always encode floats via Float.floatToIntBits / floatToRawIntBits before RealType.writeLong.","Never pass raw long user data where REAL bit patterns are expected.","Unit-test UDFs that write REAL values with edge-case doubles (NaN, Inf, large magnitudes)."],"tags":["type-mismatch","internal-error","float"],"backgroundTag":"invalid-numeric-representation","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}