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
examples
core
00_example_template
01_one_sample
02_time_to_botec
03_gcc_nested_function
04_gamma_beta
05_hundred_lognormals
makefile
more
00_example_template
01_sample_from_cdf
02_sample_from_cdf_beta
03_ci_beta
04_nuclear_war
05_burn_10kg_fat
06_nuclear_recovery
07_algebra
08_algebra_and_conversion
09_ergonomic_algebra
10_twitter_thread_example
11_billion_lognormals_paralell
12_time_to_botec_parallel
13_parallelize_min
14_check_confidence_interval
makefile
squiggle.csquiggle_more.c

Binary file not shown.

Binary file not shown.

View File

@ -23,7 +23,7 @@ DEPS=$(SQUIGGLE) $(MATH)
## Flags
DEBUG= #'-g'
WARN=-Wall -Wextra
WARN=-Wall -Wextra -Wdouble-promotion
STANDARD=-std=c99
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
DEBUG= #'-g'
WARN=-Wall -Wextra
WARN=-Wall -Wextra -Wdouble-promotion
STANDARD=-std=c99
WARNINGS=-Wall
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>
double u1 = 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;
}

View File

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