Beispiel #1
0
        public void Update(Game game)
        {
            if (firstRun)
            {
                Round.Start(game);
                firstRun = false;
            }

            Round?.Update(game);

            if (game.InputAction?.Type != InputActionType.RoundButton &&
                Round != null &&
                !Round.RoundEnd)
            {
                return;
            }

            Round?.Stop(game);
            Round.RoundEnd = false;

            RoundMode += 1;
            RoundMode  = (RoundMode)((int)RoundMode % maxRoundMode);

            Round = rounds.FirstOrDefault(x => x.Round == RoundMode);

            Round?.Start(game);

            roundModeCell.Text = ("RoundMode: " + RoundMode).PadRight(20, ' ');
        }
Beispiel #2
0
 public static double Round(this double d, int place, RoundMode mode)
 {
     double a = (10).Pow(place);
     double[] addValues = { 0.9, 0.5, 0 };
     double d1 = (d * a + addValues[(int)mode]).KillDecimal();
     return d1.Divide(a);
 }
Beispiel #3
0
        /// <summary>
        /// Round specified value to divisor, with mode.
        /// Examples:
        /// _RoundToDivisor(156, 100, Math) = 200;
        /// _RoundToDivisor(1645, 100, Ceiling) = 1700;
        /// _RoundToDivisor(1645, 300, Ceiling) = 1800;
        /// _RoundToDivisor(59140, 900, Math) = 59400     (time in seconds: 16:25:40, 15 minute, Math = 16:30:00)
        /// </summary>
        /// <param name="value"></param>
        /// <param name="divisor"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        private static double _RoundToDivisor(double value, double divisor, RoundMode mode)
        {
            double result = value;

            if (divisor > 0d)
            {
                double count = value / divisor;
                switch (mode)
                {
                case RoundMode.Floor:
                    count = Math.Floor(count);
                    break;

                case RoundMode.Math:
                    count = Math.Round(count, 0, MidpointRounding.AwayFromZero);
                    break;

                case RoundMode.Ceiling:
                    count = Math.Ceiling(count);
                    break;
                }
                result = count * divisor;
            }
            return(result);
        }
Beispiel #4
0
        private static double RoundInternal(double value, RoundMode mode)
        {
            double tmp_value;

            if (value >= 0.0)
            {
                tmp_value = Math.Floor(value + 0.5);
                if (mode != RoundMode.HalfUp)
                {
                    if ((mode == RoundMode.HalfDown && value == (-0.5 + tmp_value)) ||
                        (mode == RoundMode.HalfEven && value == (0.5 + 2 * Math.Floor(tmp_value * .5))) ||
                        (mode == RoundMode.HalfOdd && value == (0.5 + 2 * Math.Floor(tmp_value * .5) - 1.0)))
                    {
                        tmp_value = tmp_value - 1.0;
                    }
                }
            }
            else
            {
                tmp_value = Math.Ceiling(value - 0.5);
                if (mode != RoundMode.HalfUp)
                {
                    if ((mode == RoundMode.HalfDown && value == (0.5 + tmp_value)) ||
                        (mode == RoundMode.HalfEven && value == (-0.5 + 2 * Math.Ceiling(tmp_value * .5))) ||
                        (mode == RoundMode.HalfOdd && value == (-0.5 + 2 * Math.Ceiling(tmp_value * .5) + 1.0)))
                    {
                        tmp_value = tmp_value + 1.0;
                    }
                }
            }

            return(tmp_value);
        }
Beispiel #5
0
        public static Vector128 <float> Sse41VectorRoundF(Vector128 <float> value, CpuThreadState state)
        {
            if (!Sse41.IsSupported)
            {
                throw new PlatformNotSupportedException();
            }

            RoundMode roundMode = state.FPRoundingMode();

            if (roundMode == RoundMode.ToNearest)
            {
                return(Sse41.RoundToNearestInteger(value)); // even
            }
            else if (roundMode == RoundMode.TowardsPlusInfinity)
            {
                return(Sse41.RoundToPositiveInfinity(value));
            }
            else if (roundMode == RoundMode.TowardsMinusInfinity)
            {
                return(Sse41.RoundToNegativeInfinity(value));
            }
            else /* if (roundMode == RoundMode.TowardsZero) */
            {
                return(Sse41.RoundToZero(value));
            }
        }
Beispiel #6
0
 public static decimal Round(this decimal d, int place, RoundMode mode)
 {
     decimal a = (10).Pow(place);
     decimal[] addValues = { 0.9m, 0.5m, 0m };
     decimal d1 = (d * a + addValues[(int)mode]).KillDecimal();
     return d1.Divide(a);
 }
Beispiel #7
0
        public static float NearestMultipleOf(this float x, float multiple, RoundMode rm = RoundMode.UpDown)
        {
            float mod      = x % multiple;
            float midPoint = multiple / 2.0f;

            if (rm == RoundMode.UpDown)
            {
                if (mod > midPoint)
                {
                    return(x + (multiple - mod));
                }
                else
                {
                    return(x - mod);
                }
            }
            else if (rm == RoundMode.Up)
            {
                return(x + (multiple - mod));
            }
            else//(rm == RoundMode.Down)
            {
                return(x - mod);
            }
        }
Beispiel #8
0
        public int TranslateToGrid(double value, RoundMode roundingMode)
        {
            var result = Translate(value);

            switch (roundingMode)
            {
            case RoundMode.Round:
            {
                return((int)Math.Round(result));
            }

            case RoundMode.Ceiling:
            {
                return((int)Math.Ceiling(result));
            }

            case RoundMode.Floor:
            {
                return((int)Math.Floor(result));
            }

            case RoundMode.Truncate:
            {
                return((int)Math.Truncate(result));
            }
            }
            throw new InvalidEnumArgumentException();
        }
 private void Awake()
 {
     RoundMode.roundMode = this;
     isEndGame           = false;
     Time.timeScale      = 1f;
     Invoke("GetPlayerWithTeam", 0.5f);
     LobbyButton.onClick.AddListener(OnClick_BackToLobby);
 }
Beispiel #10
0
        /// <summary>
        /// Sets how image dimensions should be rounded to be power of two.
        /// </summary>
        /// <param name="inputOptions">Pointer to input options object.</param>
        /// <param name="roundMode">Round mode enumeration.</param>
        public void SetInputOptionsRoundMode(IntPtr inputOptions, RoundMode roundMode)
        {
            if (inputOptions == IntPtr.Zero)
            {
                return;
            }

            LoadIfNotLoaded();

            Functions.nvttSetInputOptionsRoundMode func = GetFunction <Functions.nvttSetInputOptionsRoundMode>(FunctionNames.nvttSetInputOptionsRoundMode);

            func(inputOptions, roundMode);
        }
Beispiel #11
0
        private static string GetVectorSse41NameRnd(RoundMode roundMode)
        {
            switch (roundMode)
            {
            case RoundMode.ToNearest:
                return(nameof(Sse41.RoundToNearestInteger));    // even

            case RoundMode.TowardsPlusInfinity:
                return(nameof(Sse41.RoundToPositiveInfinity));

            case RoundMode.TowardsMinusInfinity:
                return(nameof(Sse41.RoundToNegativeInfinity));

            default:     /* case RoundMode.TowardsZero: */
                return(nameof(Sse41.RoundToZero));
            }
        }
Beispiel #12
0
        public void Reset()
        {
            ValueType v;

            Freedom            = Vector2.UnitX;
            Projection         = Vector2.UnitX;
            DualProjection     = Vector2.UnitX;
            InstructionControl = InstructionControlFlags.None;
            RoundState         = RoundMode.ToGrid;
            MinDistance        = 1.0f;
            ControlValueCutIn  = 17.0f / 16.0f;
            SingleWidthCutIn   = 0.0f;
            SingleWidthValue   = 0.0f;
            DeltaBase          = 9;
            DeltaShift         = 3;
            Loop     = 1;
            Rp0      = Rp1 = Rp2 = 0;
            AutoFlip = true;
        }
Beispiel #13
0
        private static string GetSse41NameRnd(RoundMode roundMode)
        {
            switch (roundMode)
            {
            case RoundMode.ToNearest:
                return(nameof(Sse41.RoundToNearestInteger));    // even

            case RoundMode.TowardsMinusInfinity:
                return(nameof(Sse41.RoundToNegativeInfinity));

            case RoundMode.TowardsPlusInfinity:
                return(nameof(Sse41.RoundToPositiveInfinity));

            case RoundMode.TowardsZero:
                return(nameof(Sse41.RoundToZero));

            default: throw new ArgumentException(nameof(roundMode));
            }
        }
 public void SetData(int decimals, string method)
 {
     _decimals = decimals;
     if (method == "四捨五入")
     {
         _method = RoundMode.四捨五入;
     }
     else if (method == "無條件捨去")
     {
         _method = RoundMode.無條件捨去;
     }
     else if (method == "無條件進位")
     {
         _method = RoundMode.無條件進位;
     }
     else
     {
         _method = RoundMode.四捨五入;
     }
 }
Beispiel #15
0
        public static float RoundF(float value, CpuThreadState state)
        {
            RoundMode roundMode = state.FPRoundingMode();

            if (roundMode == RoundMode.ToNearest)
            {
                return(MathF.Round(value)); // even
            }
            else if (roundMode == RoundMode.TowardsPlusInfinity)
            {
                return(MathF.Ceiling(value));
            }
            else if (roundMode == RoundMode.TowardsMinusInfinity)
            {
                return(MathF.Floor(value));
            }
            else /* if (roundMode == RoundMode.TowardsZero) */
            {
                return(MathF.Truncate(value));
            }
        }
        /// <summary>
        /// run step 123.
        /// </summary>
        /// <returns></returns>
        public override Expr Parse()
        {
            RoundMode mode = RoundMode.Round;
            Token     t    = _tokenIt.Peek().Token;

            if (string.Compare(t.Text, "up", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                mode = RoundMode.RoundUp;
                _tokenIt.Advance();
            }
            else if (string.Compare(t.Text, "down", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                mode = RoundMode.RoundDown;
                _tokenIt.Advance();
            }
            _tokenIt.Advance();

            // The expression to round.
            var exp = _parser.ParseExpression(null, true, true);

            return(new RoundExpr(mode, exp));
        }
            private decimal GetRoundScore(decimal score, int decimals, RoundMode mode)
            {
                decimal seed = Convert.ToDecimal(Math.Pow(0.1, Convert.ToDouble(decimals)));

                switch (mode)
                {
                default:
                case RoundMode.四捨五入:
                    score = decimal.Round(score, decimals, MidpointRounding.AwayFromZero);
                    break;

                case RoundMode.無條件捨去:
                    score /= seed;
                    score  = decimal.Floor(score);
                    score *= seed;
                    break;

                case RoundMode.無條件進位:
                    decimal d2 = GetRoundScore(score, decimals, RoundMode.無條件捨去);
                    if (d2 != score)
                    {
                        score = d2 + seed;
                    }
                    else
                    {
                        score = d2;
                    }
                    break;
                }
                string ss = "0.";

                for (int i = 0; i < decimals; i++)
                {
                    ss += "0";
                }
                return(Convert.ToDecimal(Math.Round(score, decimals).ToString(ss)));
            }
Beispiel #18
0
        /// <summary>
        /// Rounds a float.
        /// </summary>
        /// <param name="x">The value to round.</param>
        /// <param name="precision">The optional number of decimal digits to round to. Can be less than zero to ommit digits at the end. Default is <c>0</c>.</param>
        /// <param name="mode">One of PHP_ROUND_HALF_UP, PHP_ROUND_HALF_DOWN, PHP_ROUND_HALF_EVEN, or PHP_ROUND_HALF_ODD. Default is <c>PHP_ROUND_HALF_UP</c>.</param>
        /// <returns>The rounded value.</returns>
        public static double round(double x, int precision = 0, RoundMode mode = RoundMode.HalfUp)
        {
            if (Double.IsInfinity(x) || Double.IsNaN(x) || x == default(double))
            {
                return(x);
            }

            if (precision == 0)
            {
                return(RoundInternal(x, mode));
            }
            else
            {
                if (precision > 23 || precision < -23)
                {
                    return(x);
                }

                //
                // Following code is taken from math.c to avoid incorrect .NET rounding
                //

                var precision_places = 14 - _Log10Abs(x);

                var    f1 = Power10Value(precision);
                double tmp_value;

                /* If the decimal precision guaranteed by FP arithmetic is higher than
                 * the requested places BUT is small enough to make sure a non-zero value
                 * is returned, pre-round the result to the precision */
                if (precision_places > precision && precision_places - precision < 15)
                {
                    var f2 = Power10Value(precision_places);
                    tmp_value = x * f2;

                    /* preround the result (tmp_value will always be something * 1e14,
                     * thus never larger than 1e15 here) */
                    tmp_value = RoundInternal(tmp_value, mode);
                    /* now correctly move the decimal point */
                    f2 = Power10Value(Math.Abs(precision - precision_places));
                    /* because places < precision_places */
                    tmp_value = tmp_value / f2;
                }
                else
                {
                    /* adjust the value */
                    tmp_value = x * f1;
                    /* This value is beyond our precision, so rounding it is pointless */
                    if (Math.Abs(tmp_value) >= 1e15)
                    {
                        return(x);
                    }
                }

                /* round the temp value */
                tmp_value = RoundInternal(tmp_value, mode);

                /* see if it makes sense to use simple division to round the value */
                //if (precision < 23 && precision > -23)
                {
                    tmp_value = tmp_value / f1;
                }
                //else
                //{
                //    /* Simple division can't be used since that will cause wrong results.
                //       Instead, the number is converted to a string and back again using
                //       strtod(). strtod() will return the nearest possible FP value for
                //       that string. */

                //    /* 40 Bytes should be more than enough for this format string. The
                //       float won't be larger than 1e15 anyway. But just in case, use
                //       snprintf() and make sure the buffer is zero-terminated */
                //    char buf[40];
                //    snprintf(buf, 39, "%15fe%d", tmp_value, -places);
                //    buf[39] = '\0';
                //    tmp_value = zend_strtod(buf, NULL);
                //    /* couldn't convert to string and back */
                //    if (!zend_finite(tmp_value) || zend_isnan(tmp_value)) {
                //        tmp_value = value;
                //    }
                //}

                return(tmp_value);
            }
        }
Beispiel #19
0
 public void SetRoundMode(RoundMode mode)
 {
     nvttSetInputOptionsRoundMode(options, mode);
 }
Beispiel #20
0
        private static void EmitSse41Fcvt_Signed(ILEmitterCtx context, RoundMode roundMode, bool scalar)
        {
            OpCodeSimd64 op = (OpCodeSimd64)context.CurrOp;

            // sizeF == ((OpCodeSimdShImm64)op).Size - 2
            int sizeF = op.Size & 1;

            if (sizeF == 0)
            {
                Type[] types       = new Type[] { typeof(Vector128 <float>), typeof(Vector128 <float>) };
                Type[] typesRndCvt = new Type[] { typeof(Vector128 <float>) };
                Type[] typesSav    = new Type[] { typeof(int) };

                context.EmitLdvec(op.Rn);
                context.EmitLdvec(op.Rn);

                context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.CompareOrdered), types));

                context.EmitLdvec(op.Rn);

                context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.And), types));

                if (op is OpCodeSimdShImm64 fixedOp)
                {
                    int fBits = GetImmShr(fixedOp);

                    // BitConverter.Int32BitsToSingle(fpScaled) == MathF.Pow(2f, fBits)
                    int fpScaled = 0x3F800000 + fBits * 0x800000;

                    context.EmitLdc_I4(fpScaled);
                    context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));

                    context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), types));
                }

                context.EmitCall(typeof(Sse41).GetMethod(GetVectorSse41NameRnd(roundMode), typesRndCvt));

                context.EmitStvectmp();
                context.EmitLdvectmp();

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Int32), typesRndCvt));

                context.EmitLdvectmp();

                context.EmitLdc_I4(0x4F000000); // 2.14748365E9f (2147483648)
                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));

                context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqual), types));

                context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Xor), types));

                context.EmitStvec(op.Rd);

                if (scalar)
                {
                    EmitVectorZero32_128(context, op.Rd);
                }
                else if (op.RegisterSize == RegisterSize.Simd64)
                {
                    EmitVectorZeroUpper(context, op.Rd);
                }
            }
            else /* if (sizeF == 1) */
            {
                Type[] types       = new Type[] { typeof(Vector128 <double>), typeof(Vector128 <double>) };
                Type[] typesRndCvt = new Type[] { typeof(Vector128 <double>) };
                Type[] typesSv     = new Type[] { typeof(long), typeof(long) };
                Type[] typesSav    = new Type[] { typeof(long) };

                context.EmitLdvec(op.Rn);
                context.EmitLdvec(op.Rn);

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.CompareOrdered), types));

                context.EmitLdvec(op.Rn);

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), types));

                if (op is OpCodeSimdShImm64 fixedOp)
                {
                    int fBits = GetImmShr(fixedOp);

                    // BitConverter.Int64BitsToDouble(fpScaled) == Math.Pow(2d, fBits)
                    long fpScaled = 0x3FF0000000000000L + fBits * 0x10000000000000L;

                    context.EmitLdc_I8(fpScaled);
                    context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));

                    context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), types));
                }

                context.EmitCall(typeof(Sse41).GetMethod(GetVectorSse41NameRnd(roundMode), typesRndCvt));

                context.EmitStvectmp();

                if (!scalar)
                {
                    context.EmitLdvectmp();
                    context.EmitLdvectmp();

                    context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.UnpackHigh), types));

                    context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToInt64), typesRndCvt));
                }
                else
                {
                    context.EmitLdc_I8(0L);
                }

                context.EmitLdvectmp();

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToInt64), typesRndCvt));

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetVector128), typesSv));

                context.EmitLdvectmp();

                context.EmitLdc_I8(0x43E0000000000000L); // 9.2233720368547760E18d (9223372036854775808)
                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.CompareGreaterThanOrEqual), types));

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Xor), types));

                context.EmitStvec(op.Rd);

                if (scalar)
                {
                    EmitVectorZeroUpper(context, op.Rd);
                }
            }
        }
Beispiel #21
0
        private static void EmitSse41Fcvt_Signed_Gp(ILEmitterCtx context, RoundMode roundMode, bool isFixed)
        {
            OpCodeSimdCvt64 op = (OpCodeSimdCvt64)context.CurrOp;

            if (op.Size == 0)
            {
                Type[] typesCmpMul = new Type[] { typeof(Vector128 <float>), typeof(Vector128 <float>) };
                Type[] typesAnd    = new Type[] { typeof(Vector128 <long>), typeof(Vector128 <long>) };
                Type[] typesRndCvt = new Type[] { typeof(Vector128 <float>) };
                Type[] typesCvt    = new Type[] { typeof(Vector128 <int>) };
                Type[] typesSav    = new Type[] { typeof(int) };

                //string nameCvt;
                int fpMaxVal;

                if (op.RegisterSize == RegisterSize.Int32)
                {
                    //nameCvt  = nameof(Sse.ConvertToInt32);
                    fpMaxVal = 0x4F000000; // 2.14748365E9f (2147483648)
                }
                else
                {
                    //nameCvt  = nameof(Sse.ConvertToInt64);
                    fpMaxVal = 0x5F000000; // 9.223372E18f (9223372036854775808)
                }

                context.EmitLdvec(op.Rn);
                context.EmitLdvec(op.Rn);

                context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.CompareOrdered), typesCmpMul));

                context.EmitLdvec(op.Rn);

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), typesAnd));

                if (isFixed)
                {
                    // BitConverter.Int32BitsToSingle(fpScaled) == MathF.Pow(2f, op.FBits)
                    int fpScaled = 0x40000000 + (op.FBits - 1) * 0x800000;

                    context.EmitLdc_I4(fpScaled);
                    context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));

                    context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.Multiply), typesCmpMul));
                }

                context.EmitCall(typeof(Sse41).GetMethod(GetSse41NameRnd(roundMode), typesRndCvt));

                context.EmitStvectmp();
                context.EmitLdvectmp();

                // TODO: Use Sse.ConvertToInt64 once it is fixed (in .NET Core 3.0),
                // remove the following if/else and uncomment the code.

                //context.EmitCall(typeof(Sse).GetMethod(nameCvt, typesRndCvt));

                if (op.RegisterSize == RegisterSize.Int32)
                {
                    context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.ConvertToInt32), typesRndCvt));
                }
                else
                {
                    context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToVector128Double), typesRndCvt));
                    context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToInt64), new Type[] { typeof(Vector128 <double>) }));
                }

                context.EmitLdvectmp();

                context.EmitLdc_I4(fpMaxVal);
                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));

                context.EmitCall(typeof(Sse).GetMethod(nameof(Sse.CompareGreaterThanOrEqual), typesCmpMul));

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToInt32), typesCvt));

                if (op.RegisterSize == RegisterSize.Int32)
                {
                    context.Emit(OpCodes.Xor);
                    context.Emit(OpCodes.Conv_U8);
                }
                else
                {
                    context.Emit(OpCodes.Conv_I8);
                    context.Emit(OpCodes.Xor);
                }

                context.EmitStintzr(op.Rd);
            }
            else /* if (op.Size == 1) */
            {
                Type[] typesCmpMul = new Type[] { typeof(Vector128 <double>), typeof(Vector128 <double>) };
                Type[] typesAnd    = new Type[] { typeof(Vector128 <long>), typeof(Vector128 <long>) };
                Type[] typesRndCvt = new Type[] { typeof(Vector128 <double>) };
                Type[] typesCvt    = new Type[] { typeof(Vector128 <int>) };
                Type[] typesSav    = new Type[] { typeof(long) };

                string nameCvt;
                long   fpMaxVal;

                if (op.RegisterSize == RegisterSize.Int32)
                {
                    nameCvt  = nameof(Sse2.ConvertToInt32);
                    fpMaxVal = 0x41E0000000000000L; // 2147483648.0000000d (2147483648)
                }
                else
                {
                    nameCvt  = nameof(Sse2.ConvertToInt64);
                    fpMaxVal = 0x43E0000000000000L; // 9.2233720368547760E18d (9223372036854775808)
                }

                context.EmitLdvec(op.Rn);
                context.EmitLdvec(op.Rn);

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.CompareOrdered), typesCmpMul));

                context.EmitLdvec(op.Rn);

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.And), typesAnd));

                if (isFixed)
                {
                    // BitConverter.Int64BitsToDouble(fpScaled) == Math.Pow(2d, op.FBits)
                    long fpScaled = 0x4000000000000000L + (op.FBits - 1) * 0x10000000000000L;

                    context.EmitLdc_I8(fpScaled);
                    context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));

                    context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.Multiply), typesCmpMul));
                }

                context.EmitCall(typeof(Sse41).GetMethod(GetSse41NameRnd(roundMode), typesRndCvt));

                context.EmitStvectmp();
                context.EmitLdvectmp();

                context.EmitCall(typeof(Sse2).GetMethod(nameCvt, typesRndCvt));

                context.EmitLdvectmp();

                context.EmitLdc_I8(fpMaxVal);
                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.SetAllVector128), typesSav));

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.CompareGreaterThanOrEqual), typesCmpMul));

                context.EmitCall(typeof(Sse2).GetMethod(nameof(Sse2.ConvertToInt32), typesCvt));

                if (op.RegisterSize == RegisterSize.Int32)
                {
                    context.Emit(OpCodes.Xor);
                    context.Emit(OpCodes.Conv_U8);
                }
                else
                {
                    context.Emit(OpCodes.Conv_I8);
                    context.Emit(OpCodes.Xor);
                }

                context.EmitStintzr(op.Rd);
            }
        }
Beispiel #22
0
        private static double RoundInternal(double value, RoundMode mode)
        {
            double tmp_value;

            if (value >= 0.0)
            {
                tmp_value = Math.Floor(value + 0.5);
                if (mode != RoundMode.HalfUp)
                {
                    if ((mode == RoundMode.HalfDown && value == (-0.5 + tmp_value)) ||
                        (mode == RoundMode.HalfEven && value == (0.5 + 2 * Math.Floor(tmp_value * .5))) ||
                        (mode == RoundMode.HalfOdd && value == (0.5 + 2 * Math.Floor(tmp_value * .5) - 1.0)))
                    {
                        tmp_value = tmp_value - 1.0;
                    }
                }
            }
            else
            {
                tmp_value = Math.Ceiling(value - 0.5);
                if (mode != RoundMode.HalfUp)
                {
                    if ((mode == RoundMode.HalfDown && value == (0.5 + tmp_value)) ||
                        (mode == RoundMode.HalfEven && value == (-0.5 + 2 * Math.Ceiling(tmp_value * .5))) ||
                        (mode == RoundMode.HalfOdd && value == (-0.5 + 2 * Math.Ceiling(tmp_value * .5) + 1.0)))
                    {
                        tmp_value = tmp_value + 1.0;
                    }
                }
            }

            return tmp_value;
        }
Beispiel #23
0
 public static int round(double x, int precision, RoundMode mode = RoundMode.Up)
 {
     throw new NotImplementedException();
     return((int)Math.Round(x));
 }
Beispiel #24
0
 public void Reset()
 {
     Freedom = Vector2.UnitX;
     Projection = Vector2.UnitX;
     DualProjection = Vector2.UnitX;
     InstructionControl = InstructionControlFlags.None;
     RoundState = RoundMode.ToGrid;
     MinDistance = 1.0f;
     ControlValueCutIn = 17.0f / 16.0f;
     SingleWidthCutIn = 0.0f;
     SingleWidthValue = 0.0f;
     DeltaBase = 9;
     DeltaShift = 3;
     Loop = 1;
     Rp0 = Rp1 = Rp2 = 0;
     AutoFlip = true;
 }
Beispiel #25
0
 public static int NearestMultipleOf(this int x, int multiple, RoundMode rm = RoundMode.UpDown)
 {
     return(Mathf.RoundToInt(((float)x).NearestMultipleOf((float)multiple, rm)));
 }
Beispiel #26
0
        public static double Round(double x, int precision /*= 0*/, RoundMode mode /*= RoundMode.HalfUp*/)
        {
            if (Double.IsInfinity(x) || Double.IsNaN(x) || x == default(double))
                return x;

            if (precision == 0)
            {
                return RoundInternal(x, mode);
            }
            else
            {
                if (precision > 23 || precision < -23)
                    return x;

                //
                // Following code is taken from math.c to avoid incorrect .NET rounding
                //

                var precision_places = 14 - _Log10Abs(x);

                var f1 = Power10Value(precision);
                double tmp_value;

                /* If the decimal precision guaranteed by FP arithmetic is higher than
                   the requested places BUT is small enough to make sure a non-zero value
                   is returned, pre-round the result to the precision */
                if (precision_places > precision && precision_places - precision < 15)
                {
                    var f2 = Power10Value(precision_places);
                    tmp_value = x * f2;
                    /* preround the result (tmp_value will always be something * 1e14,
                       thus never larger than 1e15 here) */
                    tmp_value = RoundInternal(tmp_value, mode);
                    /* now correctly move the decimal point */
                    f2 = Power10Value(Math.Abs(precision - precision_places));
                    /* because places < precision_places */
                    tmp_value = tmp_value / f2;
                }
                else
                {
                    /* adjust the value */
                    tmp_value = x * f1;
                    /* This value is beyond our precision, so rounding it is pointless */
                    if (Math.Abs(tmp_value) >= 1e15)
                        return x;
                }

                /* round the temp value */
                tmp_value = RoundInternal(tmp_value, mode);

                /* see if it makes sense to use simple division to round the value */
                //if (precision < 23 && precision > -23)
                {
                    tmp_value = tmp_value / f1;
                }
                //else
                //{
                //    /* Simple division can't be used since that will cause wrong results.
                //       Instead, the number is converted to a string and back again using
                //       strtod(). strtod() will return the nearest possible FP value for
                //       that string. */

                //    /* 40 Bytes should be more than enough for this format string. The
                //       float won't be larger than 1e15 anyway. But just in case, use
                //       snprintf() and make sure the buffer is zero-terminated */
                //    char buf[40];
                //    snprintf(buf, 39, "%15fe%d", tmp_value, -places);
                //    buf[39] = '\0';
                //    tmp_value = zend_strtod(buf, NULL);
                //    /* couldn't convert to string and back */
                //    if (!zend_finite(tmp_value) || zend_isnan(tmp_value)) {
                //        tmp_value = value;
                //    }
                //}

                return tmp_value;
            }
        }
Beispiel #27
0
 public OperatingRound(GameState gameState, Company activeCompany, int roundNumber, RoundMode mode)
     : base(activeCompany)
 {
     RoundNumber = roundNumber;
     RoundMode = mode;
 }
Beispiel #28
0
 private extern static void nvttSetInputOptionsRoundMode(IntPtr inputOptions, RoundMode mode);
Beispiel #29
0
        /// <summary>
        /// Round specified DateTime value to nearest whole value in specified interval.
        /// In example, origin = 2014-03-20 14:56:21, round = FromMinutes(15), mode = Floor; result = 2014-03-20 14:45:00
        /// </summary>
        /// <param name="origin">Original DateTime</param>
        /// <param name="round">Round divisor (amount of time, to which will be original DateTime rounded)</param>
        /// <param name="mode">Round mode</param>
        /// <returns>Rounded DateTime</returns>
        public static DateTime RoundDateTime(DateTime origin, TimeSpan round, RoundMode mode)
        {
            DateTime result = origin;
            double   rDays  = round.TotalDays;

            if (round.Ticks <= 0L)
            {   // No round:
                result = origin;
            }
            else if (rDays < 1D)
            {                                                                 // Round time (hour:min:sec):
                double seconds = origin.TimeOfDay.TotalSeconds;               // Time in seconds (i.e. 17.9.2008 16:25:40 = 59140)
                seconds = _RoundToDivisor(seconds, round.TotalSeconds, mode); // Round seconds to divisor, i.e. 15 min = 900 sec: 59140 => 59400 = 16:30:00
                result  = origin.Date.AddSeconds(seconds);                    // Rounded time = Date (without Time) + rounded seconds, i.e. 17.9.2008 + 59400 sec = 16:30:00
            }
            else if (rDays < 7D)
            {                                            // Round date to days:
                double day = origin.TimeOfDay.TotalDays; // Time as day fragment (time 18:00 = 18/24 = 0.75d)
                day    = _RoundToDivisor(day, 1d, mode); // Round day fragment (TimeOfDay) to 0 or 1, by mode
                result = origin.Date.AddDays(day);
            }
            else if (rDays <= 14D)
            {                                                              // Round date to week (to Monday):
                DateTime monday = _GetMonday(origin);                      // Nearest lower (or equal) Monday to origin DateTime
                double   dow    = ((TimeSpan)(origin - monday)).TotalDays; // Day in week as number: Monday 00:00 = 0.00; Sunday 00:00 = 6.00; Sunday 18:00 = 6.75d, and so on... (count of whole day + time in day, beginning Monday, 00:00)
                dow    = _RoundToDivisor(dow, 7d, mode);                   // Value 0.0d or 7.0d
                result = monday.Date.AddDays(dow);
            }
            else if (rDays <= 31d)
            {                                                                        // Round date to first day of Month:
                DateTime first = new DateTime(origin.Year, origin.Month, 1);         // First day of specified year and month
                double   day   = ((TimeSpan)(origin - first)).TotalDays;             // Current day (and time) in month, as number
                double   count = ((TimeSpan)(first.AddMonths(1) - first)).TotalDays; // Count of day in specified month
                day    = _RoundToDivisor(day, count, mode);                          // Value 0.0d or (count)
                result = (day == 0d ? first : first.AddMonths(1));
            }
            else if (rDays <= 92d)
            {   // Round date to first day of Quartale:
                int month = origin.Month;
                month = ((month - 1) / 3) * 3 + 1;
                DateTime first = new DateTime(origin.Year, month, 1);                // First day of specified year and quartale month
                double   day   = ((TimeSpan)(origin - first)).TotalDays;             // Current day (and time) in quartale, as number
                double   count = ((TimeSpan)(first.AddMonths(3) - first)).TotalDays; // Count of day in specified quartale
                day    = _RoundToDivisor(day, count, mode);                          // Value 0.0d or (count)
                result = (day == 0d ? first : first.AddMonths(3));
            }
            else if (rDays <= 182d)
            {   // Round date to 1.1. or to 1.7. (half-year):
                int month = origin.Month;
                month = ((month - 1) / 6) * 6 + 1;
                DateTime first = new DateTime(origin.Year, month, 1);                // First day of specified year and half-year month
                double   day   = ((TimeSpan)(origin - first)).TotalDays;             // Current day (and time) in half-year, as number
                double   count = ((TimeSpan)(first.AddMonths(6) - first)).TotalDays; // Count of day in specified half-year
                day    = _RoundToDivisor(day, count, mode);                          // Value 0.0d or (count)
                result = (day == 0d ? first : first.AddMonths(6));
            }
            else if (rDays <= 366d)
            {                                                                       // Round date to first day of Year:
                DateTime first = new DateTime(origin.Year, 1, 1);                   // First day of specified year
                double   day   = ((TimeSpan)(origin - first)).TotalDays;            // Current day (and time) in month, as number
                double   count = ((TimeSpan)(first.AddYears(1) - first)).TotalDays; // Count of day in specified year
                day    = _RoundToDivisor(day, count, mode);                         // Value 0.0d or (count)
                result = (day == 0d ? first : first.AddYears(1));
            }
            else
            {                                                                       // Round date to first day of n-th Years:
                DateTime first = new DateTime(origin.Year, 1, 1);                   // First day of specified year
                double   day   = ((TimeSpan)(origin - first)).TotalDays;            // Current day (and time) in month, as number
                double   count = ((TimeSpan)(first.AddYears(1) - first)).TotalDays; // Count of day in specified year
                day    = _RoundToDivisor(day, count, mode);                         // Value 0.0d or (count)
                result = (day == 0d ? first : first.AddYears(1));
            }
            return(result);
        }
 public Round()
 {
     _decimals = 2;
     _method   = RoundMode.四捨五入;
 }
Beispiel #31
0
 public MergerRound(Company activeCompany, int roundNumber, RoundMode mode)
     : base(activeCompany)
 {
     RoundNumber = roundNumber;
     RoundMode = mode;
 }
Beispiel #32
0
 public static GridUnitsTranslator GetUnitsTranslator(GridUnit sourceUnit, GridUnit targetUnit, RoundMode roundMode = RoundMode.Round)
 {
     return(new GridUnitsTranslator(sourceUnit, targetUnit, roundMode));
 }
Beispiel #33
0
 public void SetRoundMode(RoundMode mode)
 {
     nvttSetInputOptionsRoundMode(options, mode);
 }
Beispiel #34
0
 public GridUnitsTranslator(GridUnit sourceUnit, GridUnit targetUnit, RoundMode roundMode = RoundMode.Round)
 {
     this.roundMode = roundMode;
     multiplier     = (double)targetUnit.Divisor / sourceUnit.Divisor;
 }
Beispiel #35
0
 private static extern void nvttSetInputOptionsRoundMode(IntPtr inputOptions, RoundMode mode);
Beispiel #36
0
 /// <summary>
 /// Returns specified value (value on axis, TTick: for example DateTime) rounded to an interval (TSize: for example TimeSpan) with RoundMode.
 /// For example on TimeAxis: when value is 15.2.2016 14:35:16.165; and interval is 00:15:00.000, then result RoundValue is 15.2.2016 14:30:00 (for RoundMode = Math).
 /// </summary>
 /// <param name="value">Value (Tick) for round</param>
 /// <param name="interval">Interval on which will be Tick rounded</param>
 /// <param name="roundMode">Mode for round</param>
 /// <returns></returns>
 protected override decimal?RoundTickToInterval(decimal?value, decimal?interval, RoundMode roundMode)
 {
     return(value.HasValue && interval.HasValue ? (decimal?)DecimalNRange.RoundValue(value.Value, interval.Value, roundMode) : (decimal?)null);
 }