This repository was archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMath.cs
1034 lines (966 loc) · 36 KB
/
Math.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using Mathos.Parser;
using System.Text;
using System.Collections.Generic;
using System.Linq;
namespace Groophy.Math
{
public class Math
{
public static double Euler = 2.71828182845904523536028747135266249775724709369995;
public static double Euler_Mascheroni = 0.57721566490153286060651209008240243104215933593992;
public static double Pi = 3.14159265358979323846264338327950288419716939937510;
/// <summary>
/// https://groophy-inc.github.io/addaddition
/// </summary>
/// <param name="main"></param>
/// <param name="add"></param>
/// <returns></returns>
public static GValue Addaddition(GValue main, GValue add)
{
return new GValue((main.get_Decimal + add.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/addaddition
/// </summary>
/// <param name="main"></param>
/// <param name="add"></param>
/// <returns></returns>
public static GValue Addaddition(string main_, string add_)
{
GValue main = new GValue(main_);
GValue add = new GValue(add_);
return new GValue((main.get_Decimal + add.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/addaddition
/// </summary>
/// <param name="main"></param>
/// <param name="add"></param>
/// <returns></returns>
public static GValue Addaddition(GValue main, string add_)
{
GValue add = new GValue(add_);
return new GValue((main.get_Decimal + add.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/addaddition
/// </summary>
/// <param name="main"></param>
/// <param name="add"></param>
/// <returns></returns>
public static GValue Addaddition(string main_, GValue add)
{
GValue main = new GValue(main_);
return new GValue((main.get_Decimal + add.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/subtraction
/// </summary>
/// <param name="main"></param>
/// <param name="track"></param>
/// <returns></returns>
public static GValue Subtraction(GValue main, GValue track)
{
return new GValue((main.get_Decimal - track.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/subtraction
/// </summary>
/// <param name="main"></param>
/// <param name="track"></param>
/// <returns></returns>
public static GValue Subtraction(string main_, string track_)
{
GValue main = new GValue(main_);
GValue track = new GValue(track_);
return new GValue((main.get_Decimal - track.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/subtraction
/// </summary>
/// <param name="main"></param>
/// <param name="track"></param>
/// <returns></returns>
public static GValue Subtraction(GValue main, string track_)
{
GValue track = new GValue(track_);
return new GValue((main.get_Decimal - track.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/subtraction
/// </summary>
/// <param name="main"></param>
/// <param name="track"></param>
/// <returns></returns>
public static GValue Subtraction(string main_, GValue track)
{
GValue main = new GValue(main_);
return new GValue((main.get_Decimal - track.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/multiplication
/// </summary>
/// <param name="main"></param>
/// <param name="multi"></param>
/// <returns></returns>
public static GValue Multiplication(GValue main, GValue multi)
{
return new GValue((main.get_Decimal * multi.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/multiplication
/// </summary>
/// <param name="main"></param>
/// <param name="multi"></param>
/// <returns></returns>
public static GValue Multiplication(string main_, string multi_)
{
GValue main = new GValue(main_);
GValue multi = new GValue(multi_);
return new GValue((main.get_Decimal * multi.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/multiplication
/// </summary>
/// <param name="main"></param>
/// <param name="multi"></param>
/// <returns></returns>
public static GValue Multiplication(GValue main, string multi_)
{
GValue multi = new GValue(multi_);
return new GValue((main.get_Decimal * multi.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/multiplication
/// </summary>
/// <param name="main"></param>
/// <param name="multi"></param>
/// <returns></returns>
public static GValue Multiplication(string main_, GValue multi)
{
GValue main = new GValue(main_);
return new GValue((main.get_Decimal * multi.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/division
/// </summary>
/// <param name="main"></param>
/// <param name="div"></param>
/// <returns></returns>
public static GValue Division(GValue main, GValue div)
{
return new GValue((main.get_Decimal / div.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/division
/// </summary>
/// <param name="main"></param>
/// <param name="div"></param>
/// <returns></returns>
public static GValue Division(string main_, string div_)
{
GValue main = new GValue(main_);
GValue div = new GValue(div_);
return new GValue((main.get_Decimal / div.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/division
/// </summary>
/// <param name="main"></param>
/// <param name="div"></param>
/// <returns></returns>
public static GValue Division(GValue main, string div_)
{
GValue div = new GValue(div_);
return new GValue((main.get_Decimal / div.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/division
/// </summary>
/// <param name="main"></param>
/// <param name="div"></param>
/// <returns></returns>
public static GValue Division(string main_, GValue div)
{
GValue main = new GValue(main_);
return new GValue((main.get_Decimal / div.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/modulo
/// </summary>
/// <param name="divfrom"></param>
/// <param name="divto"></param>
/// <returns></returns>
public static GValue Modulo(GValue divfrom, GValue divto)
{
return new GValue((divfrom.get_Decimal % divto.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/modulo
/// </summary>
/// <param name="divfrom"></param>
/// <param name="divto"></param>
/// <returns></returns>
public static GValue Modulo(string divfrom_, string divto_)
{
GValue divfrom = new GValue(divfrom_);
GValue divto = new GValue(divto_);
return new GValue((divfrom.get_Decimal % divto.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/modulo
/// </summary>
/// <param name="divfrom"></param>
/// <param name="divto"></param>
/// <returns></returns>
public static GValue Modulo(GValue divfrom, string divto_)
{
GValue divto = new GValue(divto_);
return new GValue((divfrom.get_Decimal % divto.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/modulo
/// </summary>
/// <param name="divfrom"></param>
/// <param name="divto"></param>
/// <returns></returns>
public static GValue Modulo(string divfrom_, GValue divto)
{
GValue divfrom = new GValue(divfrom_);
return new GValue((divfrom.get_Decimal % divto.get_Decimal).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/period
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Period(GValue from, GValue to)
{
return new GValue(((from.get_Decimal + to.get_Decimal) / 100).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/period
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Period(GValue from, string to_)
{
GValue to = new GValue(to_);
return new GValue(((from.get_Decimal + to.get_Decimal) / 100).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/period
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Period(string from_, GValue to)
{
GValue from = new GValue(from_);
return new GValue(((from.get_Decimal + to.get_Decimal) / 100).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/Exponent
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Exponent(GValue from, GValue to)
{
return Math.Power(from, to);
}
/// <summary>
/// https://groophy-inc.github.io/period
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Exponent(string from_, string to_)
{
GValue from = new GValue(from_);
GValue to = new GValue(to_);
return Math.Power(from, to);
}
/// <summary>
/// https://groophy-inc.github.io/period
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Exponent(GValue from, string to_)
{
GValue to = new GValue(to_);
return Math.Power(from, to);
}
/// <summary>
/// https://groophy-inc.github.io/period
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Exponent(string from_, GValue to)
{
GValue from = new GValue(from_);
return Math.Power(from, to);
}
/// <summary>
/// https://groophy-inc.github.io/Exponent
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Power(GValue from, GValue to)
{
return new GValue((System.Math.Pow(from.get_Int, to.get_Int)).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/period
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Power(string from_, string to_)
{
GValue from = new GValue(from_);
GValue to = new GValue(to_);
return Math.Power(from, to);
}
/// <summary>
/// https://groophy-inc.github.io/period
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Power(GValue from, string to_)
{
GValue to = new GValue(to_);
return Math.Power(from, to);
}
/// <summary>
/// https://groophy-inc.github.io/period
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Power(string from_, GValue to)
{
GValue from = new GValue(from_);
return Math.Power(from, to);
}
/// <summary>
/// https://groophy-inc.github.io/Exponent
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Caret(GValue from, GValue to)
{
return Math.Power(from, to);
}
/// <summary>
/// https://groophy-inc.github.io/Exponent
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Caret(string from_, string to_)
{
GValue from = new GValue(from_);
GValue to = new GValue(to_);
return Math.Power(from, to);
}
/// <summary>
/// https://groophy-inc.github.io/period
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Caret(GValue from, string to_)
{
GValue to = new GValue(to_);
return Math.Power(from, to);
}
/// <summary>
/// https://groophy-inc.github.io/period
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static GValue Caret(string from_, GValue to)
{
GValue from = new GValue(from_);
return Math.Power(from, to);
}
/// <summary>
/// https://groophy-inc.github.io/sigma
/// </summary>
/// <param name="n"></param>
/// <param name="to"></param>
/// <param name="formula"></param>
/// <returns></returns>
public static GValue Sigma(GValue n, GValue to, string formula)
{
double result = 0;
MathParser parser = new MathParser();
StringBuilder sb = new StringBuilder();
parser.LocalVariables.Add("n", 0);
for (int i = n.get_Int; i < to.get_Int;i++ )
{
parser.LocalVariables["n"] = i;
double res = parser.Parse(formula);
result += res;
sb.Append(formula.Replace("n", i.ToString()) + " = " + res + Environment.NewLine);
}
sb.Append(formula.Replace("n", (to.get_Int+1).ToString()) + " = " + result.ToString() + Environment.NewLine);
GValue re = new GValue(result.ToString());
re.get_String = sb.ToString();
return re;
}
/// <summary>
/// https://groophy-inc.github.io/sigma
/// </summary>
/// <param name="n"></param>
/// <param name="to"></param>
/// <param name="formula"></param>
/// <returns></returns>
public static GValue Sigma(string n_, string to_, string formula)
{
GValue n = new GValue(n_);
GValue to = new GValue(to_);
double result = 0;
MathParser parser = new MathParser();
StringBuilder sb = new StringBuilder();
parser.LocalVariables.Add("n", 0);
for (int i = n.get_Int; i < to.get_Int; i++)
{
parser.LocalVariables["n"] = i;
double res = parser.Parse(formula);
result += res;
sb.Append(formula.Replace("n", i.ToString()) + " = " + res + Environment.NewLine);
}
sb.Append(formula.Replace("n", (to.get_Int + 1).ToString()) + " = " + result.ToString() + Environment.NewLine);
GValue re = new GValue(result.ToString());
re.get_String = sb.ToString();
return re;
}
/// <summary>
/// https://groophy-inc.github.io/sigma
/// </summary>
/// <param name="n"></param>
/// <param name="to"></param>
/// <param name="formula"></param>
/// <returns></returns>
public static GValue Sigma(GValue n, string to_, string formula)
{
GValue to = new GValue(to_);
double result = 0;
MathParser parser = new MathParser();
StringBuilder sb = new StringBuilder();
parser.LocalVariables.Add("n", 0);
for (int i = n.get_Int; i < to.get_Int; i++)
{
parser.LocalVariables["n"] = i;
double res = parser.Parse(formula);
result += res;
sb.Append(formula.Replace("n", i.ToString()) + " = " + res + Environment.NewLine);
}
sb.Append(formula.Replace("n", (to.get_Int + 1).ToString()) + " = " + result.ToString() + Environment.NewLine);
GValue re = new GValue(result.ToString());
re.get_String = sb.ToString();
return re;
}
/// <summary>
/// https://groophy-inc.github.io/sigma
/// </summary>
/// <param name="n"></param>
/// <param name="to"></param>
/// <param name="formula"></param>
/// <returns></returns>
public static GValue Sigma(string n_, GValue to, string formula)
{
GValue n = new GValue(n_);
double result = 0;
MathParser parser = new MathParser();
StringBuilder sb = new StringBuilder();
parser.LocalVariables.Add("n", 0);
for (int i = n.get_Int; i < to.get_Int; i++)
{
parser.LocalVariables["n"] = i;
double res = parser.Parse(formula);
result += res;
sb.Append(formula.Replace("n", i.ToString()) + " = " + res + Environment.NewLine);
}
sb.Append(formula.Replace("n", (to.get_Int + 1).ToString()) + " = " + result.ToString() + Environment.NewLine);
GValue re = new GValue(result.ToString());
re.get_String = sb.ToString();
return re;
}
/// <summary>
/// https://groophy-inc.github.io/root
/// </summary>
/// <param name="n"></param>
/// <param name="val"></param>
/// <returns></returns>
public static GValue Root(GValue n, GValue val)
{
return new GValue((System.Math.Pow(val.get_Double,Math.Division(new GValue("1"), n).get_Double)).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/root
/// </summary>
/// <param name="n"></param>
/// <param name="val"></param>
/// <returns></returns>
public static GValue Root(string n_, string val_)
{
GValue n = new GValue(n_);
GValue val = new GValue(val_);
return new GValue((System.Math.Pow(val.get_Double, Math.Division(new GValue("1"), n).get_Double)).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/root
/// </summary>
/// <param name="n"></param>
/// <param name="val"></param>
/// <returns></returns>
public static GValue Root(GValue n, string val_)
{
GValue val = new GValue(val_);
return new GValue((System.Math.Pow(val.get_Double, Math.Division(new GValue("1"), n).get_Double)).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/root
/// </summary>
/// <param name="n"></param>
/// <param name="val"></param>
/// <returns></returns>
public static GValue Root(string n_, GValue val)
{
GValue n = new GValue(n_);
return new GValue((System.Math.Pow(val.get_Double, Math.Division(new GValue("1"), n).get_Double)).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/root
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static GValue Square_Root(GValue val)
{
return new GValue((System.Math.Pow(val.get_Double, Math.Division(new GValue("1"), new GValue("2")).get_Double)).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/root
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static GValue Square_Root(string val_)
{
GValue val = new GValue(val_);
return new GValue((System.Math.Pow(val.get_Double, Math.Division(new GValue("1"), new GValue("2")).get_Double)).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/root
/// percent - 100
/// per_mille - 1000
/// per_million - 1000000
/// per_billion - 1000000000
/// per_trillion - 1000000000000
/// </summary>
public enum pers
{
percent,
per_mille,
per_million,
per_billion,
per_trillion
}
/// <summary>
/// https://groophy-inc.github.io/per
/// </summary>
/// <param name="value"></param>
/// <param name="p"></param>
/// <returns></returns>
public static GValue Per(GValue value, pers p)
{
switch (p)
{
case pers.percent:
return Math.Division(value, new GValue("1"));
break;
case pers.per_mille:
return Math.Division(value, new GValue("10"));
break;
case pers.per_million:
return Math.Division(value, new GValue("10000"));
break;
case pers.per_billion:
return Math.Division(value, new GValue("10000000"));
break;
case pers.per_trillion:
return Math.Division(value, new GValue("10000000000"));
break;
}
return new GValue("0");
}
/// <summary>
/// https://groophy-inc.github.io/per
/// </summary>
/// <param name="value"></param>
/// <param name="p"></param>
/// <returns></returns>
public static GValue Per(string value_, pers p)
{
GValue value = new GValue(value_);
switch (p)
{
case pers.percent:
return Math.Division(value, new GValue("1"));
break;
case pers.per_mille:
return Math.Division(value, new GValue("10"));
break;
case pers.per_million:
return Math.Division(value, new GValue("10000"));
break;
case pers.per_billion:
return Math.Division(value, new GValue("10000000"));
break;
case pers.per_trillion:
return Math.Division(value, new GValue("10000000000"));
break;
}
return new GValue("0");
}
/// <summary>
/// https://groophy-inc.github.io/abs
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static GValue Abs(GValue value)
{
if (value.get_Long < 0)
{
return Math.Multiplication(value, new GValue("-1"));
}
return value;
}
/// <summary>
/// https://groophy-inc.github.io/abs
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static GValue Abs(string value_)
{
GValue value = new GValue(value_);
if (value.get_Long < 0)
{
return Math.Multiplication(value, new GValue("-1"));
}
return value;
}
/// <summary>
/// https://groophy-inc.github.io/abs
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static GValue Absolute(GValue value)
{
if (value.get_Long < 0)
{
return Math.Multiplication(value, new GValue("-1"));
}
return value;
}
/// <summary>
/// https://groophy-inc.github.io/abs
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static GValue Absolute(string value_)
{
GValue value = new GValue(value_);
if (value.get_Long < 0)
{
return Math.Multiplication(value, new GValue("-1"));
}
return value;
}
/// <summary>
/// https://groophy-inc.github.io/factorial
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static GValue Factorial(GValue val)
{
IEnumerable<int> ints = Enumerable.Range(1, val.get_Int);
return new GValue(ints.Aggregate((f, s) => f * s).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/factorial
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static GValue Factorial(string val_)
{
GValue val = new GValue(val_);
IEnumerable<int> ints = Enumerable.Range(1, val.get_Int);
return new GValue(ints.Aggregate((f, s) => f * s).ToString());
}
/// <summary>
/// https://groophy-inc.github.io/permutation
/// </summary>
/// <param name="n"></param>
/// <param name="k"></param>
/// <returns></returns>
public static GValue Permutation(GValue n, GValue k)
{
return (Division(Factorial(n), Factorial(Subtraction(n, k))));
}
/// <summary>
/// https://groophy-inc.github.io/permutation
/// </summary>
/// <param name="n"></param>
/// <param name="k"></param>
/// <returns></returns>
public static GValue Permutation(string n_, string k_)
{
GValue n = new GValue(n_);
GValue k = new GValue(k_);
return (Division(Factorial(n), Factorial(Subtraction(n, k))));
}
/// <summary>
/// https://groophy-inc.github.io/permutation
/// </summary>
/// <param name="n"></param>
/// <param name="k"></param>
/// <returns></returns>
public static GValue Permutation(string n_, GValue k)
{
GValue n = new GValue(n_);
return (Division(Factorial(n), Factorial(Subtraction(n, k))));
}
/// <summary>
/// https://groophy-inc.github.io/permutation
/// </summary>
/// <param name="n"></param>
/// <param name="k"></param>
/// <returns></returns>
public static GValue Permutation(GValue n, string k_)
{
GValue k = new GValue(k_);
return (Division(Factorial(n), Factorial(Subtraction(n, k))));
}
/// <summary>
/// https://groophy-inc.github.io/combination
/// </summary>
/// <param name="n"></param>
/// <param name="k"></param>
/// <returns></returns>
public static GValue Combination(GValue n, GValue k)
{
GValue ret = Division(Factorial(n), Multiplication(Factorial(k), Factorial(Subtraction(n, k))));
ret.get_String = (Factorial(n).ToString() + "/[" + Factorial(k).ToString() + ".("+Factorial(Subtraction(n, k).ToString()).ToString()+")] = " + ret.get_Decimal.ToString());
return ret;
}
/// <summary>
/// https://groophy-inc.github.io/combination
/// </summary>
/// <param name="n"></param>
/// <param name="k"></param>
/// <returns></returns>
public static GValue Combination(string n_, string k_)
{
GValue n = new GValue(n_);
GValue k = new GValue(k_);
GValue ret = Division(Factorial(n), Multiplication(Factorial(k), Factorial(Subtraction(n, k))));
ret.get_String = (Factorial(n).ToString() + "/[" + Factorial(k).ToString() + ".(" + Factorial(Subtraction(n, k).ToString()).ToString() + ")] = " + ret.get_Decimal.ToString());
return ret;
}
/// <summary>
/// https://groophy-inc.github.io/combination
/// </summary>
/// <param name="n"></param>
/// <param name="k"></param>
/// <returns></returns>
public static GValue Combination(GValue n, string k_)
{
GValue k = new GValue(k_);
GValue ret = Division(Factorial(n), Multiplication(Factorial(k), Factorial(Subtraction(n, k))));
ret.get_String = (Factorial(n).ToString() + "/[" + Factorial(k).ToString() + ".(" + Factorial(Subtraction(n, k).ToString()).ToString() + ")] = " + ret.get_Decimal.ToString());
return ret;
}
/// <summary>
/// https://groophy-inc.github.io/combination
/// </summary>
/// <param name="n"></param>
/// <param name="k"></param>
/// <returns></returns>
public static GValue Combination(string n_, GValue k)
{
GValue n = new GValue(n_);
GValue ret = Division(Factorial(n), Multiplication(Factorial(k), Factorial(Subtraction(n, k))));
ret.get_String = (Factorial(n).ToString() + "/[" + Factorial(k).ToString() + ".(" + Factorial(Subtraction(n, k).ToString()).ToString() + ")] = " + ret.get_Decimal.ToString());
return ret;
}
//TODO LIM https://www.rapidtables.com/math/symbols/Calculus_Symbols.html
}
public class GValue
{
public bool get_Bool { get; set; }
public byte get_Byte { get; set; }
public sbyte get_Sbyte { get; set; }
public short get_Short { get; set; }
public ushort get_UShort { get; set; }
public int get_Int { get; set; }
public uint get_UInt { get; set; }
public long get_Long { get; set; }
public ulong get_ULong { get; set; }
public float get_Float { get; set; }
public double get_Double { get; set; }
public decimal get_Decimal { get; set; }
public string get_String { get; set; }
public string ToString()
{
return get_Decimal.ToString();
}
public void Max()
{
get_Bool = true;
get_Byte = byte.MaxValue;
get_Decimal = decimal.MaxValue;
get_Double = double.MaxValue;
get_Float = float.MaxValue;
get_Int = int.MaxValue;
get_Long = long.MaxValue;
get_Sbyte = sbyte.MaxValue;
get_Short = short.MaxValue;
get_String = int.MaxValue.ToString();
get_UInt = uint.MaxValue;
get_ULong = ulong.MaxValue;
get_UShort = ushort.MaxValue;
}
public GValue(string Val)
{
get_String = Val;
try
{
get_Int = Convert.ToInt16(Val);
}
catch
{
get_Int = 0;
}
try
{
get_Bool = Convert.ToBoolean(Val);
if (get_Int == 1) get_Bool = true;
}
catch
{
get_Bool = false;
}
try
{
get_Byte = Convert.ToByte(Val);
}
catch
{
get_Byte = 0;
}
try
{
get_Decimal = Convert.ToDecimal(Val);
}
catch
{
get_Decimal = 0;
}
try
{
get_Double = Convert.ToDouble(Val);
}
catch
{
get_Double = 0;
}
try
{
get_Float = (float)Convert.ToDouble(Val);
}
catch
{
get_Float = 0;
}
try
{
get_Long = long.Parse(Val);
}
catch
{
get_Long = 0;
}
try
{
get_Sbyte = Convert.ToSByte(Val);
}
catch
{
get_Sbyte = 0;
}
try
{
get_Short = short.Parse(Val);
}
catch
{
get_Short = 0;
}
try
{
get_UInt = Convert.ToUInt16(Val);
}
catch
{
get_UInt = 0;
}
try
{
get_ULong = ulong.Parse(Val);
}
catch