Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Nand.cs
1using System;
7
9{
14 {
24 {
25 }
26
30 public override string FunctionName => nameof(Nand);
31
39 {
40 throw new ScriptRuntimeException("Expected a double or boolean vector.", this);
41 }
42
50 {
51 return new DoubleNumber(CalcNand(Argument.Values, this));
52 }
53
60 public static double CalcNand(double[] Values, ScriptNode Node)
61 {
62 double d;
63 ulong Result;
64 int i, c = Values.Length;
65 bool Signed = false;
66
67 if (c == 0)
68 throw new ScriptRuntimeException("Empty set of values.", Node);
69
70 d = Values[0];
71 if (d < long.MinValue || d > ulong.MaxValue || d != Math.Truncate(d))
72 throw new ScriptRuntimeException("Values must be integers.", Node);
73
74 if (d < 0)
75 {
76 Result = (ulong)((long)d);
77 Signed = true;
78 }
79 else
80 {
81 Result = (ulong)d;
82 if (Result == 0)
83 return 0xffffffffffffffff;
84 }
85
86 for (i = 1; i < c; i++)
87 {
88 d = Values[i];
89 if (d < long.MinValue || d > ulong.MaxValue || d != Math.Truncate(d))
90 throw new ScriptRuntimeException("Values must be integers.", Node);
91
92 if (d < 0)
93 {
94 Result = (ulong)(((long)Result) & ((long)Result));
95 Signed = true;
96 }
97 else
98 Result &= (ulong)d;
99
100 if (Result == 0)
101 {
102 if (Signed)
103 return -1;
104 else
105 return 0xffffffffffffffff;
106 }
107 }
108
109 if (Signed)
110 {
111 if (Result > long.MaxValue)
112 throw new ScriptRuntimeException("Overflow.", Node);
113 else
114 return ~(long)Result;
115 }
116 else
117 return ~Result;
118 }
119
127 {
128 return new BooleanValue(CalcNand(Argument.Values, this));
129 }
130
137 public static bool CalcNand(bool[] Values, ScriptNode Node)
138 {
139 int i, c = Values.Length;
140
141 if (c == 0)
142 throw new ScriptRuntimeException("Empty set of values.", Node);
143
144 for (i = 0; i < c; i++)
145 {
146 if (!Values[i])
147 return true;
148 }
149
150 return false;
151 }
152
153 }
154}
Class managing a script expression.
Definition: Expression.cs:39
override IElement EvaluateVector(DoubleVector Argument, Variables Variables)
Evaluates the function on a vector argument.
Definition: Nand.cs:49
static bool CalcNand(bool[] Values, ScriptNode Node)
Calculates the logical NAND of all boolean-valued elements.
Definition: Nand.cs:137
override IElement EvaluateVector(IVector Argument, Variables Variables)
Evaluates the function on a vector argument.
Definition: Nand.cs:38
override string FunctionName
Name of the function
Definition: Nand.cs:30
static double CalcNand(double[] Values, ScriptNode Node)
Calculates the binary NAND of all double-valued elements. Values must be integers.
Definition: Nand.cs:60
override IElement EvaluateVector(BooleanVector Argument, Variables Variables)
Evaluates the function on a vector argument.
Definition: Nand.cs:126
Nand(ScriptNode Argument, int Start, int Length, Expression Expression)
Nand(v)
Definition: Nand.cs:22
ScriptNode Argument
Function argument.
Base class for funcions of one vector variable.
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
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
Basic interface for vectors.
Definition: IVector.cs:9