The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Math::SlideRule - slide rule support for Perl

SYNOPSIS

Simulate an analog computer.

  use Math::SlideRule;

  my $sr = Math::SlideRule->new();

  # scientific notation breakdown (discards sign)
  $sr->standard_form(-1234); # [ 1.234, 3, 1 ]

  # these use the "C/D" scales, or values from 1..10 with some
  # degree of precision
  $sr->divide(75, 92);
  $sr->multiply(1.5, 3.7);
  $sr->multiply(-1.1, 2.2, -3.3, 4.4);

  # this uses an A/B to C/D scale conversion
  $sr->sqrt(42);

DESCRIPTION

Slide rule support for Perl. Or, a complicated way to perform basic mathematical operations on a digital computer. Math::SlideRule::PickettPocket approximates a N 3P-ES pocket slide rule.

ATTRIBUTES

Scales and settings related to the generation of such. The scales are not scaled to one another as they are on a slide rule, so relations between A and C will require appropriate math.

A

Double decade scale from 1..100. Used by sqrt in conjunction with C scale. Weighted towards the low end, so has greater precision near 1 than at 100. Overall precision may be set by the precision attribute only when the object is constructed.

Internally, a hash reference of value and dist arrays, where the index of a particular value corresponds to a particular logarithmic distance. The internal _rank method is used to find the index of a particular value or distance in these arrays.

C

Scale from 1..10. Used by multiply and divide. Weighted towards the low end.

precision num

How precise the scales should be, 10000 by default over the range of the scale. Higher precision entails increased memory use for the resulting scale structures. Changing this on the fly is not supported.

METHODS

Calls will throw an exception if something goes awry.

divide n1, n2, ...

Divide the given numbers.

new

Constructor. Optionally can be given a custom precision attribute.

multiply n1, n2, ...

Multiply the given numbers.

  $sr->multiply(2, 3);    # 6 (or so)
  $sr->multiply(2..5);    # 120 (ish)
sqrt num

Take the square root of the given number.

standard_form num, [ min, max ]

This method returns a number as a list consisting of the characteristic, exponent, and whether the number is negative or not. Used internally by various methods.

  $sr->standard_form(5550)    # 5.55, 3, 0
  $sr->standard_form(-640)    # 6.4,  2, 1

The optional min and max values allow for a normal form between values besides the defaults of 1 and 10, though using a minimum value below 1 may result in unexpected or undefined results, elsewhere.

_rank value, listofvalues

Internal use only. Performs a binary search for a given value within an array reference of values. standard_form or such should be used to ensure that the value lies within the limits of the given list of values. The values usually will come from the letter attribute routines that tie various numerals to given logarithmic distances.

BUGS

Reporting Bugs

If the bug is in the latest version, send a report to the author. Patches that fix problems or add new features are welcome.

https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Math-SlideRule

https://github.com/thrig/Math-SlideRule

Known Issues

Incomplete implementation, e.g. missing log, trig scales. Hilariously slow compared to just doing the math directly in Perl.

SEE ALSO

Math::Round for various rounding methods (and the usual disclaimers about floating point numbers that this module does use).

AUTHOR

thrig - Jeremy Mates (cpan:JMATES) <jmates at cpan.org>

LICENSE AND COPYRIGHT

Copyright Jeremy Mates

This program is distributed under the (Revised) BSD License: https://opensource.org/licenses/BSD-3-Clause