squiggle.c

Self-contained Monte Carlo estimation in C99
Log | Files | Refs | README

commit e1af09b49a2b6f5b9a8e71d7d3d71b3803d42c56
parent 693fac451f7dd6739184aec41894eb5ac01a93b0
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Sat,  9 Dec 2023 18:18:07 +0000

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

Diffstat:
Mexamples/core/00_example_template/example | 0
Mexamples/core/01_one_sample/example | 0
Mexamples/core/02_time_to_botec/example | 0
Mexamples/core/03_gcc_nested_function/example | 0
Mexamples/core/04_gamma_beta/example | 0
Mexamples/core/05_hundred_lognormals/example | 0
Mexamples/core/makefile | 2+-
Mexamples/more/00_example_template/example | 0
Mexamples/more/01_sample_from_cdf/example | 0
Mexamples/more/02_sample_from_cdf_beta/example | 0
Mexamples/more/03_ci_beta/example | 0
Mexamples/more/04_nuclear_war/example | 0
Mexamples/more/05_burn_10kg_fat/example | 0
Mexamples/more/06_nuclear_recovery/example | 0
Mexamples/more/07_algebra/example | 0
Mexamples/more/08_algebra_and_conversion/example | 0
Mexamples/more/09_ergonomic_algebra/example | 0
Mexamples/more/10_twitter_thread_example/example | 0
Mexamples/more/11_billion_lognormals_paralell/example | 0
Mexamples/more/12_time_to_botec_parallel/example | 0
Mexamples/more/13_parallelize_min/example | 0
Mexamples/more/14_check_confidence_interval/example | 0
Mexamples/more/makefile | 2+-
Msquiggle.c | 2+-
Msquiggle_more.c | 10++++++----
25 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/examples/core/00_example_template/example b/examples/core/00_example_template/example Binary files differ. diff --git a/examples/core/01_one_sample/example b/examples/core/01_one_sample/example Binary files differ. diff --git a/examples/core/02_time_to_botec/example b/examples/core/02_time_to_botec/example Binary files differ. diff --git a/examples/core/03_gcc_nested_function/example b/examples/core/03_gcc_nested_function/example Binary files differ. diff --git a/examples/core/04_gamma_beta/example b/examples/core/04_gamma_beta/example Binary files differ. diff --git a/examples/core/05_hundred_lognormals/example b/examples/core/05_hundred_lognormals/example Binary files differ. diff --git a/examples/core/makefile b/examples/core/makefile @@ -23,7 +23,7 @@ DEPS=$(SQUIGGLE) $(MATH) ## Flags DEBUG= #'-g' -WARN=-Wall -Wextra +WARN=-Wall -Wextra -Wdouble-promotion STANDARD=-std=c99 OPTIMIZED=-O3 #-Ofast diff --git a/examples/more/00_example_template/example b/examples/more/00_example_template/example Binary files differ. diff --git a/examples/more/01_sample_from_cdf/example b/examples/more/01_sample_from_cdf/example Binary files differ. diff --git a/examples/more/02_sample_from_cdf_beta/example b/examples/more/02_sample_from_cdf_beta/example Binary files differ. diff --git a/examples/more/03_ci_beta/example b/examples/more/03_ci_beta/example Binary files differ. diff --git a/examples/more/04_nuclear_war/example b/examples/more/04_nuclear_war/example Binary files differ. diff --git a/examples/more/05_burn_10kg_fat/example b/examples/more/05_burn_10kg_fat/example Binary files differ. diff --git a/examples/more/06_nuclear_recovery/example b/examples/more/06_nuclear_recovery/example Binary files differ. diff --git a/examples/more/07_algebra/example b/examples/more/07_algebra/example Binary files differ. diff --git a/examples/more/08_algebra_and_conversion/example b/examples/more/08_algebra_and_conversion/example Binary files differ. diff --git a/examples/more/09_ergonomic_algebra/example b/examples/more/09_ergonomic_algebra/example Binary files differ. diff --git a/examples/more/10_twitter_thread_example/example b/examples/more/10_twitter_thread_example/example Binary files differ. diff --git a/examples/more/11_billion_lognormals_paralell/example b/examples/more/11_billion_lognormals_paralell/example Binary files differ. diff --git a/examples/more/12_time_to_botec_parallel/example b/examples/more/12_time_to_botec_parallel/example Binary files differ. diff --git a/examples/more/13_parallelize_min/example b/examples/more/13_parallelize_min/example Binary files differ. diff --git a/examples/more/14_check_confidence_interval/example b/examples/more/14_check_confidence_interval/example Binary files differ. diff --git a/examples/more/makefile b/examples/more/makefile @@ -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 diff --git a/squiggle.c b/squiggle.c @@ -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; } diff --git a/squiggle_more.c b/squiggle_more.c @@ -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) {