#!/usr/bin/env perl use utf8; ############################################################################### # This program demonstrates the math integer functions. # # Copyright © 2020 Richard Lesh. All rights reserved. ############################################################################### use List::Util qw(min max); use Math::Trig qw(abs rand); use Utils; use strict; use warnings; MAIN: { my $a = 5; my $b = 10; my $c = -2; # abs, floor, ceil, round, trunc, min, max print Utils::messageFormat("abs(\{0:d\}) = \{1:d\}", $a, abs($a)), "\n"; print Utils::messageFormat("abs(\{0:d\}) = \{1:d\}", $c, abs($c)), "\n"; print Utils::messageFormat("min(\{0:d\}, \{1:d\}) = \{2:d\}", $a, $b, min($a, $b)), "\n"; print Utils::messageFormat("max(\{0:d\}, \{1:d\}) = \{2:d\}", $a, $b, max($a, $b)), "\n"; print Utils::messageFormat("min(\{0:d\}, \{1:d\}) = \{2:d\}", $b, $c, min($b, $c)), "\n"; print Utils::messageFormat("max(\{0:d\}, \{1:d\}) = \{2:d\}", $b, $c, max($b, $c)), "\n"; # random numbers print Utils::messageFormat("random(\{0:d\}) = \{1:d\}", $a, int(rand($a))), "\n"; print Utils::messageFormat("random(\{0:d\}) = \{1:d\}", $a, int(rand($a))), "\n"; print Utils::messageFormat("random(\{0:d\}) = \{1:d\}", $a, int(rand($a))), "\n"; print Utils::messageFormat("random(\{0:d\}) = \{1:d\}", $a, int(rand($a))), "\n"; print Utils::messageFormat("random(\{0:d\}) = \{1:d\}", $a, int(rand($a))), "\n"; print Utils::messageFormat("random(\{0:d\}) = \{1:d\}", $b, int(rand($b))), "\n"; print Utils::messageFormat("random(\{0:d\}) = \{1:d\}", $b, int(rand($b))), "\n"; print Utils::messageFormat("random(\{0:d\}) = \{1:d\}", $b, int(rand($b))), "\n"; print Utils::messageFormat("random(\{0:d\}) = \{1:d\}", $b, int(rand($b))), "\n"; print Utils::messageFormat("random(\{0:d\}) = \{1:d\}", $b, int(rand($b))), "\n"; print Utils::messageFormat("random(2) = \{0:d\}", int(rand(2))), "\n"; print Utils::messageFormat("random(2) = \{0:d\}", int(rand(2))), "\n"; print Utils::messageFormat("random(2) = \{0:d\}", int(rand(2))), "\n"; print Utils::messageFormat("random(2) = \{0:d\}", int(rand(2))), "\n"; print Utils::messageFormat("random(2) = \{0:d\}", int(rand(2))), "\n"; print Utils::messageFormat("random() = \{0:f\}", rand()), "\n"; print Utils::messageFormat("random() = \{0:f\}", rand()), "\n"; print Utils::messageFormat("random() = \{0:f\}", rand()), "\n"; print Utils::messageFormat("random() = \{0:f\}", rand()), "\n"; print Utils::messageFormat("random() = \{0:f\}", rand()), "\n"; }