示例#1
0
        public DyObject Round(ExecutionContext ctx, DyObject number, [Default(2)] DyObject digits)
        {
            if (number.TypeId != DyType.Float)
            {
                ctx.InvalidType(number);
            }
            else if (digits.TypeId != DyType.Integer)
            {
                ctx.InvalidType(digits);
            }

            return(new DyFloat(Math.Round(number.GetFloat(), (int)digits.GetInteger())));
        }
示例#2
0
        public DyObject Randomize(ExecutionContext _, [Default(int.MaxValue)] DyObject max, [Default(0)] DyObject min, [Default] DyObject seed)
        {
            int iseed;

            if (seed.TypeId != DyType.Nil)
            {
                iseed = (int)seed.GetInteger();
            }
            else
            {
                var dt  = DateTime.Now;
                var dt2 = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, 0, 0);
                iseed = (int)(dt2 - dt).Ticks;
            }

            var rnd = new Random(iseed);

            return(DyInteger.Get(rnd.Next((int)min.GetInteger(), (int)max.GetInteger())));
        }