Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement sin, Complex.Complex.
  • Loading branch information
colomon authored and sorear committed Jul 7, 2011
1 parent bad54f1 commit 981a202
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/Builtins.cs
Expand Up @@ -760,6 +760,25 @@ class SubstrLValue: Variable {
}
}

static Func<Variable,Variable> sin_d = sin;
public static Variable sin(Variable a1) {
P6any o1 = a1.Fetch();
int r1;
if (!o1.mo.is_any)
return HandleSpecial1(a1,o1, sin_d);
P6any n1 = GetNumber(a1, o1, out r1);

if (r1 == NR_COMPLEX) {
Complex v1 = PromoteToComplex(r1, n1);
return MakeComplex(Math.Sin(v1.re) * Math.Cosh(v1.im),
Math.Cos(v1.re) * Math.Sinh(v1.im));
}
{
double v1 = PromoteToFloat(r1, n1);
return MakeFloat(Math.Sin(v1));
}
}

static Func<Variable,Variable> floor_d = floor;
public static Variable floor(Variable a1) {
P6any o1 = a1.Fetch();
Expand Down
4 changes: 4 additions & 0 deletions lib/CORE.setting
Expand Up @@ -127,6 +127,7 @@ my class Cool {
method sqrt() { sqrt self }
method sign() { sign self }
method conjugate() { self }
method sin() { Q:CgOp { (sin {self}) } }
method split($matcher, $limit?, :$all?) {
my $matchrx = (($matcher ~~ Regex) ?? $matcher !! /$matcher/);
Expand Down Expand Up @@ -345,6 +346,7 @@ my class Complex is Numeric {
method new($re,$im) { $re + $im\i }
method perl() { defined(self) ?? ~self !! self.typename }
method ACCEPTS(Mu $t) { defined(self) ?? self == $t !! $t.^does(self) }
method Complex() { self }
method re() { Q:CgOp { (complex_re {self}) } }
method im() { Q:CgOp { (complex_im {self}) } }
method conjugate() { self.re - (self.im)i }
Expand Down Expand Up @@ -1863,6 +1865,8 @@ sub lines($filehandle = $*IN) { $filehandle.lines }
sub prompt($msg) { print $msg; $*IN.get }
sub getc($handle) { $handle.getc }
sub sin($x) { $x.sin }
INIT {
$PROCESS::IN ::= Q:CgOp { (box TextReader (treader_stdin)) };
$PROCESS::OUT ::= TextWriter.new;
Expand Down

0 comments on commit 981a202

Please sign in to comment.