public LexoInteger Ceil()
        {
            if (IsExact())
            {
                return(_mag);
            }

            var floor = Floor();

            return(floor.Add(LexoInteger.One(floor.GetSystem())));
        }
        public static LexoDecimal Parse(string str, ILexoNumeralSystem system)
        {
            var partialIndex = str.IndexOf(system.GetRadixPointChar());

            if (str.LastIndexOf(system.GetRadixPointChar()) != partialIndex)
            {
                throw new FormatException("More than one " + system.GetRadixPointChar());
            }

            if (partialIndex < 0)
            {
                return(Make(LexoInteger.Parse(str, system), 0));
            }

            var intStr = str.Substring(0, partialIndex) + str.Substring(partialIndex + 1);

            return(Make(LexoInteger.Parse(intStr, system), str.Length - 1 - partialIndex));
        }
        public static LexoDecimal Make(LexoInteger integer, int sig)
        {
            if (integer.IsZero())
            {
                return(new LexoDecimal(integer, 0));
            }

            var zeroCount = 0;

            for (var i = 0; i < sig && integer.GetMag(i) == 0; ++i)
            {
                ++zeroCount;
            }

            var newInteger = integer.ShiftRight(zeroCount);
            var newSig     = sig - zeroCount;

            return(new LexoDecimal(newInteger, newSig));
        }
        public LexoDecimal SetScale(int nSig, bool ceiling)
        {
            if (nSig >= _sig)
            {
                return(this);
            }

            if (nSig < 0)
            {
                nSig = 0;
            }

            var diff = _sig - nSig;
            var nmag = _mag.ShiftRight(diff);

            if (ceiling)
            {
                nmag = nmag.Add(LexoInteger.One(nmag.GetSystem()));
            }

            return(Make(nmag, nSig));
        }
 public static LexoDecimal From(LexoInteger integer)
 {
     return(Make(integer, 0));
 }
        public static LexoDecimal Half(ILexoNumeralSystem sys)
        {
            var mid = sys.GetBase() / 2;

            return(Make(LexoInteger.Make(sys, 1, new[] { mid }), 1));
        }
 private LexoDecimal(LexoInteger mag, int sig)
 {
     _mag = mag;
     _sig = sig;
 }