#!/usr/bin/perl # Michael Tartaglia - math file # This file contains basic rounding math functions. I was not # originally happy with the lack of control given by the built-in "int" # function, so I developed this package. package math; use Exporter; @ISA = qw(Exporter); @EXPORT = qw (&round &floor &ceil &abs); sub round { local $num = $_[0]; local $int = 0; while ($num > 1) { ++$int; --$num; } $num *= 10; ++$int if ($num >= 5); return $int; } sub floor { local $num = $_[0]; local $int = 0; while ($num >= 1) { ++$int; --$num; } return $int; } sub ceil { local $num = $_[0]; local $int = 0; while ($int < $num) { ++$int; } return $int; } sub abs { $int = $_[0]; $int += $int * 2 if ($int < 0); return $int; }