App-PerlCalc
view release on metacpan or search on metacpan
#!/usr/bin/perl
# Copyright (c) 2003-2009 David Caldwell -*- cperl -*-
use strict;
use warnings;
sub revstr($) { join "", reverse split //, $_[0] } # Reverse the characters in a string.
sub comma($$) { revstr join(",", unpack("(A$_[1])*", revstr($_[0]))) }
sub compute ($) {
$_[0] =~ s/\b([\d.]+)([kmgtpezyKMGTPEZY])[bB]?/($1*1024**(index("kmgtpezy",lc "$2")+1))/g;
my $a = eval($_[0]); die unless defined $a;
my $i = eval("use bigint; $_[0];"); $i = $a unless defined $i;
my $n = eval("use bignum; $_[0];"); $n = $a unless defined $n;
my $r = eval("use bigrat; $_[0];"); $r = $a unless defined $r;
my $is = "";
eval { $is = $i->copy()->bfloor().""; };
$is = int $i if $@;
( run in 0.591 second using v1.01-cache-2.11-cpan-65fba6d93b7 )