@ScalarOperator(CAST)
    @SqlType(StandardTypes.SMALLINT)
    public static long castToSmallint(@SqlType(StandardTypes.DOUBLE) double value)
    {
        try {
            return Shorts.checkedCast(DoubleMath.roundToInt(value, HALF_UP));
        }
        catch (ArithmeticException | IllegalArgumentException e) {
            throw new PrestoException(INVALID_CAST_ARGUMENT, format("Unable to cast %s to smallint", value), e);
        }
    }
@Test
    public void testCastToSmallInt()
    {
        assertFunction("cast(" + (0x1.0p15 - 0.6) + " as smallint)", SMALLINT, Short.MAX_VALUE);
        assertInvalidFunction("cast(DOUBLE '" + 0x1.0p15 + "' as smallint)", INVALID_CAST_ARGUMENT);
        assertInvalidFunction("cast(9.2E9 as smallint)", INVALID_CAST_ARGUMENT);
        assertInvalidFunction("cast(-9.2E9 as smallint)", INVALID_CAST_ARGUMENT);
        assertInvalidFunction("cast(infinity() as smallint)", INVALID_CAST_ARGUMENT);
        assertInvalidFunction("cast(-infinity() as smallint)", INVALID_CAST_ARGUMENT);
        assertInvalidFunction("cast(nan() as smallint)", INVALID_CAST_ARGUMENT);
    }