C


Enter formula/string to calculate. example; 1+3



Died at /www/cgi/calc2.pl line 59, line 1.
__END__ =head1 NAME PC - A simple but feature filled command line Perl calculator =head1 SYNOPSIS pc 11+3 =head1 DESCRIPTION C is a quick and dirty command line perl calculator. Pass it an expression on the command line and it will print the result in a number of different formats. You can also run C with no command line parameters and it will run an interactive loop (using C> if you have it installed). C is designed to give you all the output you ever could want without having to memorize any stupid command line switches. There are none, in fact. It also doesn't overload you with redundant data. If the floating point answer is the same as the integer answer then it doesn't show it to you. Same with the fractions. =head1 TUTORIAL =head2 The basics 11+3 14 0xe 016 The first number is the math string, followed by the reversed result then hex and octal and integer and ord and binary representations. Simple enough. =head2 Order of operations This shows that C uses Perl's order of operations (operator precedence if you are in a programming mood): 1+3*2 7 0x7 07 =head2 ASCII 1+3*20 61 0x3d 075 '=' Here we see an extra field was printed. In this case C detected the final integer value was in the ASCII range and printed the character represented by the value 61, an equal sign. =head2 Bitwise Operations We also get Perl (and C) style bitwise operators: 1+3*20<<2 244 0xf4 0364 =head2 Floating point Of course it's not restricted to only integers, it can handle floats too: 1+3*20/55 2 0x2 02 2.0909090909090 23/11 You'll notice it shows the result of the floating point math in addition to the integer math. =head2 Fractions You might have noticed a fraction in the output of the previous example. C uses Perl's "bigrat" library to do fractions: 3/4+1/2 0 0x0 01 1.25 5/4 =head2 Human readable 1000*2000 2,000,000 2000000 0x1e,8480 0x1e8480 07502200 1.90MB You'll notice that the integer and hex results are printed twice--one with commas and one without. The one with commas is so that you the human can read the output easily. The one without commas is for copying and pasting. You should also notice that C helpfully told you the number was 1.90MB. If a number is bigger than 1024 (1KB) it will print it in human readable byte quantity. =head2 Power of 2 magnitude suffixes It also accepts magnitude suffixes on the input: 16m 16,777,216 16777216 0x100,0000 0x1000000 0100000000 16MB The following suffixes are allowed: kmgtpezy (lower or upper case, with or without a trailing "b"). Note that the human readable output "16MB" doesn't have a decimal point. It will remove the decimal point if the number is exactly that value. So: 16m+1 16,777,217 16777217 0x100,0001 0x1000001 0100000001 16.0MB Since "16.0MB" has a decimal point, we know the value isn't exactly 16 megabytes. =head2 Large numbers C uses Perl's bigint so that it can handle numbers bigger than 32 bits: 1<<40 1,099,511,627,776 1099511627776 0x100,0000,0000 0x10000000000 020000000000000 1TB =head2 Trancendental and trignomentric functions C gives you access to all the Perl math functions: sin(3.141592) ** .5 1 0x1 0 0.0008084490047 1 =head2 Random Perl code ord("a") 0x61 0141 97 'a' =head1 SEE ALSO L =head1 COPYRIGHT This library is free software; you can redistribute it and/or modify it under the same terms as perl itself. Copyright (C) 2003-2009 David Caldwell =head1 AUTHOR David Caldwell Updated for the cloud by Gerald Krug =cut