package Mirror::Math;

use strict;
use warnings;
use POSIX;

sub stddev {
    my @elems = @_;
    my ($avg, $var) = (0, 0);

    return 0 if (scalar(@elems) == 1);

    for (@elems) {
	$avg += $_;
    }
    $avg /= scalar(@elems);

    for (@elems) {
	$var += ($_-$avg)**2;
    }
    $var /= scalar(@elems)-1;

    return sqrt($var);
}

sub iquartile(@) {
    my @elems = @_;
    my ($lower, $upper) = (0.25 * $#elems, 0.75 * $#elems);

    $lower = POSIX::ceil($lower);
    $upper = POSIX::ceil($upper);

    return @elems[$lower..$upper];
}

1;
