Skip to content

Commit

Permalink
Rearrange NotComplex and DifferentReal a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed Jul 27, 2011
1 parent 59b5e94 commit 3900295
Show file tree
Hide file tree
Showing 14 changed files with 695 additions and 615 deletions.
200 changes: 112 additions & 88 deletions S32-trig/atan2.t

Large diffs are not rendered by default.

86 changes: 46 additions & 40 deletions S32-trig/cos.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ my @sinhes = @sines.grep({ $_.key < degrees-to-radians(500) }).map({; $_.key =>
my @coshes = @sines.grep({ $_.key < degrees-to-radians(500) }).map({; $_.key =>
(exp($_.key) + exp(-$_.key)) / 2.0 });

class NotComplex is Cool {
has $.value;

multi method new(Complex $value is copy) {
self.bless(*, :$value);
}

multi method Numeric() {
self.value;
}
}

class DifferentReal is Real {
has $.value;

multi method new($value is copy) {
self.bless(*, :$value);
}

multi method Bridge() {
self.value;
}
}



# cos tests
Expand Down Expand Up @@ -66,59 +90,41 @@ for @cosines -> $angle
is(cos(Inf), NaN, "cos(Inf) -");
is(cos(-Inf), NaN, "cos(-Inf) -");

# Num tests
is_approx(cos((-7.85398163404734).Num), 0, "cos(Num) - -7.85398163404734");
is_approx(cos(:x((-5.49778714383314).Num)), 0.707106781186548, "cos(:x(Num)) - -5.49778714383314");
{
# Num tests
is_approx(cos((-7.85398163404734).Num), 0, "cos(Num) - -7.85398163404734");
is_approx(cos(:x((-5.49778714383314).Num)), 0.707106781186548, "cos(:x(Num)) - -5.49778714383314");
}

# Rat tests
is_approx((-2.09439510241262).Rat(1e-9).cos, -0.5, "Rat.cos - -2.09439510241262");
is_approx(cos((-1.57079632680947).Rat(1e-9)), 0, "cos(Rat) - -1.57079632680947");
is_approx(cos(:x((-1.04719755120631).Rat(1e-9))), 0.5, "cos(:x(Rat)) - -1.04719755120631");
{
# Rat tests
is_approx((-2.09439510241262).Rat(1e-9).cos, -0.5, "Rat.cos - -2.09439510241262");
is_approx(cos((-1.57079632680947).Rat(1e-9)), 0, "cos(Rat) - -1.57079632680947");
is_approx(cos(:x((-1.04719755120631).Rat(1e-9))), 0.5, "cos(:x(Rat)) - -1.04719755120631");
}

# Complex tests
is_approx(cos((-0.785398163404734 + 2i).Complex), 2.66027408529666 + 2.56457758882432i, "cos(Complex) - -0.785398163404734 + 2i");
is_approx(cos(:x((0 + 2i).Complex)), 3.76219569108363 + -0i, "cos(:x(Complex)) - 0 + 2i");
{
# Complex tests
is_approx(cos((-0.785398163404734 + 2i).Complex), 2.66027408529666 + 2.56457758882432i, "cos(Complex) - -0.785398163404734 + 2i");
is_approx(cos(:x((0 + 2i).Complex)), 3.76219569108363 + -0i, "cos(:x(Complex)) - 0 + 2i");
}

# Str tests
is_approx((0.785398163404734).Str.cos, 0.707106781186548, "Str.cos - 0.785398163404734");
is_approx(cos((1.57079632680947).Str), 0, "cos(Str) - 1.57079632680947");
is_approx(cos(:x((2.3561944902142).Str)), -0.707106781186548, "cos(:x(Str)) - 2.3561944902142");
{
# Str tests
is_approx((0.785398163404734).Str.cos, 0.707106781186548, "Str.cos - 0.785398163404734");
is_approx(cos((1.57079632680947).Str), 0, "cos(Str) - 1.57079632680947");
is_approx(cos(:x((2.3561944902142).Str)), -0.707106781186548, "cos(:x(Str)) - 2.3561944902142");
}

{
# NotComplex tests

class NotComplex is Cool {
has $.value;

multi method new(Complex $value is copy) {
self.bless(*, :$value);
}

multi method Numeric() {
self.value;
}
}

is_approx(NotComplex.new(3.14159265361894 + 2i).cos, -3.76219569108363 + 1.05698434049896e-10i, "NotComplex.cos - 3.14159265361894 + 2i");
is_approx(cos(NotComplex.new(3.92699081702367 + 2i)), -2.66027408521913 + 2.56457758889906i, "cos(NotComplex) - 3.92699081702367 + 2i");
is_approx(cos(:x(NotComplex.new(4.7123889804284 + 2i))), 1.64464647771967e-10 + 3.62686040784702i, "cos(:x(NotComplex)) - 4.7123889804284 + 2i");
}

{
# DifferentReal tests

class DifferentReal is Real {
has $.value;

multi method new($value is copy) {
self.bless(*, :$value);
}

multi method Bridge() {
self.value;
}
}

is_approx(DifferentReal.new(5.23598775603156).cos, 0.5, "DifferentReal.cos - 5.23598775603156");
is_approx(cos(DifferentReal.new(8.63937979745208)), -0.707106781186548, "cos(DifferentReal) - 8.63937979745208");
is_approx(cos(:x(DifferentReal.new(10.9955742876663))), 0, "cos(:x(DifferentReal)) - 10.9955742876663");
Expand Down
86 changes: 46 additions & 40 deletions S32-trig/cosec.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ my @sinhes = @sines.grep({ $_.key < degrees-to-radians(500) }).map({; $_.key =>
my @coshes = @sines.grep({ $_.key < degrees-to-radians(500) }).map({; $_.key =>
(exp($_.key) + exp(-$_.key)) / 2.0 });

class NotComplex is Cool {
has $.value;

multi method new(Complex $value is copy) {
self.bless(*, :$value);
}

multi method Numeric() {
self.value;
}
}

class DifferentReal is Real {
has $.value;

multi method new($value is copy) {
self.bless(*, :$value);
}

multi method Bridge() {
self.value;
}
}



# cosec tests
Expand Down Expand Up @@ -66,59 +90,41 @@ for @sines -> $angle
is(cosec(Inf), NaN, "cosec(Inf) -");
is(cosec(-Inf), NaN, "cosec(-Inf) -");

# Num tests
is_approx(cosec((-3.92699081702367).Num), 1.41421356232158, "cosec(Num) - -3.92699081702367");
is_approx(cosec(:x((-0.523598775603156).Num)), -1.99999999998317, "cosec(:x(Num)) - -0.523598775603156");
{
# Num tests
is_approx(cosec((-3.92699081702367).Num), 1.41421356232158, "cosec(Num) - -3.92699081702367");
is_approx(cosec(:x((-0.523598775603156).Num)), -1.99999999998317, "cosec(:x(Num)) - -0.523598775603156");
}

# Rat tests
is_approx((0.523598775603156).Rat(1e-9).cosec, 1.99999999998317, "Rat.cosec - 0.523598775603156");
is_approx(cosec((0.785398163404734).Rat(1e-9)), 1.41421356236279, "cosec(Rat) - 0.785398163404734");
is_approx(cosec(:x((1.57079632680947).Rat(1e-9))), 1, "cosec(:x(Rat)) - 1.57079632680947");
{
# Rat tests
is_approx((0.523598775603156).Rat(1e-9).cosec, 1.99999999998317, "Rat.cosec - 0.523598775603156");
is_approx(cosec((0.785398163404734).Rat(1e-9)), 1.41421356236279, "cosec(Rat) - 0.785398163404734");
is_approx(cosec(:x((1.57079632680947).Rat(1e-9))), 1, "cosec(:x(Rat)) - 1.57079632680947");
}

# Complex tests
is_approx(cosec((2.3561944902142 + 2i).Complex), 0.194833118732865 + 0.187824499978879i, "cosec(Complex) - 2.3561944902142 + 2i");
is_approx(cosec(:x((3.92699081702367 + 2i).Complex)), -0.194833118743389 + 0.187824499967129i, "cosec(:x(Complex)) - 3.92699081702367 + 2i");
{
# Complex tests
is_approx(cosec((2.3561944902142 + 2i).Complex), 0.194833118732865 + 0.187824499978879i, "cosec(Complex) - 2.3561944902142 + 2i");
is_approx(cosec(:x((3.92699081702367 + 2i).Complex)), -0.194833118743389 + 0.187824499967129i, "cosec(:x(Complex)) - 3.92699081702367 + 2i");
}

# Str tests
is_approx((4.7123889804284).Str.cosec, -1, "Str.cosec - 4.7123889804284");
is_approx(cosec((5.49778714383314).Str), -1.41421356244522, "cosec(Str) - 5.49778714383314");
is_approx(cosec(:x((6.80678408284103).Str)), 1.99999999978126, "cosec(:x(Str)) - 6.80678408284103");
{
# Str tests
is_approx((4.7123889804284).Str.cosec, -1, "Str.cosec - 4.7123889804284");
is_approx(cosec((5.49778714383314).Str), -1.41421356244522, "cosec(Str) - 5.49778714383314");
is_approx(cosec(:x((6.80678408284103).Str)), 1.99999999978126, "cosec(:x(Str)) - 6.80678408284103");
}

{
# NotComplex tests

class NotComplex is Cool {
has $.value;

multi method new(Complex $value is copy) {
self.bless(*, :$value);
}

multi method Numeric() {
self.value;
}
}

is_approx(NotComplex.new(10.2101761242615 + 2i).cosec, -0.194833118753914 + 0.18782449995538i, "NotComplex.cosec - 10.2101761242615 + 2i");
is_approx(cosec(NotComplex.new(-3.92699081702367 + 2i)), 0.194833118743389 + 0.187824499967129i, "cosec(NotComplex) - -3.92699081702367 + 2i");
is_approx(cosec(:x(NotComplex.new(-0.523598775603156 + 2i))), -0.140337325258517 - 0.234327511878805i, "cosec(:x(NotComplex)) - -0.523598775603156 + 2i");
}

{
# DifferentReal tests

class DifferentReal is Real {
has $.value;

multi method new($value is copy) {
self.bless(*, :$value);
}

multi method Bridge() {
self.value;
}
}

is_approx(DifferentReal.new(0.523598775603156).cosec, 1.99999999998317, "DifferentReal.cosec - 0.523598775603156");
is_approx(cosec(DifferentReal.new(0.785398163404734)), 1.41421356236279, "cosec(DifferentReal) - 0.785398163404734");
is_approx(cosec(:x(DifferentReal.new(1.57079632680947))), 1, "cosec(:x(DifferentReal)) - 1.57079632680947");
Expand Down
86 changes: 46 additions & 40 deletions S32-trig/cosech.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ my @sinhes = @sines.grep({ $_.key < degrees-to-radians(500) }).map({; $_.key =>
my @coshes = @sines.grep({ $_.key < degrees-to-radians(500) }).map({; $_.key =>
(exp($_.key) + exp(-$_.key)) / 2.0 });

class NotComplex is Cool {
has $.value;

multi method new(Complex $value is copy) {
self.bless(*, :$value);
}

multi method Numeric() {
self.value;
}
}

class DifferentReal is Real {
has $.value;

multi method new($value is copy) {
self.bless(*, :$value);
}

multi method Bridge() {
self.value;
}
}



# cosech tests
Expand Down Expand Up @@ -66,59 +90,41 @@ for @sines -> $angle
is(cosech(Inf), 0, "cosech(Inf) -");
is(cosech(-Inf), "-0", "cosech(-Inf) -");

# Num tests
is_approx(cosech((-6.28318530723787).Num), -0.00373489848806798, "cosech(Num) - -6.28318530723787");
is_approx(cosech(:x((-3.92699081702367).Num)), -0.0394210493494572, "cosech(:x(Num)) - -3.92699081702367");
{
# Num tests
is_approx(cosech((-6.28318530723787).Num), -0.00373489848806798, "cosech(Num) - -6.28318530723787");
is_approx(cosech(:x((-3.92699081702367).Num)), -0.0394210493494572, "cosech(:x(Num)) - -3.92699081702367");
}

# Rat tests
is_approx((-0.523598775603156).Rat(1e-9).cosech, -1.8253055746695, "Rat.cosech - -0.523598775603156");
is_approx(cosech((0.523598775603156).Rat(1e-9)), 1.8253055746695, "cosech(Rat) - 0.523598775603156");
is_approx(cosech(:x((0.785398163404734).Rat(1e-9))), 1.15118387090806, "cosech(:x(Rat)) - 0.785398163404734");
{
# Rat tests
is_approx((-0.523598775603156).Rat(1e-9).cosech, -1.8253055746695, "Rat.cosech - -0.523598775603156");
is_approx(cosech((0.523598775603156).Rat(1e-9)), 1.8253055746695, "cosech(Rat) - 0.523598775603156");
is_approx(cosech(:x((0.785398163404734).Rat(1e-9))), 1.15118387090806, "cosech(:x(Rat)) - 0.785398163404734");
}

# Complex tests
is_approx(cosech((1.57079632680947 + 2i).Complex), -0.156411854193272 - 0.372638353746799i, "cosech(Complex) - 1.57079632680947 + 2i");
is_approx(cosech(:x((2.3561944902142 + 2i).Complex)), -0.0772627459225851 - 0.171882832059526i, "cosech(:x(Complex)) - 2.3561944902142 + 2i");
{
# Complex tests
is_approx(cosech((1.57079632680947 + 2i).Complex), -0.156411854193272 - 0.372638353746799i, "cosech(Complex) - 1.57079632680947 + 2i");
is_approx(cosech(:x((2.3561944902142 + 2i).Complex)), -0.0772627459225851 - 0.171882832059526i, "cosech(:x(Complex)) - 2.3561944902142 + 2i");
}

# Str tests
is_approx((3.14159265361894).Str.cosech, 0.086589537527514, "Str.cosech - 3.14159265361894");
is_approx(cosech((3.92699081702367).Str), 0.0394210493494572, "cosech(Str) - 3.92699081702367");
is_approx(cosech(:x((4.7123889804284).Str)), 0.0179680320529917, "cosech(:x(Str)) - 4.7123889804284");
{
# Str tests
is_approx((3.14159265361894).Str.cosech, 0.086589537527514, "Str.cosech - 3.14159265361894");
is_approx(cosech((3.92699081702367).Str), 0.0394210493494572, "cosech(Str) - 3.92699081702367");
is_approx(cosech(:x((4.7123889804284).Str)), 0.0179680320529917, "cosech(:x(Str)) - 4.7123889804284");
}

{
# NotComplex tests

class NotComplex is Cool {
has $.value;

multi method new(Complex $value is copy) {
self.bless(*, :$value);
}

multi method Numeric() {
self.value;
}
}

is_approx(NotComplex.new(5.49778714383314 + 2i).cosech, -0.00340879719539436 - 0.00744860766594804i, "NotComplex.cosech - 5.49778714383314 + 2i");
is_approx(cosech(NotComplex.new(6.28318530723787 + 2i)), -0.00155424826436473 - 0.00339611810181237i, "cosech(NotComplex) - 6.28318530723787 + 2i");
is_approx(cosech(:x(NotComplex.new(6.80678408284103 + 2i))), -0.000920717929196107 - 0.00201181030212346i, "cosech(:x(NotComplex)) - 6.80678408284103 + 2i");
}

{
# DifferentReal tests

class DifferentReal is Real {
has $.value;

multi method new($value is copy) {
self.bless(*, :$value);
}

multi method Bridge() {
self.value;
}
}

is_approx(DifferentReal.new(10.2101761242615).cosech, 7.35879739979009e-05, "DifferentReal.cosech - 10.2101761242615");
is_approx(cosech(DifferentReal.new(12.5663706144757)), 6.97468471168976e-06, "cosech(DifferentReal) - 12.5663706144757");
is_approx(cosech(:x(DifferentReal.new(-6.28318530723787))), -0.00373489848806798, "cosech(:x(DifferentReal)) - -6.28318530723787");
Expand Down
Loading

0 comments on commit 3900295

Please sign in to comment.