DateTime Archives

Happy Pi Day!

Did you know that 22/7 is actually a better approximation of pi than 3.14 is?

use DateTime;
use Math::Trig qw(pi);
use Test::More tests => 1;

my $today = DateTime::->now;
my $dm    = sprintf '%d/%d' => ($today->day, $today->month);

cmp_ok(
	abs( eval($dm) - pi ),
	'<',
	0.0015,
)
or diag("this test only passes on 22/7")

About Toby Inkster

user-pic I'm tobyink on CPAN, IRC and PerlMonks.