@ScalarOperator(CAST)
    @SqlType(StandardTypes.INTEGER)
    public static long castToInteger(@SqlType(StandardTypes.REAL) long value)
    {
        try {
            return DoubleMath.roundToInt(intBitsToFloat((int) value), HALF_UP);
        }
        catch (ArithmeticException e) {
            throw new PrestoException(INVALID_CAST_ARGUMENT, format("Unable to cast %s to integer", intBitsToFloat((int) value)), e);
        }
    }
@Test
    public void testCastToInteger()
    {
        assertFunction("CAST(REAL'754.2008' AS INTEGER)", INTEGER, 754);
        assertFunction("CAST(REAL'-754.1985' AS INTEGER)", INTEGER, -754);
        assertFunction("CAST(REAL'9.99' AS INTEGER)", INTEGER, 10);
        assertFunction("CAST(REAL'-0.0' AS INTEGER)", INTEGER, 0);

        assertFunction("cast(REAL '" + Math.nextDown(0x1.0p31f) + "' as integer)", INTEGER, (int) Math.nextDown(0x1.0p31f));
        assertInvalidFunction("cast(REAL '" + 0x1.0p31 + "' as integer)", INVALID_CAST_ARGUMENT);
        assertInvalidFunction("cast(REAL '" + Math.nextUp(0x1.0p31f) + "' as integer)", INVALID_CAST_ARGUMENT);
        assertInvalidFunction("cast(REAL '" + Math.nextDown(-0x1.0p31f) + "' as integer)", INVALID_CAST_ARGUMENT);
        assertFunction("cast(REAL '" + -0x1.0p31 + "' as integer)", INTEGER, (int) -0x1.0p31);
        assertFunction("cast(REAL '" + Math.nextUp(-0x1.0p31f) + "' as integer)", INTEGER, (int) Math.nextUp(-0x1.0p31f));

        assertInvalidFunction("cast(9.3E9 as integer)", INVALID_CAST_ARGUMENT, "Unable to cast 9.3E9 to integer");
        assertInvalidFunction("cast(-9.3E9 as integer)", INVALID_CAST_ARGUMENT, "Unable to cast -9.3E9 to integer");
        assertInvalidFunction("CAST(cast(nan() AS REAL) as INTEGER)", INVALID_CAST_ARGUMENT, "Unable to cast NaN to integer");
        assertInvalidFunction("CAST(cast(infinity() AS REAL) as INTEGER)", INVALID_CAST_ARGUMENT, "Unable to cast Infinity to integer");
        assertInvalidFunction("CAST(cast(-infinity() AS REAL) as INTEGER)", INVALID_CAST_ARGUMENT, "Unable to cast -Infinity to integer");
        assertInvalidFunction("CAST(REAL '" + (Integer.MAX_VALUE + 0.6) + "' as INTEGER)", INVALID_CAST_ARGUMENT, "Unable to cast 2.14748365E9 to integer");
    }