1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
########################################################################
#
# maths 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#
########################################################################
#
# Project : File Preprocessor - maths module
# Filename : $RCSfile: maths.pm,v $
# Author : $Author: darren $
# Maintainer : Darren Miller: darren@cabaret.demon.co.uk
# File version : $Revision: 1.3 $
# Last changed : $Date: 2001/09/04 22:21:58 $
# Description : This implements simple maths routines
# Licence : GNU copyleft
#
########################################################################
# THIS IS A FILEPP MODULE, YOU NEED FILEPP TO USE IT!!!
# usage: filepp -m maths.pm <files>
########################################################################
package Maths;
use strict;
# version number of module
my $VERSION = '1.0.0';
require "function.pm";
########################################################################
# Define Pi as M_PI
########################################################################
Filepp::Define("M_PI 3.14159265358979323846");
Filepp::Define("M_E 2.7182818284590452354");
########################################################################
# Add all input, usage: - ANY NUMBER OF INPUTS
# Add(a, b, ....)
########################################################################
sub Add
{
my $sum = 0;
my $arg;
foreach $arg (@_) { $sum += $arg; }
return $sum;
}
Function::AddFunction("add", "Maths::Add");
########################################################################
# Multiply all inputs, usage: - ANY NUMBER OF INPUTS
# Mul(a, b, ....)
########################################################################
sub Mul
{
my $mul = 1;
my $arg;
foreach $arg (@_) { $mul *= $arg; }
return $mul;
}
Function::AddFunction("mul", "Maths::Mul");
########################################################################
# Subtract b from a, usage: - TWO INPUTS ONLY
# Sub(a, b)
########################################################################
sub Sub
{
my ($a, $b) = @_;
return $a - $b;
}
Function::AddFunction("sub", "Maths::Sub");
########################################################################
# Divide a/b, usage: - TWO INPUTS ONLY
# Div(a, b)
########################################################################
sub Div
{
my ($a, $b) = @_;
return $a / $b;
}
Function::AddFunction("div", "Maths::Div");
########################################################################
# Abs(a) - returns the absoulte value of a
# Abs(a, b)
########################################################################
sub Abs
{
my $a = shift;
return abs($a);
}
Function::AddFunction("abs", "Maths::Abs");
########################################################################
# Atan2 arctangent of a/b, usage: - TWO INPUTS ONLY
# Atan2(a, b)
########################################################################
sub Atan2
{
my ($a, $b) = @_;
return atan2($a, $b);
}
Function::AddFunction("atan2", "Maths::Atan2");
########################################################################
# Cos(a) - returns the cosine value of a
# Cos(a)
########################################################################
sub Cos
{
my $a = shift;
return cos($a);
}
Function::AddFunction("cos", "Maths::Cos");
########################################################################
# Exp(a) - returns the exponential value of a
# Exp(a)
########################################################################
sub Exp
{
my $a = shift;
return exp($a);
}
Function::AddFunction("exp", "Maths::Exp");
########################################################################
# Int(a) - returns the integer value of a
# Int(a)
########################################################################
sub Int
{
my $a = shift;
return int($a);
}
Function::AddFunction("int", "Maths::Int");
########################################################################
# Log(a) - returns the logarithm value of a
# Log(a)
########################################################################
sub Log
{
my $a = shift;
return log($a);
}
Function::AddFunction("log", "Maths::Log");
########################################################################
# Rand(a) - returns a random fractional number in range 0 to a,
# if a is ommitted, number is in range 0 to 1
# Rand(a)
########################################################################
sub Rand
{
if($_[0]) { return rand($_[0]); }
return rand();
}
Function::AddFunction("rand", "Maths::Rand");
########################################################################
# Sin(a) - returns the sine value of a
# Sin(a)
########################################################################
sub Sin
{
my $a = shift;
return sin($a);
}
Function::AddFunction("sin", "Maths::Sin");
########################################################################
# Sqrt(a) - returns the square root value of a
# Sqrt(a)
########################################################################
sub Sqrt
{
my $a = shift;
return sqrt($a);
}
Function::AddFunction("sqrt", "Maths::Sqrt");
########################################################################
# Srand(a) - seeds random number generator with a
# Srand(a)
########################################################################
sub Srand
{
if($_[0]) { srand($_[0]); }
else { srand(); }
return "";
}
Function::AddFunction("srand", "Maths::Srand");
return 1;
########################################################################
# End of file
########################################################################
|