Math::...:Digits(3pm)
π Math::...:Digits(3pm) π
okay bestie, so this is a page from the User Contributed Perl Documentation collection, and the actual star of the show is Math::PlanePath::Base::Digits β lowercase in the real name, the header's just doing its lil abbreviated thing π
β¨ NAME β¨
Math::PlanePath::Base::Digits β helpers for digit based paths π¦
β¨ SYNOPSIS β¨
use Math::PlanePath::Base::Digits 'digit_split_lowtohigh';
foreach my $digit (digit_split_lowtohigh ($n, 16)) {
}
β¨ DESCRIPTION β¨
So this is a lil grab-bag of generic helper functions for paths that are built on digits or on powering π₯
They're designed to work on plain Perl integers and floats, and there's also some special case support for Math::BigInt in there π«Ά
β¨ EXPORTS β¨
ngl, nothing is exported by default π but every function down below can be grabbed the usual Exporter style way, like:
use Math::PlanePath::Base::Digits 'round_down_pow';
(But not parameter_info_radix2(), and the reason why is explained further down π)
β¨ FUNCTIONS β¨
πΈ Generic πΈ
($power, $exponent) = round_up_pow ($n, $radix)($power, $exponent) = round_down_pow ($n, $radix)β returns the power of$radixthat's equal to$n, or either higher or lower than it, depending. For example:
($pow, $exp) = round_down_pow (260, 2);
# $pow==512 # the next higher power
# $exp==9 # the exponent in that power
# 2**9=512 is next above 260
($pow, $exp) = round_down_pow (260, 2);
# $pow==256 # the next lower power
# $exp==8 # the exponent in that power
# 2**8=256 is next below 260
@digits = digit_split_lowtohigh ($n, $radix)@bits = bit_split_lowtohigh ($n)β returns a list of digits from$nin base$radix, or in binary. For example:
@digits = digit_split_lowtohigh (12345, 10);
# @digits = (5,4,3,2,1) # decimal digits low to high
If $n==0 then what you get back is an empty list. The current code expects $n >= 0 β¨
The lowtohigh in the name is there to make it super clear which direction the digits come back in. You can hit it with reverse() to get high to low instead (see "reverse" in perlfunc).
bit_split_lowtohigh() is literally just digit_split_lowtohigh() called with radix=2, no cap π§’
$n = digit_join_lowtohigh ($arrayref, $radix)$n = digit_join_lowtohigh ($arrayref, $radix, $zero)β returns a value made by joining digits from$arrayrefin base$radix. For example:
@digits = (5,4,3,2,1) # decimal digits low to high
$n = digit_split_lowtohigh (\@digits, 10);
# $n == 12345
The optional $zero can be a 0 of an overloaded number type such as Math::BigInt, which makes the returned $n be of that type π
π Subclassing π
$aref = parameter_info_array()β returns an arrayref with aradixparameter, default 2. This is designed to be imported into a PlanePath subclass so it becomes that subclass'sparameter_info_array()method π
package Math::PlanePath::MySubclass;
use Math::PlanePath::Base::Digits 'parameter_info_array';
The arrayref is:
[ { name => 'radix',
share_key => 'radix_2',
display => 'Radix',
type => 'integer',
minimum => 2,
default => 2,
width => 3,
description => 'Radix (number base).',
}
]
$href = Math::PlanePath::Base::Digits::parameter_info_radix2()β returns the singleradixparameter hashref from the info right above βοΈ This one's for when a subclass wants the radix parameter and other parameters too:
package Math::PlanePath::MySubclass;
use constant parameter_info_array =>
[
{ name => 'something_else',
type => 'integer',
default => '123',
},
Math::PlanePath::Base::Digits::parameter_info_radix2(),
];
If the description part needs to be more specific or more detailed, you can override it, like for example:
{ %{Math::PlanePath::Base::Digits::parameter_info_radix2()},
description => 'Radix, for both something and something.',
},
π this function is not exportable! It's meant for a one-off call in an initializer, so there's genuinely no need to import it for repeated use. periodt.
β¨ SEE ALSO β¨
Math::PlanePath, Math::PlanePath::Base::Generic
Math::BigInt
β¨ HOME PAGE β¨
<http://user42.tuxfamily.org/math-planepath/index.html>
β¨ LICENSE β¨
Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Kevin Ryde
This file is part of Math-PlanePath.
Math-PlanePath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-PlanePath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
and that's the whole page bestie!! π this lil writeup shipped with perl v5.32.0 and got dated 2021-01-23, so if you're reading this, tell the calendar it ate π β¨
π¦ where this page comes from
- debian bookworm: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- debian trixie: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu jammy: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu noble: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu resolute: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu stonking: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms