@ScalarOperator(CAST)
    @SqlType(StandardTypes.SMALLINT)
    public static long castToSmallint(@SqlType(StandardTypes.REAL) long value)
    {
        try {
            return Shorts.checkedCast(DoubleMath.roundToInt(intBitsToFloat((int) value), HALF_UP));
        }
        catch (ArithmeticException | IllegalArgumentException e) {
            throw new PrestoException(INVALID_CAST_ARGUMENT, format("Unable to cast %s to smallint", intBitsToFloat((int) value)), e);
        }
    }
@Test
    public void testCastToSmallint()
    {
        assertFunction("CAST(REAL'754.2008' AS SMALLINT)", SMALLINT, (short) 754);
        assertFunction("CAST(REAL'-754.1985' AS SMALLINT)", SMALLINT, (short) -754);
        assertFunction("CAST(REAL'9.99' AS SMALLINT)", SMALLINT, (short) 10);
        assertFunction("CAST(REAL'-0.0' AS SMALLINT)", SMALLINT, (short) 0);
        assertInvalidFunction("CAST(cast(nan() AS REAL) as SMALLINT)", INVALID_CAST_ARGUMENT, "Unable to cast NaN to smallint");
        assertInvalidFunction("CAST(cast(infinity() AS REAL) as SMALLINT)", INVALID_CAST_ARGUMENT, "Unable to cast Infinity to smallint");
        assertInvalidFunction("CAST(cast(-infinity() AS REAL) as SMALLINT)", INVALID_CAST_ARGUMENT, "Unable to cast -Infinity to smallint");
        assertInvalidFunction("CAST(REAL '" + (Short.MAX_VALUE + 0.6) + "' as SMALLINT)", INVALID_CAST_ARGUMENT, "Unable to cast 32767.6 to smallint");
    }