Exemple #1
0
        public static double Log(double d)
        {
            // d == 0 ==> -Infty
            Contract.Ensures(d != 0.0 || Double.IsNegativeInfinity(Contract.Result <double>()));

            // 0 < d < 1 ==> < 0
            Contract.Ensures(!(0.0 < d && d < 1.0) || Contract.Result <double>() < 0);

            // d == 1 ==> 1
            Contract.Ensures(d != 1.0 || Contract.Result <double>() == 0.0);

            // d > 1 ==> > 1
            Contract.Ensures(d <1.0 || Contract.Result <double>()> 0.0);

            // d == NaN || d is -Infty ==> Nan
            Contract.Ensures(!Double.IsNaN(d) || !Double.IsNegativeInfinity(d) || Double.IsNaN(Contract.Result <Double>()));

            // d is +Infty ==> +Infty
            Contract.Ensures(!Double.IsPositiveInfinity(d) || Double.IsPositiveInfinity(Contract.Result <Double>()));

            return(default(double));
        }
Exemple #2
0
        private static TimeSpan From(double value, long tickMultiplicator)
        {
            if (Double.IsNaN(value))
            {
                throw new ArgumentException(Locale.GetText("Value cannot be NaN."), "value");
            }
            if (Double.IsNegativeInfinity(value) || Double.IsPositiveInfinity(value) ||
                (value < MinValue.Ticks) || (value > MaxValue.Ticks))
            {
                throw new OverflowException(Locale.GetText("Outside range [MinValue,MaxValue]"));
            }

            try {
                value = (value * (tickMultiplicator / TicksPerMillisecond));

                checked {
                    long val = (long)Math.Round(value);
                    return(new TimeSpan(val * TicksPerMillisecond));
                }
            }
            catch (OverflowException) {
                throw new OverflowException(Locale.GetText("Resulting timespan is too big."));
            }
        }