@ScalarOperator(CAST)
    @SqlType(StandardTypes.TINYINT)
    public static long castToTinyint(@SqlType(StandardTypes.REAL) long value)
    {
        try {
            return SignedBytes.checkedCast(DoubleMath.roundToInt(intBitsToFloat((int) value), HALF_UP));
        }
        catch (ArithmeticException | IllegalArgumentException e) {
            throw new PrestoException(INVALID_CAST_ARGUMENT, format("Unable to cast %s to tinyint", intBitsToFloat((int) value)), e);
        }
    }
@Test
    public void testCastToTinyint()
    {
        assertFunction("CAST(REAL'127.45' AS TINYINT)", TINYINT, (byte) 127);
        assertFunction("CAST(REAL'-128.234' AS TINYINT)", TINYINT, (byte) -128);
        assertFunction("CAST(REAL'9.99' AS TINYINT)", TINYINT, (byte) 10);
        assertFunction("CAST(REAL'-0.0' AS TINYINT)", TINYINT, (byte) 0);
        assertInvalidFunction("CAST(cast(nan() AS REAL) as TINYINT)", INVALID_CAST_ARGUMENT, "Unable to cast NaN to tinyint");
        assertInvalidFunction("CAST(cast(infinity() AS REAL) as TINYINT)", INVALID_CAST_ARGUMENT, "Unable to cast Infinity to tinyint");
        assertInvalidFunction("CAST(cast(-infinity() AS REAL) as TINYINT)", INVALID_CAST_ARGUMENT, "Unable to cast -Infinity to tinyint");
        assertInvalidFunction("CAST(REAL '" + (Byte.MAX_VALUE + 0.6) + "' as TINYINT)", INVALID_CAST_ARGUMENT, "Unable to cast 127.6 to tinyint");
    }