English     Español
[Main Index] : Programming : Languages : Perl : CPAN Modules : Data Type Utilities : Math
 Math::NoCarry CPAN (Perl) Module 

Search

 

Documents

Math::NoCarry - Perl extension for no carry arithmetic (Displayed)

Math::NoCarry - Perl extension for no carry arithmetic


NAME

Math::NoCarry - Perl extension for no carry arithmetic


SYNOPSIS

        use Math::NoCarry;
        my $sum        = Math::NoCarry::add( 123, 456 );
        my $difference = Math::NoCarry::subtract( 123, 456 );
        
        my $product    = Math::NoCarry::multiply( 123, 456 );
                
=head1 DESCRIPTION

No carry arithmetic doesn't allow you to carry digits to the next column. For example, if you add 8 and 4, you normally expect the answer to be 12, but that 1 digit is a carry. In no carry arithmetic you can't do that, so the sum of 8 and 4 is just 2. In effect, this is addition modulo 10 in each column. I discard all of the carry digits in this example:

          1234
        + 5678
        ------
          6802
          
For multiplication, the result of pair-wise multiplication
of digits is the modulo 10 value of their normal, everyday
multiplication.
        123
      x 456
      -----
          8   6 x 3 
         2    6 x 2
        6     6 x 1
        
         5    5 x 3
        0     5 x 2
       5      5 x 1
     
        2     4 x 3
       8      4 x 2
    + 4       4 x 1
    -------
      43878
    
Since multiplication and subtraction are actually types of
additions, you can multiply and subtract like this as well.

No carry arithmetic is both associative and commutative.


FUNCTIONS

This module does not export any functions.

multiply( A, B )
Returns the no carry product of A and B.

Return A if it is the only argument ( A x 1 );

add( A, B )
Returns the no carry sum of the positive numbers A and B.

Returns A if it is the only argument ( A + 0 )

Returns undef or the empty list if either number is negative.

add( A, B )
Returns the no carry difference of the postive numbers A and B.

Returns A if it is the only argument ( A - 0 )

Returns undef or the empty list if either number is negative.


BUGS

* none reported yet :)


TO DO

* this could be a full object package with overloaded +, *, and - operators

* it would be nice if i could give the functions more than two arguments.

* addition and subtraction don't do negative numbers.


AUTHOR

brian d foy, <bdfoy@cpan.org>


COPYRIGHT

Copyright 2002, brian d foy, All Rights Reserved.

You may redistribute this under the same terms as Perl itself.

Information

This site is currently in testing, it is not yet operating using the full database. Until it is officially launched you may wish to visit Help-Site Computer Manuals. After launch, this site (HelpSpy) will replace Help-Site. Information about the spider which is currently trawling the Internet looking for links to add to this directory can be found here.
   

©Copyright Nicholas Reynolds 2004