Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 144 lines (120 sloc) 4.321 kb
08a7d84 @colomon Significant expansion of the C# Complex class in Utils.cs. Complete impl...
colomon authored
1 my $real = "";
2 my $complex = "";
3 my $function = "";
4
5 print <<"Prelude";
6 // DO NOT EDIT! Autogenerated file, created by tools/make_trig_code.pl.
7 using Niecza;
8 using System;
9
10 public partial class Builtins {
11 Prelude
12
13 my @normal_functions = <sin asin cos acos tan atan sinh asinh cosh acosh tanh atanh>;
14 my %inverted_functions = (
15 sec => "cos", asec => "acos",
16 cosec => "sin", acosec => "asin",
17 cotan => "tan", acotan => "atan",
18 sech => "cosh", asech => "acosh",
19 cosech => "sinh", acosech => "asinh",
20 cotanh => "tanh", acotanh => "atanh"
21 );
22 # sinh asinh cosh acosh tanh atanh sech asech cosech acosech cotanh acotanh>;
23
24 foreach my $function (@normal_functions) {
25 my $upper_function = ucfirst($function);
26
27 if ($function =~ /h/) {
28
29 print <<"Function";
30
e5c7060 @sorear Avoid "Top" use in junctional autothread
authored
31 static readonly Func<Constants,Variable,Variable> ${function}_d = ${function};
32 [ImplicitConsts] public static Variable ${function}(Constants c, Variable a1) {
08a7d84 @colomon Significant expansion of the C# Complex class in Utils.cs. Complete impl...
colomon authored
33 P6any o1 = a1.Fetch();
34 int r1;
35 if (!o1.mo.is_any)
e5c7060 @sorear Avoid "Top" use in junctional autothread
authored
36 return HandleSpecial1(c, a1,o1, ${function}_d);
08a7d84 @colomon Significant expansion of the C# Complex class in Utils.cs. Complete impl...
colomon authored
37 P6any n1 = GetNumber(a1, o1, out r1);
38
39 if (r1 == NR_COMPLEX) {
40 Complex v1 = PromoteToComplex(r1, n1);
41 return MakeComplex(v1.$upper_function());
42 }
43 {
44 Complex v1 = PromoteToComplex(r1, n1);
45 Complex v2 = v1.$upper_function();
46 if (v2.im < -1e-15 || v2.im > 1e-15) {
47 return MakeFloat(double.NaN);
48 } else {
49 return MakeFloat(v2.re);
50 }
51 }
52 }
53 Function
54
55 } else {
56
57 print <<"Function";
58
e5c7060 @sorear Avoid "Top" use in junctional autothread
authored
59 static readonly Func<Constants,Variable,Variable> ${function}_d = ${function};
60 [ImplicitConsts] public static Variable ${function}(Constants c, Variable a1) {
08a7d84 @colomon Significant expansion of the C# Complex class in Utils.cs. Complete impl...
colomon authored
61 P6any o1 = a1.Fetch();
62 int r1;
63 if (!o1.mo.is_any)
e5c7060 @sorear Avoid "Top" use in junctional autothread
authored
64 return HandleSpecial1(c, a1,o1, ${function}_d);
08a7d84 @colomon Significant expansion of the C# Complex class in Utils.cs. Complete impl...
colomon authored
65 P6any n1 = GetNumber(a1, o1, out r1);
66
67 if (r1 == NR_COMPLEX) {
68 Complex v1 = PromoteToComplex(r1, n1);
69 return MakeComplex(v1.$upper_function());
70 }
71 {
72 double v1 = PromoteToFloat(r1, n1);
73 return MakeFloat(Math.$upper_function(v1));
74 }
75 }
76 Function
77 }
78 }
79
80 foreach my $function (keys %inverted_functions) {
81 my $upper_function = ucfirst($function);
82 my $base_function = ucfirst($inverted_functions{$function});
83 # print "xyzzy: $base_function\n";
84 my $double = "1 / Math.$base_function(v1)";
85 if ($function =~ /^a/) {
86 $double = "Math.$base_function(1 / v1)";
87 }
88
89 if ($function =~ /h/) {
90
91 print <<"Function";
92
e5c7060 @sorear Avoid "Top" use in junctional autothread
authored
93 static readonly Func<Constants,Variable,Variable> ${function}_d = ${function};
94 [ImplicitConsts] public static Variable ${function}(Constants c, Variable a1) {
08a7d84 @colomon Significant expansion of the C# Complex class in Utils.cs. Complete impl...
colomon authored
95 P6any o1 = a1.Fetch();
96 int r1;
97 if (!o1.mo.is_any)
e5c7060 @sorear Avoid "Top" use in junctional autothread
authored
98 return HandleSpecial1(c, a1,o1, ${function}_d);
08a7d84 @colomon Significant expansion of the C# Complex class in Utils.cs. Complete impl...
colomon authored
99 P6any n1 = GetNumber(a1, o1, out r1);
100
101 if (r1 == NR_COMPLEX) {
102 Complex v1 = PromoteToComplex(r1, n1);
103 return MakeComplex(v1.$upper_function());
104 }
105 {
106 Complex v1 = PromoteToComplex(r1, n1);
107 Complex v2 = v1.$upper_function();
108 if (v2.im < -1e-15 || v2.im > 1e-15) {
109 return MakeFloat(double.NaN);
110 } else {
111 return MakeFloat(v2.re);
112 }
113 }
114 }
115 Function
116
117 } else {
118
119 print <<"Function";
120
e5c7060 @sorear Avoid "Top" use in junctional autothread
authored
121 static readonly Func<Constants,Variable,Variable> ${function}_d = ${function};
122 [ImplicitConsts] public static Variable ${function}(Constants c, Variable a1) {
08a7d84 @colomon Significant expansion of the C# Complex class in Utils.cs. Complete impl...
colomon authored
123 P6any o1 = a1.Fetch();
124 int r1;
125 if (!o1.mo.is_any)
e5c7060 @sorear Avoid "Top" use in junctional autothread
authored
126 return HandleSpecial1(c, a1,o1, ${function}_d);
08a7d84 @colomon Significant expansion of the C# Complex class in Utils.cs. Complete impl...
colomon authored
127 P6any n1 = GetNumber(a1, o1, out r1);
128
129 if (r1 == NR_COMPLEX) {
130 Complex v1 = PromoteToComplex(r1, n1);
131 return MakeComplex(v1.$upper_function());
132 }
133 {
134 double v1 = PromoteToFloat(r1, n1);
135 return MakeFloat($double);
136 }
137 }
138 Function
139
140 }
141 }
142
8edc022 @sorear Starting inventory of globals that need isolation
authored
143 print "}\n";
Something went wrong with that request. Please try again.