File tree Expand file tree Collapse file tree 4 files changed +44
-1
lines changed
AbMath/Utilities/Reverse Polish Notation Expand file tree Collapse file tree 4 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -52,14 +52,26 @@ public static double Min(params double[] Arguments)
52
52
return Arguments [ 1 ] ;
53
53
}
54
54
55
+ public static double Lcm ( params double [ ] Arguments )
56
+ {
57
+ return ( Arguments [ 0 ] * Arguments [ 1 ] ) / Gcd ( Arguments ) ;
58
+ }
59
+
60
+ public static double Gcd ( params double [ ] Arguments )
61
+ {
62
+ Arguments [ 0 ] = Math . Abs ( Arguments [ 0 ] ) ;
63
+ Arguments [ 1 ] = Math . Abs ( Arguments [ 1 ] ) ;
64
+ return ( Arguments [ 1 ] == 0 ) ? Arguments [ 0 ] : Gcd ( Arguments [ 1 ] , Arguments [ 0 ] % Arguments [ 1 ] ) ;
65
+ }
66
+
55
67
public static double ln ( params double [ ] Arguments )
56
68
{
57
69
return Math . Log ( Arguments [ 0 ] ) ;
58
70
}
59
71
60
72
public static double Log ( params double [ ] Arguments )
61
73
{
62
- if ( Arguments . Length == 0 )
74
+ if ( Arguments . Length == 1 )
63
75
{
64
76
return Math . Log ( Arguments [ 0 ] ) ;
65
77
}
Original file line number Diff line number Diff line change @@ -9,6 +9,21 @@ namespace AbMath.Utilities
9
9
/// Reverse Polish Notation
10
10
/// Used for math equations
11
11
/// </summary>
12
+ ///
13
+
14
+ //TODO
15
+ //ABS
16
+ //ARCSIN,ARCTAN,ARCCOS
17
+ //Random
18
+ //Random(Min,Max)
19
+ //Generify
20
+ //Auto Scaling from decimal to double to Big Integer
21
+ //Complex Number Support sqrt(-1) = i
22
+
23
+ //TODO
24
+ //Add a data class so that other classes such as
25
+ //the Tokenizer, Shunter, and the like don't need a copy of RPN.
26
+
12
27
public partial class RPN
13
28
{
14
29
public enum Assoc { Left , Right } ;
Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ public class Shunt : IShunt<string>
19
19
Queue < string > Output ;
20
20
Stack < string > Operator ;
21
21
22
+ //TODO: Implement Variadic Functions
23
+ //See http://wcipeg.com/wiki/Shunting_yard_algorithm#Variadic_functions
24
+ Stack < int > Arity ;
25
+
22
26
public Shunt ( RPN rpn )
23
27
{
24
28
RPN = rpn ;
Original file line number Diff line number Diff line change @@ -50,6 +50,18 @@ private void DefaultFunctions()
50
50
Compute = new Run ( DoFunctions . Round )
51
51
} ) ;
52
52
53
+ AddFunction ( "gcd" , new Functions
54
+ {
55
+ Arguments = 2 ,
56
+ Compute = new Run ( DoFunctions . Gcd )
57
+ } ) ;
58
+
59
+ AddFunction ( "lcm" , new Functions
60
+ {
61
+ Arguments = 2 ,
62
+ Compute = new Run ( DoFunctions . Lcm )
63
+ } ) ;
64
+
53
65
AddFunction ( "ln" , new Functions
54
66
{
55
67
Arguments = 1 ,
You can’t perform that action at this time.
0 commit comments