diff --git a/examples/06_gamma_beta/example b/examples/06_gamma_beta/example index b3743d3..20513bc 100755 Binary files a/examples/06_gamma_beta/example and b/examples/06_gamma_beta/example differ diff --git a/squiggle.c b/squiggle.c index 9d649d3..3d3f4e6 100644 --- a/squiggle.c +++ b/squiggle.c @@ -105,9 +105,9 @@ float sample_gamma(float alpha, uint64_t* seed) v = 1.0 + c * x; } while (v <= 0.0); - v = pow(v, 3); + v = v * v * v; u = sample_unit_uniform(seed); - if (u < 1.0 - 0.0331 * pow(x, 4)) { // Condition 1 + if (u < 1.0 - 0.0331 * (x * x * x * x)) { // Condition 1 // the 0.0331 doesn't inspire much confidence // however, this isn't the whole story // by knowing that Condition 1 implies condition 2 @@ -115,7 +115,7 @@ float sample_gamma(float alpha, uint64_t* seed) // i.e., of not using the logarithms return d * v; } - if (log(u) < 0.5 * pow(x, 2) + d * (1.0 - v + log(v))) { // Condition 2 + if (log(u) < 0.5 * (x * x) + d * (1.0 - v + log(v))) { // Condition 2 return d * v; } } @@ -161,7 +161,8 @@ float array_std(float* array, int length) float mean = array_mean(array, length); float std = 0.0; for (int i = 0; i < length; i++) { - std += pow(array[i] - mean, 2.0); + std += (array[i] - mean); + std *= std; } std = sqrt(std / length); return std;