Arithmetic-PaperAndPencil
view release on metacpan or search on metacpan
lib/Arithmetic/PaperAndPencil.pm view on Meta::CPAN
This string parameter can be either C<"quotient"> (default value) or
C<"remainder">, or C<"both">. It controls which value is (are)
returned by the method to the main programme.
=item * C<mult-and-sub>
This string parameter can be either C<"combined"> (default value) or
C<"separate">. It controls the computation of the successive partial
remainders with a multiplication (quotient digit times full divisor)
and a subtraction (from the partial dividend). If C<"combined">, the
multiplication and the subtraction are done at the same time, digit
per digit. If C<"separate">, the multiplication is done first in full,
then the subtraction is done.
=back
The various types are
=over 4
=item * C<std>
The standard division.
=item * C<cheating>
This is the standard division with a twist. The standard division is
usually a trial-and-error process in which several candidate digits
are tried for each quotient digit. With this technique, the
trial-and-error process is cut short and only the successful digit is
tried.
Acceptable break from reality: This is not a real method, this is a
convenience method which gives shorter HTML files than what the
C<"std"> type generates.
=item * C<prepared>
Before starting the division, the module computes the partial products
of the divisor with any single-digit number. These when computing the
intermediate remainders, instead of doing a multiplication -
subtraction combination, the already known partial product is simply
copied from the preparation list then subtracted from the previous
intermediate remainder. The C<mult-and-sub> parameter defaults to
C<"separate"> for this division type.
=item * C<boat>
The dividend is written above an horizontal line. The divisor is
written below this line. As the first partial remainder is computed,
the used digits of the dividend and divisor are stricken and the
digits of the partial remainder are written above the digits of the
dividend. When computing the next digits, the divisor is rewritten and
the computation of the next partial remainder again strikes the digits
of the first partial remainder and of the second occurrence of the
divider.
Acceptable break from reality: I have not found anywhere an
explanation for this technique. The way it is implemented is just some
guesswork after some reverse engineering attempt on a few examples. A
special point is that it seems to require something similar to the
C<cheating> technique above, because I do not see how we can
"unstrike" the digits that were stricken with the previous digit
candidate.
=back
=head2 square_root
Simulates the extraction of the square root of a number. There is a
single positional parameter, an instance of the
C<Arithmetic::PaperAndPencil::Number> class.
There is an optional keyword parameter, C<mult-and-sub>. Its purpose
is the same as for division. If set to C<'combined'> (default value),
the computing of the product (candidate digit times divisor) is
combined with the subtraction from the partial dividend. If set to
C<'separate'>, the multiplication and the subtraction are executed in
separate and successive phases.
=head2 conversion
Simulates the conversion of a number from its current radix to a new
radix.
The parameters are:
=over 4
=item * C<number>
The number to convert, instance of C<Arithmetic::PaperAndPencil::Number>.
=item * C<radix>
The destination radix for the conversion. This is a native integer,
not an instance of C<Arithmetic::PaperAndPencil::Number>.
=item * C<nb-op>
The number of operations on a single page. After this number is
reached, a new page is generated. This allows keeping the complete
operation sufficiently short. This parameter is a native integer. If
zero (default value), no new pages are generated.
=item * C<type>
A string parameter specifying which algorithm is used to convert a
number. Values C<'mult'> and C<'Horner'> are synonymous and use the
cascading multiplication algorithm (or Horner scheme). Value C<'div'>
uses the cascading division algorithm.
=item * C<div-type>
A string parameter specifying which kind of division is used: C<'std'>
(default value) uses a standard division with a full trial-and-error
processing for candidate quotient digits, C<'cheating'> uses a
standard division in which the trial-and-error of candidate quotient
digits is artificially reduced to a single iteration, C<'prepared'>
first computes the list of multiples for the target radix and uses it
( run in 2.572 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )