add -Wdouble-promotion warning and fix issues it brings up

This commit is contained in:
NunoSempere 2023-12-09 18:18:07 +00:00
parent 693fac451f
commit e1af09b49a
25 changed files with 9 additions and 7 deletions

Binary file not shown.

Binary file not shown.

View File

@ -23,7 +23,7 @@ DEPS=$(SQUIGGLE) $(MATH)
## Flags ## Flags
DEBUG= #'-g' DEBUG= #'-g'
WARN=-Wall -Wextra WARN=-Wall -Wextra -Wdouble-promotion
STANDARD=-std=c99 STANDARD=-std=c99
OPTIMIZED=-O3 #-Ofast OPTIMIZED=-O3 #-Ofast

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -25,7 +25,7 @@ DEPS=$(SQUIGGLE) $(SQUIGGLE_MORE) $(MATH) $(OPENMP)
## Flags ## Flags
DEBUG= #'-g' DEBUG= #'-g'
WARN=-Wall -Wextra WARN=-Wall -Wextra -Wdouble-promotion
STANDARD=-std=c99 STANDARD=-std=c99
WARNINGS=-Wall WARNINGS=-Wall
OPTIMIZED=-O3 #-Ofast OPTIMIZED=-O3 #-Ofast

View File

@ -50,7 +50,7 @@ double sample_unit_normal(uint64_t* seed)
// // See: <https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform> // // See: <https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform>
double u1 = sample_unit_uniform(seed); double u1 = sample_unit_uniform(seed);
double u2 = sample_unit_uniform(seed); double u2 = sample_unit_uniform(seed);
double z = sqrtf(-2.0 * log(u1)) * sin(2 * PI * u2); double z = sqrt(-2.0 * log(u1)) * sin(2 * PI * u2);
return z; return z;
} }

View File

@ -248,8 +248,9 @@ box inverse_cdf_double(double cdf(double), double p)
// 1. Make sure that cdf(low) < p < cdf(high) // 1. Make sure that cdf(low) < p < cdf(high)
int interval_found = 0; int interval_found = 0;
while ((!interval_found) && (low > -FLT_MAX / 4) && (high < FLT_MAX / 4)) { while ((!interval_found) && (low > -DBL_MAX / 4) && (high < DBL_MAX / 4)) {
// ^ Using FLT_MIN and FLT_MAX is overkill // for floats, use FLT_MAX instead
// Note that this approach is overkill
// but it's also the *correct* thing to do. // but it's also the *correct* thing to do.
int low_condition = (cdf(low) < p); int low_condition = (cdf(low) < p);
@ -314,8 +315,9 @@ box inverse_cdf_box(box cdf_box(double), double p)
// 1. Make sure that cdf(low) < p < cdf(high) // 1. Make sure that cdf(low) < p < cdf(high)
int interval_found = 0; int interval_found = 0;
while ((!interval_found) && (low > -FLT_MAX / 4) && (high < FLT_MAX / 4)) { while ((!interval_found) && (low > -DBL_MAX / 4) && (high < DBL_MAX / 4)) {
// ^ Using FLT_MIN and FLT_MAX is overkill // for floats, use FLT_MAX instead
// Note that this approach is overkill
// but it's also the *correct* thing to do. // but it's also the *correct* thing to do.
box cdf_low = cdf_box(low); box cdf_low = cdf_box(low);
if (cdf_low.empty) { if (cdf_low.empty) {