Permalink
Browse files

Use native types in ymd-from-daycount, shaving ~7% off masak++'s exam…

…ple.
  • Loading branch information...
1 parent f5da44b commit 5dbca1f5a8e0b2e49f25538ed0d111d5c4287bc4 @jnthn jnthn committed Jan 20, 2012
Showing with 10 additions and 10 deletions.
  1. +10 −10 src/core/Temporal.pm
View
20 src/core/Temporal.pm
@@ -28,18 +28,18 @@ my role Dateish {
method ymd-from-daycount($daycount) {
# taken from <http://www.merlyn.demon.co.uk/daycount.htm>
- my $day = $daycount.Int + 678881;
- my $t = (4 * ($day + 36525)) div 146097 - 1;
- my $year = 100 * $t;
- $day -= 36524 * $t + ($t +> 2);
+ my int $day = $daycount.Int + 678881;
+ my int $t = (4 * ($day + 36525)) div 146097 - 1;
+ my int $year = 100 * $t;
+ $day = $day - (36524 * $t + ($t +> 2));
$t = (4 * ($day + 366)) div 1461 - 1;
- $year += $t;
- $day -= 365 * $t + ($t +> 2);
- my $month = (5 * $day + 2) div 153;
- $day -= (2 + $month * 153) div 5 - 1;
+ $year = $year + $t;
+ $day = $day - (365 * $t + ($t +> 2));
+ my int $month = (5 * $day + 2) div 153;
+ $day = $day - ((2 + $month * 153) div 5 - 1);
if ($month > 9) {
- $month -= 12;
- $year++;
+ $month = $month - 12;
+ $year = $year + 1;
}
($year, $month + 3, $day)
}

0 comments on commit 5dbca1f

Please sign in to comment.