Skip to content

Commit ba8e822

Browse files
committed
c/hvapprox.c (compute_hua_wang_direction): Pre-compute sinl().
1 parent c22f43e commit ba8e822

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

c/hvapprox.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,15 +573,21 @@ compute_hua_wang_direction(double * restrict direction, dimension_t dim,
573573
{
574574
ASSUME(2 <= dim && dim <= 32);
575575
dimension_t k, j;
576-
direction[0] = STATIC_CAST(double, sinl(theta[0]));
576+
for (j = 1; j < dim; j++)
577+
direction[j] = STATIC_CAST(double, cosl(theta[dim - j - 1]));
578+
579+
double * sinl_theta = malloc((dim - 1) * sizeof(*theta));
580+
for (k = 0; k < dim - 1; k++)
581+
sinl_theta[k] = STATIC_CAST(double, sinl(theta[k]));
582+
direction[0] = sinl_theta[0];
577583
for (k = 1; k < dim - 1; k++)
578-
direction[0] *= STATIC_CAST(double, sinl(theta[k]));
584+
direction[0] *= sinl_theta[k];
579585
for (j = 1; j < dim; j++) {
580-
direction[j] = STATIC_CAST(double, cosl(theta[dim - j - 1]));
581586
for (k = 0; k < dim - j - 1; k++) {
582-
direction[j] *= STATIC_CAST(double, sinl(theta[k]));
587+
direction[j] *= sinl_theta[k];
583588
}
584589
}
590+
free(sinl_theta);
585591
for (k = 0; k < dim; k++) {
586592
// FIXME: Can direction[k] be negative? If not, then we don't need fabs().
587593
direction[k] = (fabs(direction[k]) <= ALMOST_ZERO_WEIGHT)

0 commit comments

Comments
 (0)