Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 2d14b99510
Fetching contributors…

Cannot retrieve contributors at this time

144 lines (120 sloc) 4.149 kB
my $real = "";
my $complex = "";
my $function = "";
print <<"Prelude";
// DO NOT EDIT! Autogenerated file, created by tools/make_trig_code.pl.
using Niecza;
using System;
public partial class Builtins {
Prelude
my @normal_functions = <sin asin cos acos tan atan sinh asinh cosh acosh tanh atanh>;
my %inverted_functions = (
sec => "cos", asec => "acos",
cosec => "sin", acosec => "asin",
cotan => "tan", acotan => "atan",
sech => "cosh", asech => "acosh",
cosech => "sinh", acosech => "asinh",
cotanh => "tanh", acotanh => "atanh"
);
# sinh asinh cosh acosh tanh atanh sech asech cosech acosech cotanh acotanh>;
foreach my $function (@normal_functions) {
my $upper_function = ucfirst($function);
if ($function =~ /h/) {
print <<"Function";
static readonly Func<Variable,Variable> ${function}_d = ${function};
public static Variable ${function}(Variable a1) {
P6any o1 = a1.Fetch();
int r1;
if (!o1.mo.is_any)
return HandleSpecial1(a1,o1, ${function}_d);
P6any n1 = GetNumber(a1, o1, out r1);
if (r1 == NR_COMPLEX) {
Complex v1 = PromoteToComplex(r1, n1);
return MakeComplex(v1.$upper_function());
}
{
Complex v1 = PromoteToComplex(r1, n1);
Complex v2 = v1.$upper_function();
if (v2.im < -1e-15 || v2.im > 1e-15) {
return MakeFloat(double.NaN);
} else {
return MakeFloat(v2.re);
}
}
}
Function
} else {
print <<"Function";
static readonly Func<Variable,Variable> ${function}_d = ${function};
public static Variable ${function}(Variable a1) {
P6any o1 = a1.Fetch();
int r1;
if (!o1.mo.is_any)
return HandleSpecial1(a1,o1, ${function}_d);
P6any n1 = GetNumber(a1, o1, out r1);
if (r1 == NR_COMPLEX) {
Complex v1 = PromoteToComplex(r1, n1);
return MakeComplex(v1.$upper_function());
}
{
double v1 = PromoteToFloat(r1, n1);
return MakeFloat(Math.$upper_function(v1));
}
}
Function
}
}
foreach my $function (keys %inverted_functions) {
my $upper_function = ucfirst($function);
my $base_function = ucfirst($inverted_functions{$function});
# print "xyzzy: $base_function\n";
my $double = "1 / Math.$base_function(v1)";
if ($function =~ /^a/) {
$double = "Math.$base_function(1 / v1)";
}
if ($function =~ /h/) {
print <<"Function";
static readonly Func<Variable,Variable> ${function}_d = ${function};
public static Variable ${function}(Variable a1) {
P6any o1 = a1.Fetch();
int r1;
if (!o1.mo.is_any)
return HandleSpecial1(a1,o1, ${function}_d);
P6any n1 = GetNumber(a1, o1, out r1);
if (r1 == NR_COMPLEX) {
Complex v1 = PromoteToComplex(r1, n1);
return MakeComplex(v1.$upper_function());
}
{
Complex v1 = PromoteToComplex(r1, n1);
Complex v2 = v1.$upper_function();
if (v2.im < -1e-15 || v2.im > 1e-15) {
return MakeFloat(double.NaN);
} else {
return MakeFloat(v2.re);
}
}
}
Function
} else {
print <<"Function";
static readonly Func<Variable,Variable> ${function}_d = ${function};
public static Variable ${function}(Variable a1) {
P6any o1 = a1.Fetch();
int r1;
if (!o1.mo.is_any)
return HandleSpecial1(a1,o1, ${function}_d);
P6any n1 = GetNumber(a1, o1, out r1);
if (r1 == NR_COMPLEX) {
Complex v1 = PromoteToComplex(r1, n1);
return MakeComplex(v1.$upper_function());
}
{
double v1 = PromoteToFloat(r1, n1);
return MakeFloat($double);
}
}
Function
}
}
print "}\n";
Jump to Line
Something went wrong with that request. Please try again.