Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,6 +1,4 @@
import std.stdio;
real mean(Range)(Range r) {
real mean(Range)(Range r) pure nothrow @nogc {
real sum = 0.0;
int count;
@ -16,8 +14,10 @@ real mean(Range)(Range r) {
}
void main() {
import std.stdio;
int[] data;
writeln("mean: ", data.mean());
writeln("Mean: ", data.mean);
data = [3, 1, 4, 1, 5, 9];
writeln("mean: ", data.mean());
writeln("Mean: ", data.mean);
}

View file

@ -1,6 +1,6 @@
import std.stdio, std.algorithm, std.range;
real mean(Range)(Range r) pure nothrow {
real mean(Range)(Range r) pure nothrow @nogc {
return r.sum / max(1.0L, r.count);
}

View file

@ -1,10 +1,10 @@
import std.stdio, std.conv, std.algorithm, std.math, std.traits;
CommonType!(T, real) mean(T)(T[] n ...) if (isNumeric!(T)) {
alias CommonType!(T, real) E;
CommonType!(T, real) mean(T)(T[] n ...) if (isNumeric!T) {
alias E = CommonType!(T, real);
auto num = n.dup;
schwartzSort!(abs, "a > b")(num);
return reduce!q{a+b}(0.0L, map!(to!E)(num)) / max(1, num.length);
num.schwartzSort!(abs, "a > b");
return num.map!(to!E).sum(0.0L) / max(1, num.length);
}
void main() {