prestodb/presto · error · GenericInternalException

Value (%sb) is not a valid single-precision float

Error message

Value (%sb) is not a valid single-precision float

What it means

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.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/type/RealType.java:80

    @Override
    public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
    {
        // WARNING: the correctness of InCodeGenerator is dependent on the implementation of this
        // function being the equivalence of internal long representation.
        float leftValue = intBitsToFloat(leftBlock.getInt(leftPosition));
        float rightValue = intBitsToFloat(rightBlock.getInt(rightPosition));
        return realCompare(leftValue, rightValue);
    }

    @Override
    public void writeLong(BlockBuilder blockBuilder, long value)
    {
        try {
            toIntExact(value);
        }
        catch (ArithmeticException e) {
            throw new GenericInternalException(format("Value (%sb) is not a valid single-precision float", Long.toBinaryString(value).replace(' ', '0')));
        }
        blockBuilder.writeInt((int) value).closeEntry();
    }

    @Override
    public boolean equals(Object other)
    {
        return other instanceof RealType;
    }

    @Override
    public int hashCode()
    {
        return getClass().hashCode();
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Convert the value to float bits first: writeLong(blockBuilder, floatToRawIntBits((float) doubleValue)) within int range.
  2. If you have a double, cast to float then encode with Math/Float.floatToIntBits.
  3. If the long is user data, range-check it fits in 32 bits before passing to RealType.writeLong.

Example fix

// before
realType.writeLong(blockBuilder, someLong);
// after
realType.writeLong(blockBuilder, Float.floatToIntBits((float) someDouble));
Defensive patterns

Strategy: validation

Validate before calling

if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) throw new IllegalArgumentException("not a 32-bit float bit pattern");

Type guard

boolean isValidFloatBits(long v) { return v >= Integer.MIN_VALUE && v <= Integer.MAX_VALUE; }

Try / catch

try { realType.writeLong(blockBuilder, value); } catch (GenericInternalException e) { /* fix encoding to floatToIntBits */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/41492a1e59d53d04. Report an issue: GitHub.