Skip to content

Commit

Permalink
Change from-radians to work on self rather than a passed parameter.
Browse files Browse the repository at this point in the history
For some reason Any.from-radians ignored self completely and did its work on a passed parameter.  This patch changes from-radians to work on self instead (like Any.to-radians does).  Note as well that no conversion to Num is done, it just does the math, so it works fine for Complex too.
  • Loading branch information
colomon committed Sep 24, 2009
1 parent 7a33068 commit 3afb78d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/setting/Any-num.pm
Expand Up @@ -55,12 +55,12 @@ class Any is also {
}
}

our Num multi method !from-radians(Num $x, $base) {
our multi method !from-radians($base) {
given $base {
when /:i ^d/ { $x * 180/pi } # Convert to degrees.
when /:i ^g/ { $x * 200/pi } # Convert to gradians.
when /:i ^r/ { $x } # Convert to radians.
when Num { $x /(2 * pi) } # Convert to revolutions.
when /:i ^d/ { self * 180/pi } # Convert to degrees.
when /:i ^g/ { self * 200/pi } # Convert to gradians.
when /:i ^r/ { self } # Convert to radians.
when Num { self /(2 * pi) } # Convert to revolutions.
default { die "Unable to convert to base: $base" }
}
}
Expand Down
27 changes: 14 additions & 13 deletions src/setting/Num.pm
Expand Up @@ -5,7 +5,7 @@ class Num is also {
$N1 = acos $N0
%r = box $N1
};
self!from-radians($r, $base)
$r!from-radians($base)
}
our Num multi method acosh($base = 'radians') is export {
Expand All @@ -18,7 +18,7 @@ class Num is also {
$N0 = ln $N0
%r = box $N0
};
self!from-radians($r, $base)
$r!from-radians($base)
}

our Num multi method acosec($base = 'radians') is export {
Expand All @@ -28,13 +28,14 @@ class Num is also {
$N2 = asin $N1
%r = box $N2
};
self!from-radians($r, $base)
$r!from-radians($base)
}
our Num multi method acosech($base = 'radians') is export {
# MUST: This is certainly wrong -- if nothing else,
# asinh also calls from-radians on its result.
self!from-radians(asinh(1/+self), $base)
# (Except it seems to be passing tests?)
asinh(1/+self)!from-radians($base)
}

our Num multi method acotan($base = 'radians') is export {
Expand All @@ -44,7 +45,7 @@ class Num is also {
$N2 = atan $N1
%r = box $N2
};
self!from-radians($r, $base)
$r!from-radians($base)
}
our Num multi method acotanh($base = 'radians') is export {
Expand All @@ -57,7 +58,7 @@ class Num is also {
$N4 = $N4 / 2
%r = box $N4
};
self!from-radians($r, $base)
$r!from-radians($base)
}

our Num multi method asec($base = 'radians') is export {
Expand All @@ -66,7 +67,7 @@ class Num is also {
$N1 = asec $N0
%r = box $N1
};
self!from-radians($r, $base)
$r!from-radians($base)
}
our Num multi method asech($base = 'radians') is export {
Expand All @@ -81,7 +82,7 @@ class Num is also {
$N1 = ln $N1
%r = box $N1
};
self!from-radians($r, $base)
$r!from-radians($base)
}

our Num multi method asin($base = 'radians') is export {
Expand All @@ -90,7 +91,7 @@ class Num is also {
$N1 = asin $N0
%r = box $N1
};
self!from-radians($r, $base)
$r!from-radians($base)
}
our Num multi method asinh($base = 'radians') is export {
Expand All @@ -103,7 +104,7 @@ class Num is also {
$N0 = ln $N0
%r = box $N0
};
self!from-radians($r, $base)
$r!from-radians($base)
}

our Num multi method atan($base = 'radians') is export {
Expand All @@ -112,7 +113,7 @@ class Num is also {
$N1 = atan $N0
%r = box $N1
};
self!from-radians($r, $base)
$r!from-radians($base)
}
our Num multi method atan2(Num $x = 1, $base = 'radians') is export {
Expand All @@ -123,7 +124,7 @@ class Num is also {
$N2 = atan $N0, $N1
%r = box $N2
};
self!from-radians($r, $base)
$r!from-radians($base)
}

our Num multi method atanh($base = 'radians') is export {
Expand All @@ -136,7 +137,7 @@ class Num is also {
$N0 /= 2
%r = box $N0
};
self!from-radians($r, $base)
$r!from-radians($base)
}
our Num multi method cos($base = 'radians') is export {
Expand Down

0 comments on commit 3afb78d

Please sign in to comment.