Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
And.cs
1using System;
6
8{
13 {
22 public And(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
23 : base(Left, Right, Start, Length, Expression)
24 {
25 }
26
33 public override IElement EvaluateOptimizedResult(bool Left)
34 {
35 if (!Left)
36 return BooleanValue.False;
37 else
38 return null;
39 }
40
47 public override IElement Evaluate(bool Left, bool Right)
48 {
49 if (Left && Right)
50 return BooleanValue.True;
51 else
52 return BooleanValue.False;
53 }
54
61 public override IElement Evaluate(double Left, double Right)
62 {
63 ulong L, R;
64 bool LSigned;
65 bool RSigned;
66
67 if (Left != Math.Floor(Left) || Right != Math.Floor(Right))
68 throw new ScriptRuntimeException("Operands must be integer values.", this);
69
70 if (Left < 0)
71 {
72 LSigned = true;
73 if (Left < long.MinValue)
74 throw new ScriptRuntimeException("Operand out of bounds.", this);
75
76 L = (ulong)((long)Left);
77 }
78 else
79 {
80 LSigned = false;
81 if (Left > ulong.MaxValue)
82 throw new ScriptRuntimeException("Operand out of bounds.", this);
83
84 L = (ulong)Left;
85 }
86
87 if (Right < 0)
88 {
89 RSigned = true;
90 if (Right < long.MinValue)
91 throw new ScriptRuntimeException("Operand out of bounds.", this);
92
93 R = (ulong)((long)Right);
94 }
95 else
96 {
97 RSigned = false;
98 if (Right > ulong.MaxValue)
99 throw new ScriptRuntimeException("Operand out of bounds.", this);
100
101 R = (ulong)Right;
102 }
103
104 L &= R;
105
106 if (LSigned && RSigned)
107 return new DoubleNumber((long)L);
108 else
109 return new DoubleNumber(L);
110 }
111 }
112}
Class managing a script expression.
Definition: Expression.cs:39
Base class for binary dual double/bool operators.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly BooleanValue False
Constant false value.
static readonly BooleanValue True
Constant true value.
Unspecified And.
Definition: And.cs:13
override IElement Evaluate(bool Left, bool Right)
Evaluates the boolean operator.
Definition: And.cs:47
override IElement EvaluateOptimizedResult(bool Left)
Gives the operator a chance to optimize its execution if it knows the value of the left operand....
Definition: And.cs:33
override IElement Evaluate(double Left, double Right)
Evaluates the double operator.
Definition: And.cs:61
And(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
Binary And.
Definition: And.cs:22
Basic interface for all types of elements.
Definition: IElement.cs:20