Exemplo n.º 1
0
    public static KuduInt128 MaxDecimal128(int precision)
    {
        if (precision > MaxDecimal128Precision)
        {
            throw new ArgumentOutOfRangeException(nameof(precision),
                                                  $"Max precision for decimal128 is {MaxDecimal128Precision}");
        }

        return(KuduInt128.PowerOf10(precision) - 1);
    }
Exemplo n.º 2
0
    public static KuduInt128 EncodeDecimal128(decimal value, int targetPrecision, int targetScale)
    {
        var dec   = new DecimalAccessor(value);
        var scale = (int)dec.Scale;

        CheckConditions(value, scale, targetPrecision, targetScale);

        int scaleAdjustment = targetScale - scale;
        var maxValue        = KuduInt128.PowerOf10(targetPrecision - scaleAdjustment) - 1;
        var unscaledValue   = new KuduInt128(dec.Low, dec.Mid, dec.High, 0);

        if (unscaledValue > maxValue)
        {
            ThrowValueTooBig(value, targetPrecision);
        }

        var factor = KuduInt128.PowerOf10(scaleAdjustment);
        var result = unscaledValue * factor;

        return(dec.IsNegative ? result.Negate() : result);
    }