presto-spi/src/main/java/io/prestosql/spi/type/DecimalConversions.java/DecimalConversions/internalDoubleToLongDecimal
class DecimalConversions:    private static Slice internalDoubleToLongDecimal(double value, long precision, long scale)
    {
        if (Double.isInfinite(value) || Double.isNaN(value)) {
            throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast DOUBLE '%s' to DECIMAL(%s, %s)", value, precision, scale));
        }

        try {
            // todo consider changing this implementation to more performant one which does not use intermediate String objects
            BigDecimal bigDecimal = BigDecimal.valueOf(value).setScale(intScale(scale), HALF_UP);
            Slice decimal = Decimals.encodeScaledValue(bigDecimal);
            if (UnscaledDecimal128Arithmetic.overflows(decimal, intScale(precision))) {
                throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast DOUBLE '%s' to DECIMAL(%s, %s)", value, precision, scale));
            }
            return decimal;
        }
        catch (ArithmeticException e) {
            throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast DOUBLE '%s' to DECIMAL(%s, %s)", value, precision, scale));
        }
    }