コード例 #1
0
        public Value Now(IReadOnlyList <Value> args)
        {
            ArgumentsVerifier.VerifyAndThrow(args, "", ErrorType.InvalidArgument);
            var ticks = DateTime.Now.Ticks / TimeSpan.TicksPerSecond * TimeSpan.TicksPerSecond;

            return(new Value(DateTimeUtility.DateTimeToString(new DateTime(ticks))));
        }
コード例 #2
0
        public Value Average(IReadOnlyList <Value> args)
        {
            var nums = args.Where(a => a.DataType == DataType.Number).ToList();

            ArgumentsVerifier.VerifyAndThrow(nums, "n+", ErrorType.InvalidArgument);
            return(new Value(nums.Average(n => n.Number)));
        }
コード例 #3
0
        public Value DaysInMonth(IReadOnlyList <Value> args)
        {
            ArgumentsVerifier.VerifyAndThrow(args, "s", ErrorType.InvalidArgument);
            var date = DateTimeUtility.ParseDateTime(args[0].String);

            return(new Value(DateTimeUtility.GetDaysInMonth(date.Year, date.Month)));
        }
コード例 #4
0
 public Value Logarithm10(IReadOnlyList <Value> args)
 {
     ArgumentsVerifier.VerifyAndThrow(args, "n", ErrorType.InvalidArgument);
     if (args[0].Number <= 0m)
     {
         throw new ErrorException(ErrorType.InvalidArgument);
     }
     return(new Value(Math.Log((double)args[0].Number, 10.0)));
 }
コード例 #5
0
 public Value Sqrt(IReadOnlyList <Value> args)
 {
     ArgumentsVerifier.VerifyAndThrow(args, "n", ErrorType.InvalidArgument);
     if (args[0].Number < 0m)
     {
         throw new ErrorException(ErrorType.InvalidArgument);
     }
     return(new Value(Math.Sqrt((double)args[0].Number)));
 }
コード例 #6
0
        public Value Median(IReadOnlyList <Value> args)
        {
            var nums = args.Where(x => x.DataType == DataType.Number).ToList();

            ArgumentsVerifier.VerifyAndThrow(nums, "n+", ErrorType.InvalidArgument);
            var sorted = nums.OrderBy(n => n.Number).ToList();
            var a      = sorted[(sorted.Count - 1) / 2].Number / 2m;
            var b      = sorted[(sorted.Count + 0) / 2].Number / 2m;

            return(new Value(a + b));
        }
コード例 #7
0
        public Value Kyureki(IReadOnlyList <Value> args)
        {
            ArgumentsVerifier.VerifyAndThrow(args, "s", ErrorType.InvalidArgument);
            var date = DateTimeUtility.ParseDateTime(args[0].String);
            var sb   = new StringBuilder();

            sb.Append(DateTimeUtility.DateTimeToKyurekiString(date));
            sb.Append(DateTimeUtility.TryGetEtoString(date, out var eto) ? $" {eto}" : null);
            sb.Append(DateTimeUtility.TryGetRokuyoString(date, out var rokuyo) ? $" {rokuyo}" : null);
            return(new Value(sb.ToString()));
        }
コード例 #8
0
        public Value Factorial(IReadOnlyList <Value> args)
        {
            ArgumentsVerifier.VerifyAndThrow(args, "n", ErrorType.InvalidArgument);
            if (args[0].Number < 0m)
            {
                throw new ErrorException(ErrorType.InvalidArgument);
            }
            var f = 1m;

            for (var n = args[0].Number; n > 1; n--)
            {
                f *= n;
            }
            return(new Value(f));
        }
コード例 #9
0
 public Value Logarithm(IReadOnlyList <Value> args)
 {
     ArgumentsVerifier.VerifyAndThrow(args, "nn?", ErrorType.InvalidArgument);
     if (args[0].Number <= 0m)
     {
         throw new ErrorException(ErrorType.InvalidArgument);
     }
     if (args.Count == 2 && args[1].Number < 0m)
     {
         throw new ErrorException(ErrorType.InvalidArgument);
     }
     if (args.Count == 2 && args[1].Number == 1m)
     {
         throw new ErrorException(ErrorType.InvalidArgument);
     }
     return((args.Count == 1) ?
            new Value(Math.Log((double)args[0].Number)) :
            new Value(Math.Log((double)args[0].Number, (double)args[1].Number)));
 }
コード例 #10
0
 public Value Sign(IReadOnlyList <Value> args)
 {
     ArgumentsVerifier.VerifyAndThrow(args, "n", ErrorType.InvalidArgument);
     return(new Value(Math.Sign(args[0].Number)));
 }
コード例 #11
0
 public Value Round(IReadOnlyList <Value> args)
 {
     ArgumentsVerifier.VerifyAndThrow(args, "n", ErrorType.InvalidArgument);
     return(new Value(Math.Round(args[0].Number, MidpointRounding.AwayFromZero)));
 }
コード例 #12
0
 public Value Atan2(IReadOnlyList <Value> args)
 {
     ArgumentsVerifier.VerifyAndThrow(args, "nn", ErrorType.InvalidArgument);
     return(new Value(Degrees(Math.Atan2((double)args[0].Number, (double)args[1].Number))));
 }
コード例 #13
0
 public Value DayOfWeek(IReadOnlyList <Value> args)
 {
     ArgumentsVerifier.VerifyAndThrow(args, "s", ErrorType.InvalidArgument);
     return(new Value(DateTimeUtility.ParseDateTime(args[0].String).DayOfWeek.ToString().Substring(0, 3).ToLower()));
 }
コード例 #14
0
 public Value DayOfYear(IReadOnlyList <Value> args)
 {
     ArgumentsVerifier.VerifyAndThrow(args, "s", ErrorType.InvalidArgument);
     return(new Value(DateTimeUtility.ParseDateTime(args[0].String).DayOfYear));
 }
コード例 #15
0
 public Value Weeks(IReadOnlyList <Value> args)
 {
     ArgumentsVerifier.VerifyAndThrow(args, "s", ErrorType.InvalidArgument);
     return(new Value(DateTimeUtility.ParseTimeSpan(args[0].String).TotalDays / 7.0));
 }