Example #1
0
        public override IMatched <IObject> Execute(Machine machine, IObject x, IObject y)
        {
            if (x is INumeric n1 && y is INumeric n2 && n1.IsPrimitive && n2.IsPrimitive)
            {
                var dx = n1.AsDouble();
                var dy = n2.AsDouble();

                return(Float.FloatObject(dx / dy).Matched());
            }
Example #2
0
        public override void RegisterClassMessages()
        {
            base.RegisterClassMessages();

            classMessages["e".get()]   = (_, _) => (Float)Math.E;
            classMessages["pi".get()]  = (_, _) => (Float)Math.PI;
            classMessages["nan".get()] = (_, _) => (Float)double.NaN;
            classMessages["parse"]     = (_, msg) => parse(msg.Arguments[0].AsString);
            classMessages["max".get()] = (_, _) => Float.FloatObject(double.MaxValue);
            classMessages["min".get()] = (_, _) => Float.FloatObject(double.MinValue);
        }
Example #3
0
 public static IObject parse(string value)
 {
     try
     {
         var number = double.Parse(value.Replace("_", ""));
         return(Success.Object(Float.FloatObject(number)));
     }
     catch (Exception exception)
     {
         return(Failure.Object(exception.Message));
     }
 }
Example #4
0
        public static IMatched <IObject> Evaluate(INumeric x)
        {
            switch (x)
            {
            case Int i:
                return(Int.IntObject(-i.Value).Matched());

            case Float f:
                return(Float.FloatObject(-f.Value).Matched());

            case Long l:
                return(Long.LongObject(-l.Value).Matched());

            case Complex c:
                return(c.Negate().Matched());

            case Rational r:
                return(r.Negate().Matched());

            default:
                return(failedMatch <IObject>(notNumeric((IObject)x)));
            }
        }
Example #5
0
 public Math()
 {
     fields.New("pi", Float.FloatObject(System.Math.PI));
     fields.New("e", Float.FloatObject(System.Math.E));
 }
Example #6
0
 public IObject Parse(string source) => Float.FloatObject(source.ToDouble());