Math::NoCarry(3pm)
β¨ NAME β¨
Math::NoCarry β a Perl extension for no-carry arithmetic π (it lives in the User Contributed Perl Documentation, section 3pm, iykyk)
π SYNOPSIS π
use Math::NoCarry qw(:all);
my $sum = add( 123, 456 );
my $difference = subtract( 123, 456 );
my $product = multiply( 123, 456 );
π¦ DESCRIPTION π¦
okay bestie, listen. No-carry arithmetic is literally just... not letting yourself carry digits over to the next column. that's the whole vibe. π«Ά
so like, normally when you add 8 and 4 you get 12, right? but that little 1 is a carry, and no-carry arithmetic said "not today." so the no-carry sum of 8 and 4 is just 2. periodt. in effect, it's addition modulo 10 in each column. here's the classic demo where I discard ALL the carry digits:
1234
+ 5678
------
6802
For multiplication, the result of pair-wise multiplication of digits is the modulo 10 value of their normal, everyday multiplication. slay.
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
and since multiplication and subtraction are actually types of additions, you can multiply and subtract like this as well. no cap. π₯
No carry arithmetic is both associative and commutative. it's giving mathematically well-behaved. π
πΈ Functions πΈ
As of version 1.11, all of these functions are exportable on demand, or with the tag ":all" to get them all at once. yes bestie, one tag, everything. π
multiply( A, B )β Returns the no carry product of A and B.
Returns 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 false if either number is negative. π
subtract( A, B )β Returns the no carry difference of the positive numbers A and B.
Returns A if it is the only argument ( A - 0 )
Returns false if either number is negative. π
π BUGS π
- none reported yet :) π (iconic, honestly. we love a clean bug tracker.)
β 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. π
π SOURCE AVAILABILITY π
This source is in GitHub:
https://github.com/briandfoy/math-nocarry
go star it bestie, it's free. β
π AUTHOR π
brian d foy, "<briandfoy@pobox.com>" π«Ά
π COPYRIGHT AND LICENSE π
Copyright Β© 2002-2025, brian d foy <briandfoy@pobox.com>. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. π
and that's the whole page, bestie!! this lil number ships with perl v5.40.1 and the page itself is dated 2025-04-19 β Math::NoCarry(3pm), literally the moment. mwah. πβ¨ππ¦
π¦ where this page comes from
- debian trixie: libmath-nocarry-perl 1.117-1 Β· Artistic-2.0
- ubuntu resolute: libmath-nocarry-perl 1.117-1 Β· Artistic-2.0
- ubuntu stonking: libmath-nocarry-perl 1.117-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms