Arithmetic-PaperAndPencil
view release on metacpan or search on metacpan
lib/Arithmetic/PaperAndPencil.pm view on Meta::CPAN
open $fh, '>', 'addition.html' or die "opening file $!";
print $fh $html;
close $fh or die "closing file $!";
The first HTML file ends with
355000000|113
0160 |---
0470 |3141592
0180 |
0670 |
1050 |
0330|
104|
and the second one with
DEAD
BEEF
-----
19D9C
=head1 DESCRIPTION
Arithmetic::PaperAndPencil is a module which allows simulating the
paper and pencil techniques for basic arithmetic operations on
integers: addition, subtraction, multiplication and division, but also
square root extraction and conversion from a radix to another.
An object from the C<Arithmetic::PaperAndPencil> class is called
"paper sheet", because it represents a paper sheet on which the
simulated human scribbles his computations. In some cases, the human
would use a wad of sheets instead of a single sheet. This is simulated
in the module, but we still call the object a "paper sheet".
=head2 Problems, known bugs and acceptable breaks from reality
Most humans can only compute in radix 10. Some persons have a
theoretical knowledge of numeric bases other than 10, and a limited
practical skill of using radix 2, radix 8 and radix 16. The module
uses any radix from 2 to 36, without difference.
The module can use numbers of any length. Human beings will not be
able to multiply two 100-digit numbers. Or if they try, they will
spend much effort and the result may be wrong. The module can easily
multiply two 100-digit numbers. The output may be lengthy and boring,
but it will be correct.
Humans can detect situations where the computation procedure can be
amended, such as a multiplication where the multiplicand and the
multiplier contain many "0" digits. The module does not detect these
cases and still uses the unaltered computation procedure.
Human beings write their calculations on A4 paper (21 cm à 29,7 cm) or
letter paper (21,6 cm à 27,9 cm). The module writes its calculations
on unlimited sheets of paper. If you want to compute the product of
two 1000-digit numbers, the multiplication will have a 2000-char width
and a 1000-line height and still be on a single sheet of paper.
If you ask for the operations with the "talking" formulas, most of
these formulas are the traditional sentences which accompanies the
writing of the computation. But in some cases, the module displays a
non-standard sentence, to explain better what is happening.
=head1 EXPORT
None.
=head1 UTILITY METHODS
=head2 new
Creates an empty paper sheet. Or removes the content of an already
existing paper sheet.
=head2 from_csv
Creates a paper sheet containing the operations listed in the
parameter CSV string.
=head2 csv
Generates a string with a CSV format and listing all operations stored
in the sheet object. The opposite of C<from_csv>. This string can be
printed into a CSV file for later retrieval.
=head2 html
Generates a string using the HTML format.
For a properly formatted HTML file, the module user should provide the
beginning of the file, from the C<< <html> >> tag until the C<< <body>
>> tag, and then the end of the file, with the C<< </body></html> >>
tags.
The parameters are the following:
=over 4
=item * C<lang>
The language for the titles and messages. The C<"fr"> language is
fully specified, and the C<"en"> language is still incomplete. For the
moment, there are no other languages.
=item * C<silent>
Boolean parameter controlling the display of the "spoken" messages. If
C<1>, only the titles are displayed. It C<0>, all messages are
displayed.
=item * C<level>
Integer parameter controlling the display of partial operations. If
C<0>, only the final complete operation is shown. If C<1>, each sheet
is displayed upon switching to another sheet (when using a wad of
sheets). If C<2> or more, partial operations are displayed. The higher
the parameter, the more often the partial operations are displayed.
=item * C<css>
( run in 1.853 second using v1.01-cache-2.11-cpan-22024b96cdf )