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()); }
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); }
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)); } }
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))); } }
public Math() { fields.New("pi", Float.FloatObject(System.Math.PI)); fields.New("e", Float.FloatObject(System.Math.E)); }
public IObject Parse(string source) => Float.FloatObject(source.ToDouble());