ctfe5
auto ctfe5 =
q{--- ctfe5
// call
i32 fib(i32 number) {
if (number < 1) return 0;
if (number < 3) return 1;
return fib(number-1) + fib(number-2);
}
// loop
i32 fib2(i32 number) {
i32 lo = 0;
i32 hi = 1;
for (i32 i = 0; i < number; ++i) {
hi = hi + lo;
lo = hi - lo;
}
return lo;
}
i32 get() {
enum i32 val = fib(6); // CTFE
return val; // 8
}
i32 get2() {
enum i32 val = fib2(30); // CTFE
return val; // 8
}
};
tests ctfe
functionsvariables