.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Math::NoCarry 3pm" .TH Math::NoCarry 3pm "2018-06-23" "perl v5.26.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Math::NoCarry \- Perl extension for no\- carry arithmetic .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Math::NoCarry qw(:all); \& \& my $sum = add( 123, 456 ); \& \& my $difference = subtract( 123, 456 ); \& \& my $product = multiply( 123, 456 ); .Ve .SH "DESCRIPTION" .IX Header "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: .PP .Vb 4 \& 1234 \& + 5678 \& \-\-\-\-\-\- \& 6802 .Ve .PP For multiplication, the result of pair-wise multiplication of digits is the modulo 10 value of their normal, everyday multiplication. .PP .Vb 6 \& 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 .Ve .PP Since multiplication and subtraction are actually types of additions, you can multiply and subtract like this as well. .PP No carry arithmetic is both associative and commutative. .SS "Functions" .IX Subsection "Functions" As of version 1.11, all of these functions are exportable on demand, or with the tag \f(CW\*(C`:all\*(C'\fR to get them all at once. .IP "multiply( A, B )" 4 .IX Item "multiply( A, B )" Returns the no carry product of A and B. .Sp Return A if it is the only argument ( A x 1 ); .IP "add( A, B )" 4 .IX Item "add( A, B )" Returns the no carry sum of the positive numbers A and B. .Sp Returns A if it is the only argument ( A + 0 ) .Sp Returns false if either number is negative. .IP "subtract( A, B )" 4 .IX Item "subtract( A, B )" Returns the no carry difference of the positive numbers A and B. .Sp Returns A if it is the only argument ( A \- 0 ) .Sp Returns false if either number is negative. .SH "BUGS" .IX Header "BUGS" * none reported yet :) .SH "TO DO" .IX Header "TO DO" * this could be a full object package with overloaded +, *, and \- operators .PP * it would be nice if I could give the functions more than two arguments. .PP * addition and subtraction don't do negative numbers. .SH "SOURCE AVAILABILITY" .IX Header "SOURCE AVAILABILITY" This source is in GitHub: .PP .Vb 1 \& https://github.com/briandfoy/math\-nocarry .Ve .SH "AUTHOR" .IX Header "AUTHOR" brian d foy, \f(CW\*(C`\*(C'\fR .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright © 2002\-2018, brian d foy . All rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.