summaryrefslogtreecommitdiffstats
path: root/security/nss/lib/freebl/mpi/stats
blob: a5deb94c039edeece378110f7b306a6f3624b763 (plain)
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
#!/usr/bin/perl

#
# Treat each line as a sequence of comma and/or space delimited
# floating point numbers, and compute basic statistics on them.
# These are written to standard output

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

$min = 1.7976931348623157E+308;
$max = 2.2250738585072014E-308;
$sum = $num = 0;

while(<>) {
    chomp;

    @nums = split(/[\s,]+/, $_);
    next if($#nums < 0);

    $num += scalar @nums;
    foreach (@nums) {
	$min = $_ if($_ < $min);
	$max = $_ if($_ > $max);
	$sum += $_;
    }
}

if($num) {
    $avg = $sum / $num;
} else {
    $min = $max = 0;
}

printf "%d\tmin=%.2f, avg=%.2f, max=%.2f, sum=%.2f\n",
    $num, $min, $avg, $max, $sum;

# end