NAME
Math - constants and functions
SYNOPSIS
use Math ':all';
printf "2.71828182845905 = %s\n", E;
printf "1.5707963267949 = %s\n", PI1_2;
printf "1 = %s\n", round(0.5);
printf "1 = %s\n", ceil(0.5);
printf "0 = %s\n", floor(0.5);
or
use Math;
printf "%s\n", Math::PI;
printf "%s\n", Math::round(0.5);
SEE ALSO
perlfunc Perl built-in functions
PDL for scientific and bulk numeric data processing and display
Math::Complex, Math::Trig, Math::Quaternion, Math::Vectors
Constants
E
Euler's constant, e, approximately 2.718
LN10
Natural logarithm of 10, approximately 2.302
LN2
Natural logarithm of 2, approximately 0.693
PI
Ratio of the circumference of a circle to its diameter, approximately 3.1415 or atan2( 0, -1 ).
PI1_2 == PI * 1/2
SQRT1_2
square root of 1/2, approximately 0.707
SQRT2
square root of 2, approximately 1.414
Functions
Note number, number1, number2, base, and exponent indicate any expression with a scalar value.
abs(number)
Returns the absolute value of number
acos(number)
Returns the arc cosine (in radians) of number
asin(number)
Returns the arc sine (in radians) of number
atan(number)
Returns the arc tangent (in radians) of number
atan2(number1, number2)
perls atan2
ceil(number)
Returns the least integer greater than or equal to number
cos(number)
Returns the cosine of number where number is expressed in radians
exp(number)
Returns e, to the power of number (i.e. enumber)
even(number)
Returns 1 if number is even otherwise 0
floor(number)
Returns the greatest integer less than or equal to its argument
fmod(number, number)
POSIX fmod
log(number)
Returns the natural logarithm (base e) of number
log10(number)
Returns the logarithm (base 10) of number
min(number1, number2)
Returns the lesser of number1 and number2
max(number1, number2)
Returns the greater of number1 and number2
clamp(number, min, max)
Returns number between or equal min and max
odd(number)
Returns 1 if number is odd otherwise 0
pro(number, number1, number2, ...)
Returns the product of its arguments
pro(1,2,3) == 1 * 2 * 3;
my $product = pro(@array);
pow
Computes $x raised to the power $exponent .
$ret = POSIX::pow( $x, $exponent );
You can also use the ** operator, see perlop.
random
Returns a pseudo-random number between 0 and 1.
$ret = Math::random();
Returns a pseudo-random number between 0 and $number1.
$ret = Math::random($number1);
Returns a pseudo-random number between number1 and number2.
$ret = Math::random($number1, $number2);
round
Returns the value of $number rounded to the nearest integer
$ret = Math::round($number);
Returns the value of $number rounded to the nearest float point number.
$ret = round($number, $digits);
round(0.123456, 2) == 0.12;
round(50, -2) == 100;
round(5, -1) == 10;
round(0.5) == 1;
round(0.05, 1) == 0.1;
round(0.005, 2) == 0.01;
sig(number)
Returns 1 if number is greater 0.
Returns -1 if number is lesser 0 otherwise -1.
sin(number)
Returns the sine of number where number is expressed in radians
sqrt(number)
Returns the square root of its argument
sum(number, number1, number2, ...)
Returns the sum of its arguments
sum(1..3) == 1 + 2 + 3;
my $sum = sum(@array);
tan(number)
Returns the tangent of number, where number is expressed in radians
x(number, base=10)
Returns the digital_root of number to base
MODULES
Algebra
Algorithms
Math::Calc::Units::Convert::Base
Math::Calc::Units::Convert::Base2Metric
Math::Calc::Units::Convert::Byte
Math::Calc::Units::Convert::Combo
Math::Calc::Units::Convert::Date
Math::Calc::Units::Convert::Distance
Math::Calc::Units::Convert::Metric
Math::Calc::Units::Convert::Multi
Math::Calc::Units::Convert::Time
Math::Calculus::TaylorEquivalent
Complex
Expression
Fourier
Fractal
Math::Fractal::DLA::Race2Center
Math::Fractal::DLA::Surrounding
Geometry
Math::Geometry::Planar::GPC::Inherit
Math::Geometry::Planar::GPC::Polygon
Math::Geometry::Planar::Offset
Math::GrahamFunction::SqFacts::Dipole
Integral
Math::Intersection::StraightLine
Logic
Matrix
Numbers
Math::PartialOrder::LRUCaching
Polynom
Random
Simple
String
Math::String::Charset::Grouped
Math::String::Charset::Wordlist
Symbolic
Math::Symbolic::Custom::CCompiler
Math::Symbolic::Custom::Contains
Math::Symbolic::Custom::DefaultDumpers
Math::Symbolic::Custom::DefaultMods
Math::Symbolic::Custom::DefaultTests
Math::Symbolic::Custom::ErrorPropagation
Math::Symbolic::Custom::LaTeXDumper
Math::Symbolic::Custom::Pattern
Math::Symbolic::Custom::Pattern::Export
Math::Symbolic::Custom::Simplification
Math::Symbolic::Custom::Transformation
Math::Symbolic::Custom::Transformation::Group
Math::Symbolic::ExportConstants
Math::Symbolic::Parser::Precompiled
Math::Symbolic::VectorCalculus
Math::SymbolicX::Calculator::Command
Math::SymbolicX::Calculator::Command::Assignment
Math::SymbolicX::Calculator::Command::DerivativeApplication
Math::SymbolicX::Calculator::Command::Insertion
Math::SymbolicX::Calculator::Command::Transformation
Math::SymbolicX::Calculator::Interface
Math::SymbolicX::Calculator::Interface::Shell
Math::SymbolicX::Calculator::Interface::Web
Math::SymbolicX::Calculator::Interface::Web::Server
Math::SymbolicX::NoSimplification
Math::SymbolicX::ParserExtensionFactory
Math::SymbolicX::Statistics::Distributions
Taylor
Trig
Vector
ematica
SEE ALSO
perlfunc Perl built-in functions
PDL for scientific and bulk numeric data processing and display
Math::Complex, Math::Trig, Math::Quaternion, Math::Vectors
BUGS & SUGGESTIONS
If you run into a miscalculation, need some sort of feature or an additional holiday, or if you know of any new changes to the funky math, please drop the author a note.
ARRANGED BY
Holger Seelig holger.seelig@yahoo.de
COPYRIGHT
This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.