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

This is a few generic helper functions for paths based on digits or powering.

They're designed to work on plain Perl integers and floats and there's some special case support for Math::BigInt.

EXPORTS

Nothing is exported by default but each function below can be as in the usual Exporter style,

use Math::PlanePath::Base::Digits 'round_down_pow';

FUNCTIONS

Generic

($power, $exponent) = round_down_pow ($n, $radix)

Return the power of $radix which is at or less than $n. For example

($pow, $exp) = round_down_pow (260, 2);
# $pow==256  # the next lower power
# $exp==8    # the exponent in that power
# since 2**8=256 is next below 260
@digits = digit_split_lowtohigh ($n, $radix)

Return a list of digits from $n in base $radix. For example,

@digits = digit_split_lowtohigh (12345, 10);
# @digits = (5,4,3,2,1)   # decimal digits low to high

If $n==0 then the return is an empty list. For the current code $n should be >=0.

"lowtohigh" in the name tries to make it clear which way the digits are returned. A reverse can be used to get high to low instead ("reverse" in perlfunc).

Subclassing

$aref = parameter_info_array()

Return an arrayref of a radix parameter. This is designed to be imported into a PlanePath subclass for use as its parameter_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()

Return the single radix parameter hashref from the info above. This can be used when a subclass wants the radix parameter and other parameters too,

package Math::PlanePath::MySubclass;
use constant parameter_info_array =>
  [
   { name            => 'somethig_else',
     type            => 'integer',
     default         => '123',
   },
   Math::PlanePath::Base::Digits::parameter_info_radix2(),
  ];

If a specific or more detailed "description" part is wanted then it could be overridden with for example

{ %{Math::PlanePath::Base::Digits::parameter_info_radix2()},
  description => 'Radix, for both something and something.',
},

SEE ALSO

Math::PlanePath

Math::BigInt

HOME PAGE

http://user42.tuxfamily.org/math-planepath/index.html

LICENSE

Copyright 2010, 2011, 2012 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/>.