public override LuryObject Div(LuryObject other) { if (other == null) { throw new LuryException(LuryExceptionType.NilReference); } if (other is LuryInteger) { return(new LuryReal(this.value / ((LuryInteger)other).Value)); } if (other is LuryReal) { return(new LuryReal(this.value / ((LuryReal)other).value)); } if (other is LuryComplex) { var o = (LuryComplex)other; var icd2 = 1.0 / (o.Real * o.Real + o.Imag * o.Imag); return(new LuryComplex((this.value * o.Real) * icd2, (-this.value * o.Imag) * icd2)); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override LuryObject IDiv(LuryObject other) { if (other == null) { throw new LuryException(LuryExceptionType.NilReference); } if (other is LuryInteger) { return(new LuryReal(this.value / ((LuryInteger)other).Value)); } if (other is LuryReal) { var o = ((LuryReal)other).Value; if (o == 0.0) { throw new LuryException(LuryExceptionType.DivideByZero); } return(new LuryReal((double)((long)((double)this.value / o)))); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override LuryObject Con(LuryObject other) { if (other == null) throw new LuryException(LuryExceptionType.NilReference); return new LuryString(this.value + other.ToString()); }
public override LuryObject Pow(LuryObject other) { if (other == null) { throw new LuryException(LuryExceptionType.NilReference); } double or = 0.0, oi = 0.0; if (other is LuryInteger) { or = ((LuryInteger)other).Value; } else if (other is LuryReal) { or = ((LuryReal)other).Value; } else if (other is LuryComplex) { or = ((LuryComplex)other).real; oi = ((LuryComplex)other).imag; } else { throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); } var log_zr = Math.Log(Math.Sqrt(this.real * this.real + this.imag * this.imag)); var log_zi = Math.Atan2(this.imag, this.real); var a_log_zr = or * log_zr - log_zi * oi; var a_log_zi = oi * log_zr + or * log_zi; return(new LuryComplex(Math.Exp(a_log_zr) * Math.Cos(a_log_zi), Math.Exp(a_log_zr) * Math.Sin(a_log_zi))); }
public override LuryObject Mul(LuryObject other) { if (other == null) { throw new LuryException(LuryExceptionType.NilReference); } if (other is LuryInteger) { return(new LuryComplex(this.real * ((LuryInteger)other).Value, this.imag * ((LuryInteger)other).Value)); } if (other is LuryReal) { return(new LuryComplex(this.real * ((LuryReal)other).Value, this.imag * ((LuryReal)other).Value)); } if (other is LuryComplex) { var o = (LuryComplex)other; return(new LuryComplex(this.real * o.Real - this.imag * o.imag, this.imag * o.real + this.real * o.imag)); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override LuryObject Pow(LuryObject other) { if (other == null) { throw new LuryException(LuryExceptionType.NilReference); } if (other is LuryInteger) { return(new LuryReal(Math.Pow(this.value, ((LuryInteger)other).Value))); } if (other is LuryReal) { return(new LuryReal(Math.Pow(this.value, ((LuryReal)other).value))); } if (other is LuryComplex) { var or = ((LuryComplex)other).Real; var oi = ((LuryComplex)other).Imag; var log_zr = Math.Log(this.value); var log_zi = Math.Atan2(0.0, this.value); var a_log_zr = or * log_zr - log_zi * oi; var a_log_zi = oi * log_zr + or * log_zi; return(new LuryComplex(Math.Exp(a_log_zr) * Math.Cos(a_log_zi), Math.Exp(a_log_zr) * Math.Sin(a_log_zi))); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override LuryObject Con(LuryObject other) { if (other == null) { throw new LuryException(LuryExceptionType.NilReference); } return(new LuryString(this.value + other.ToString())); }
public override LuryBoolean CEq(LuryObject other) { if (other == null) throw new LuryException(LuryExceptionType.NilReference); if (!(other is LuryString)) throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); return this.value == ((LuryString)other).value ? LuryBoolean.True : LuryBoolean.False; }
public override LuryObject BAnd(LuryObject other) { if (other == null) throw new LuryException(LuryExceptionType.NilReference); if (other is LuryInteger) return new LuryInteger(this.value & ((LuryInteger)other).value); throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override LuryBoolean CEq(LuryObject other) { if (other == null) throw new LuryException(LuryExceptionType.NilReference); if (other is LuryInteger) return this.value == (double)((LuryInteger)other).Value ? LuryBoolean.True : LuryBoolean.False; if (other is LuryReal) return this.value == ((LuryReal)other).Value ? LuryBoolean.True : LuryBoolean.False; throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override LuryBoolean CEq(LuryObject other) { if (other == null) { throw new LuryException(LuryExceptionType.NilReference); } if (!(other is LuryBoolean)) { throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); } return(this.value == ((LuryBoolean)other).value ? True : False); }
public override LuryObject BOr(LuryObject other) { if (other == null) { throw new LuryException(LuryExceptionType.NilReference); } if (other is LuryInteger) { return(new LuryInteger(this.value | ((LuryInteger)other).value)); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override LuryObject Add(LuryObject other) { if (other == null) throw new LuryException(LuryExceptionType.NilReference); if (other is LuryInteger) return new LuryReal(this.value + ((LuryInteger)other).Value); if (other is LuryReal) return new LuryReal(this.value + ((LuryReal)other).value); if (other is LuryComplex) return new LuryComplex(this.value + ((LuryComplex)other).Real, ((LuryComplex)other).Imag); throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override LuryObject IDiv(LuryObject other) { if (other == null) { throw new LuryException(LuryExceptionType.NilReference); } if (other is LuryInteger) { return(new LuryComplex((double)(long)(this.real / ((LuryInteger)other).Value), (double)(long)(this.imag / ((LuryInteger)other).Value))); } if (other is LuryReal) { return(new LuryComplex((double)(long)(this.real / ((LuryReal)other).Value), (double)(long)(this.imag / ((LuryReal)other).Value))); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override LuryBoolean CEq(LuryObject other) { if (other == null) { throw new LuryException(LuryExceptionType.NilReference); } if (other is LuryInteger) { return(this.value == (double)((LuryInteger)other).Value ? LuryBoolean.True : LuryBoolean.False); } if (other is LuryReal) { return(this.value == ((LuryReal)other).Value ? LuryBoolean.True : LuryBoolean.False); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override LuryObject Sub(LuryObject other) { if (other == null) { throw new LuryException(LuryExceptionType.NilReference); } if (other is LuryInteger) { return(new LuryComplex(this.real - ((LuryInteger)other).Value, this.imag)); } if (other is LuryReal) { return(new LuryComplex(this.real - ((LuryReal)other).Value, this.imag)); } if (other is LuryComplex) { return(new LuryComplex(this.real - ((LuryComplex)other).Real, this.imag - ((LuryComplex)other).Imag)); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public virtual LuryObject BXor(LuryObject other) { throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public void SetMemberNoRecursion(string name, LuryObject value) { this.members.Add(name, value); }
public virtual LuryObject Pow(LuryObject other) { throw new NotSupportedException(); }
public StatementExit(LuryObject returnValue, StatementExitReason reason) { this.ReturnValue = returnValue; this.ExitReason = reason; }
public override void Assign(LuryObject value, LuryContext context) { context[this.reference] = value; }
public override LuryObject IDiv(LuryObject other) { if (other == null) throw new LuryException(LuryExceptionType.NilReference); if (other is LuryInteger) return new LuryReal(this.value / ((LuryInteger)other).Value); if (other is LuryReal) { var o = ((LuryReal)other).Value; if (o == 0.0) throw new LuryException(LuryExceptionType.DivideByZero); return new LuryReal((double)((long)((double)this.value / o))); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public static void SetBuiltInFunctions(LuryObject obj) { obj["println"] = new LuryFunction(PrintLine); obj["print"] = new LuryFunction(Print); }
public override LuryObject Mul(LuryObject other) { if (other == null) throw new LuryException(LuryExceptionType.NilReference); if (other is LuryInteger) return new LuryComplex(this.real * ((LuryInteger)other).Value, this.imag * ((LuryInteger)other).Value); if (other is LuryReal) return new LuryComplex(this.real * ((LuryReal)other).Value, this.imag * ((LuryReal)other).Value); if (other is LuryComplex) { var o = (LuryComplex)other; return new LuryComplex(this.real * o.Real - this.imag * o.imag, this.imag * o.real + this.real * o.imag); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override void Assign(LuryObject value, LuryContext context) { var parentObj = this.parent.Evaluate(context); if (parentObj == null) throw new LuryException(LuryExceptionType.NilReference); if (parentObj.Has(this.child)) parentObj[this.child] = value; else throw new LuryException(LuryExceptionType.AttributeIsNotFound); }
public LuryBoolean IsNot(LuryObject other) { return this.Is(other).LNot(); }
public LuryBoolean Is(LuryObject other) { throw new NotImplementedException(); }
public virtual LuryBoolean CNe(LuryObject other) { return this.CEq(other).LNot(); }
public virtual LuryBoolean CELt(LuryObject other) { return this.CLt(other).LOr(this.CEq(other)); }
public abstract void Assign(LuryObject value, LuryContext context);
public ConstantNode(LuryObject constant) { this.constant = constant; }
public override LuryObject IDiv(LuryObject other) { if (other == null) throw new LuryException(LuryExceptionType.NilReference); if (other is LuryInteger) return new LuryComplex((double)(long)(this.real / ((LuryInteger)other).Value), (double)(long)(this.imag / ((LuryInteger)other).Value)); if (other is LuryReal) return new LuryComplex((double)(long)(this.real / ((LuryReal)other).Value), (double)(long)(this.imag / ((LuryReal)other).Value)); throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public virtual LuryBoolean CEGt(LuryObject other) { return(this.CGt(other).LOr(this.CEq(other))); }
public override LuryObject Pow(LuryObject other) { if (other == null) throw new LuryException(LuryExceptionType.NilReference); double or = 0.0, oi = 0.0; if (other is LuryInteger) or = ((LuryInteger)other).Value; else if (other is LuryReal) or = ((LuryReal)other).Value; else if (other is LuryComplex) { or = ((LuryComplex)other).real; oi = ((LuryComplex)other).imag; } else throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); var log_zr = Math.Log(Math.Sqrt(this.real * this.real + this.imag * this.imag)); var log_zi = Math.Atan2(this.imag, this.real); var a_log_zr = or * log_zr - log_zi * oi; var a_log_zi = oi * log_zr + or * log_zi; return new LuryComplex(Math.Exp(a_log_zr) * Math.Cos(a_log_zi), Math.Exp(a_log_zr) * Math.Sin(a_log_zi)); }
public virtual LuryBoolean CEq(LuryObject other) { throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override LuryObject Div(LuryObject other) { if (other == null) throw new LuryException(LuryExceptionType.NilReference); if (other is LuryInteger) return new LuryReal(this.value / ((LuryInteger)other).Value); if (other is LuryReal) return new LuryReal(this.value / ((LuryReal)other).value); if (other is LuryComplex) { var o = (LuryComplex)other; var icd2 = 1.0 / (o.Real * o.Real + o.Imag * o.Imag); return new LuryComplex((this.value * o.Real) * icd2, (-this.value * o.Imag) * icd2); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public virtual LuryBoolean CNe(LuryObject other) { return(this.CEq(other).LNot()); }
public override LuryObject Pow(LuryObject other) { if (other == null) throw new LuryException(LuryExceptionType.NilReference); if (other is LuryInteger) return new LuryReal(Math.Pow(this.value, ((LuryInteger)other).Value)); if (other is LuryReal) return new LuryReal(Math.Pow(this.value, ((LuryReal)other).value)); if (other is LuryComplex) { var or = ((LuryComplex)other).Real; var oi = ((LuryComplex)other).Imag; var log_zr = Math.Log(this.value); var log_zi = Math.Atan2(0.0, this.value); var a_log_zr = or * log_zr - log_zi * oi; var a_log_zi = oi * log_zr + or * log_zi; return new LuryComplex(Math.Exp(a_log_zr) * Math.Cos(a_log_zi), Math.Exp(a_log_zr) * Math.Sin(a_log_zi)); } throw new LuryException(LuryExceptionType.NotSupportedOperationBinary); }
public override void Assign(LuryObject value, LuryContext context) { this.lvalue.Assign(value, context); }
public LuryBoolean IsNot(LuryObject other) { return(this.Is(other).LNot()); }