@ScalarOperator(CAST)
    @SqlType(StandardTypes.INTEGER)
    public static long castToInteger(@SqlType(StandardTypes.DOUBLE) double value)
    {
        try {
            return DoubleMath.roundToInt(value, HALF_UP);
        }
        catch (ArithmeticException e) {
            throw new PrestoException(INVALID_CAST_ARGUMENT, format("Unable to cast %s to integer", value), e);
        }
    }
@Test
    public void testCastToInteger()
    {
        assertFunction("cast(37.7E0 as integer)", INTEGER, 38);
        assertFunction("cast(-37.7E0 as integer)", INTEGER, -38);
        assertFunction("cast(17.1E0 as integer)", INTEGER, 17);
        assertFunction("cast(-17.1E0 as integer)", INTEGER, -17);
        assertFunction("cast(9.2E8 as integer)", INTEGER, 920000000);
        assertFunction("cast(-9.2E8 as integer)", INTEGER, -920000000);
        assertFunction("cast(2.21E8 as integer)", INTEGER, 221000000);
        assertFunction("cast(-2.21E8 as integer)", INTEGER, -221000000);
        assertFunction("cast(17.5E0 as integer)", INTEGER, 18);
        assertFunction("cast(-17.5E0 as integer)", INTEGER, -18);

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

        assertInvalidFunction("cast(9.3E9 as integer)", INVALID_CAST_ARGUMENT);
        assertInvalidFunction("cast(-9.3E9 as integer)", INVALID_CAST_ARGUMENT);

        assertInvalidFunction("cast(infinity() as integer)", INVALID_CAST_ARGUMENT);
        assertInvalidFunction("cast(-infinity() as integer)", INVALID_CAST_ARGUMENT);
        assertInvalidFunction("cast(nan() as integer)", INVALID_CAST_ARGUMENT);
    }