Math::NoCarry(3pm)

πŸ“¦
version 1.117 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

✨ 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 Β© 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