Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created February 18, 2010 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnthn/307599 to your computer and use it in GitHub Desktop.
Save jnthn/307599 to your computer and use it in GitHub Desktop.
diff --git a/src/core/Any-num.pm b/src/core/Any-num.pm
index 66c99ab..6cd9022 100644
--- a/src/core/Any-num.pm
+++ b/src/core/Any-num.pm
@@ -41,23 +41,21 @@ augment class Any {
# Used by the :Trig subs and methods in the Int and Num classes.
our multi method !to-radians($base) {
- given $base {
- when /:i degrees/ { self * (312689/99532)/180.0 } # Convert from degrees.
- when /:i gradians/ { self * (312689/99532)/200.0 } # Convert from gradians.
- when /:i radians/ { self + 0 } # Convert from radians.
- when Num { self * 2.0 * (312689/99532) } # Convert from revolutions.
- default { die "Unable to convert to base: $base" }
- }
+ my $base-lc = $base.lc;
+ $base-lc eq 'degrees' ?? (self * (312689/99532)/180.0) !! # Convert from degrees.
+ $base-lc eq 'gradians' ?? (self * (312689/99532)/200.0) !! # Convert from gradians.
+ $base-lc eq 'radians' ?? (self + 0) !! # Convert from radians.
+ $base ~~ Num ?? (self * 2.0 * (312689/99532)) !! # Convert from revolutions.
+ die "Unable to convert to base: $base";
}
our multi method !from-radians($base) {
- given $base {
- when /:i degrees/ { self * 180/(312689/99532) } # Convert to degrees.
- when /:i gradians/ { self * 200/(312689/99532) } # Convert to gradians.
- when /:i radians/ { self + 0 } # Convert to radians.
- when Num { self /(2 * (312689/99532)) } # Convert to revolutions.
- default { die "Unable to convert to base: $base" }
- }
+ my $base-lc = $base.lc;
+ $base-lc eq 'degrees' ?? (self * 180/(312689/99532)) !! # Convert to degrees.
+ $base-lc eq 'gradians' ?? (self * 200/(312689/99532)) !! # Convert to gradians.
+ $base-lc eq 'radians' ?? (self + 0) !! # Convert to radians.
+ $base ~~ Num ?? (self /(2 * (312689/99532))) !! # Convert to revolutions.
+ die "Unable to convert to base: $base";
}
multi method log() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment