This is sort of stupid (as in rather basic), but I figure someone could learn from this.
Usage:
$min(numbers sepearted by spaces)
$max(numbers sepearted by spaces)
$average(numbers sepearted by spaces)
$decimal(number of decimal places, number) [IE: $decimal(2, 5.546) will return 5.55]
alias min {
var %num = $1-,%x = 1,%min
while (%x <= $numtok(%num,32)) {
var %tok = $gettok(%num,%x,32)
if (!%min) || (%tok < %min) { %min = %tok }
inc %x
}
return %min
}
alias max {
var %num = $1-,%x = 1,%max
while (%x <= $numtok(%num,32)) {
var %tok = $gettok(%num,%x,32)
if (!%max) || (%tok > %max) { %max = %tok }
inc %x
}
return %max
}
alias average {
var %num = $1-,%x = 1,%total,%tok
while (%x <= $numtok(%num,32)) {
%tok = $gettok(%num,%x,32)
%total = $calc(%total + %tok)
inc %x
}
return $calc(%total / %x)
}
alias decimal {
if ($2 isnum) {
var %tok = $gettok($2,2,46),%tokn = $gettok($2,1,46)
if ($1 = 0) { return %tokn | halt }
return %tokn $+ . $+ $iif($right($left(%tok,$calc($1 + 1)),1) >= 5,$calc($left(%tok,$1) + 1),$left(%tok,$1))
}
}
You can also simplify your $min & $max alias to this ( which you can also specifify the token delimiters):
;Syntax: $min(n1 n2 n3,C)
alias min return $gettok($sorttok($$1,$2,n),1,$2)
;Syntax: $max(n1 n2 n3,C)
alias max return $gettok($sorttok($$1,$2,nr),1,$2)
For your $decimal, $round is already built-in with mIRC which does the same thing.