Skip to content
This repository
tag: v15
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 144 lines (120 sloc) 4.149 kb
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
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";
Something went wrong with that request. Please try again.