-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberSymbol.cs
117 lines (102 loc) · 3.82 KB
/
NumberSymbol.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
namespace CalculatorCSharp
{
public class NumberSymbol : Symbol
{
private double numericValue;
public NumberSymbol(string numericString)
{
level = -1;
NumericValue = double.Parse(numericString);
rawSymbol = numericString;
}
public NumberSymbol(double value)
{
level = -1;
NumericValue = value;
}
public double NumericValue
{
get { return numericValue; }
set
{
numericValue = value;
rawSymbol = value.ToString();
}
}
public static implicit operator double(NumberSymbol symbol) => symbol?.numericValue ?? 0;
public static implicit operator NumberSymbol(double number) => new NumberSymbol(number);
/**
* <summary>
* Returns a <see cref="NumberSymbol"/> with an equal negative value.
* </summary>
*/
public static NumberSymbol operator -(NumberSymbol item)
=> new NumberSymbol(-item.NumericValue);
/**
* <summary>
* Returns a <see cref="NumberSymbol"/> equal to the sum of the two
* <see cref="NumberSymbol"/>'s <see cref="NumericValue"/>s.
* </summary>
*/
public static NumberSymbol operator +(NumberSymbol left, NumberSymbol right)
=> new NumberSymbol(left.NumericValue + right.NumericValue);
/**
* <summary>
* Returns a <see cref="NumberSymbol"/> equal to the difference between the two
* <see cref="NumberSymbol"/>'s values.
* </summary>
*/
public static NumberSymbol operator -(NumberSymbol left, NumberSymbol right)
=> new NumberSymbol(left.NumericValue - right.NumericValue);
/**
* <summary>
* Returns a <see cref="NumberSymbol"/> equal to the product of the two
* <see cref="NumberSymbol"/>'s values.
* </summary>
*/
public static NumberSymbol operator *(NumberSymbol left, NumberSymbol right)
=> new NumberSymbol(left.NumericValue * right.NumericValue);
/**
* <summary>
* Returns a <see cref="NumberSymbol"/> equal to the quotient of the two
* <see cref="NumberSymbol"/>'s values.
* </summary>
*/
public static NumberSymbol operator /(NumberSymbol left, NumberSymbol right)
=> new NumberSymbol(left.NumericValue / right.NumericValue);
/**
* <summary>
* Returns a <see cref="NumberSymbol"/> equal to the value of this instance's
* <see cref="NumericValue"/> raised to the power of <paramref name="right"/>'s
* <see cref="NumericValue"/>.
* </summary>
* <param name="right">
* The <see cref="NumberSymbol"/> to raise this instance's value to.
* </param>
*/
public NumberSymbol Pow(NumberSymbol right)
=> new NumberSymbol(System.Math.Pow(numericValue, right));
public static NumberSymbol Negate(NumberSymbol item)
{
return -item;
}
public static NumberSymbol Add(NumberSymbol left, NumberSymbol right)
{
return left + right;
}
public static NumberSymbol Subtract(NumberSymbol left, NumberSymbol right)
{
return left - right;
}
public static NumberSymbol Multiply(NumberSymbol left, NumberSymbol right)
{
return left * right;
}
public static NumberSymbol Divide(NumberSymbol left, NumberSymbol right)
{
return left / right;
}
public double ToDouble() => numericValue;
public static NumberSymbol FromDouble(double number) => new NumberSymbol(number);
}
}