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,11 +1,11 @@
import std.stdio, std.traits, std.algorithm;
auto sma(T, int period)() {
auto sma(T, int period)() pure nothrow @safe {
T[period] data = 0;
T sum = 0;
int index, nFilled;
return (in T v) nothrow {
return (in T v) nothrow @safe @nogc {
sum += -data[index] + v;
data[index] = v;
index = (index + 1) % period;
@ -19,6 +19,5 @@ void main() {
immutable s5 = sma!(double, 5);
foreach (immutable e; [1, 2, 3, 4, 5, 5, 4, 3, 2, 1])
writefln("Added %d, sma(3) = %f, sma(5) = %f",
e, s3(e), s5(e));
writefln("Added %d, sma(3) = %f, sma(5) = %f", e, s3(e), s5(e));
}

View file

@ -5,7 +5,7 @@ struct SMA(T, int period) {
T sum = 0;
int index, nFilled;
auto opCall(in T v) pure nothrow {
auto opCall(in T v) pure nothrow @safe @nogc {
sum += -data[index] + v;
data[index] = v;
index = (index + 1) % period;
@ -19,6 +19,5 @@ void main() {
SMA!(double, 5) s5;
foreach (immutable e; [1, 2, 3, 4, 5, 5, 4, 3, 2, 1])
writefln("Added %d, sma(3) = %f, sma(5) = %f",
e, s3(e), s5(e));
writefln("Added %d, sma(3) = %f, sma(5) = %f", e, s3(e), s5(e));
}