26 Jul 2022 15:03:37 UTC
- Distribution: Math-SlideRule
- Module version: 1.11
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (0)
- Testers (403 / 0 / 1)
- KwaliteeBus factor: 1
- 98.50% Coverage
- License: bsd
- Perl: v5.10.0
- Activity24 month
- Download (45.84KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This versionJMATES thrigand 1 contributors
- Jeremy Mates
- SEE ALSO
- LICENSE AND COPYRIGHT
Math::SlideRule - slide rule support for Perl
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);
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.
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.
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
distarrays, 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.
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.
Calls will throw an exception if something goes awry.
- divide n1, n2, ...
Divide the given numbers.
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.
If the bug is in the latest version, send a report to the author. Patches that fix problems or add new features are welcome.
Incomplete implementation, e.g. missing log, trig scales. Hilariously slow compared to just doing the math directly in Perl.
Math::Round for various rounding methods (and the usual disclaimers about floating point numbers that this module does use).
thrig - Jeremy Mates (cpan:JMATES)
<jmates at cpan.org>
Copyright Jeremy Mates
This program is distributed under the (Revised) BSD License: https://opensource.org/licenses/BSD-3-Clause
Module Install Instructions
To install Math::SlideRule, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Math::SlideRule
For more information on module installation, please visit the detailed CPAN module installation guide.