diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-28 13:46:35 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-28 13:46:35 -0400 |
| commit | 9bc18cb6174ff563c18a1ca9b462c58971b51733 (patch) | |
| tree | e57e42ed40d1ffa1e6c402841f32b7efdd910796 /src/stdlib | |
| parent | a79b3c2216d386e705603c6dcbf10c1c391fcd99 (diff) | |
Fix some minor floating point promotion issues
Diffstat (limited to 'src/stdlib')
| -rw-r--r-- | src/stdlib/nums.c | 4 | ||||
| -rw-r--r-- | src/stdlib/nums.h | 2 | ||||
| -rw-r--r-- | src/stdlib/optionals.c | 4 |
3 files changed, 5 insertions, 5 deletions
diff --git a/src/stdlib/nums.c b/src/stdlib/nums.c index 93e2b21b..ca8dcc4e 100644 --- a/src/stdlib/nums.c +++ b/src/stdlib/nums.c @@ -125,11 +125,11 @@ public CONSTFUNC bool Num32$near(float a, float b, float ratio, float absolute) if (a == b) return true; - float diff = fabs(a - b); + float diff = fabsf(a - b); if (diff < absolute) return true; else if (isnan(diff)) return false; - float epsilon = fabs(a * ratio) + fabs(b * ratio); + float epsilon = fabsf(a * ratio) + fabsf(b * ratio); if (isinf(epsilon)) epsilon = FLT_MAX; return (diff < epsilon); } diff --git a/src/stdlib/nums.h b/src/stdlib/nums.h index f355fb6f..3f0cccc8 100644 --- a/src/stdlib/nums.h +++ b/src/stdlib/nums.h @@ -100,7 +100,7 @@ MACROLIKE CONSTFUNC float Num32$from_int(Int_t i, bool truncate) { float ret = (float)mpz_get_d(*i.big); if (!truncate) { mpz_t roundtrip; - mpz_init_set_d(roundtrip, ret); + mpz_init_set_d(roundtrip, (double)ret); if unlikely (mpz_cmp(*i.big, roundtrip) != 0) fail("Could not convert integer to 32-bit floating point without losing precision: ", i); } diff --git a/src/stdlib/optionals.c b/src/stdlib/optionals.c index d91ebffc..462b2df2 100644 --- a/src/stdlib/optionals.c +++ b/src/stdlib/optionals.c @@ -81,9 +81,9 @@ public void Optional$deserialize(FILE *in, void *outval, Array_t *pointers, cons else if (nonnull->tag == TableInfo) *(Table_t*)outval = (Table_t){.entries={.length=-1}}; else if (nonnull == &Num$info) - *(double*)outval = NAN; + *(double*)outval = (double)NAN; else if (nonnull == &Num32$info) - *(float*)outval = NAN; + *(float*)outval = (float)NAN; else if (nonnull->tag == StructInfo || (nonnull->tag == OpaqueInfo && type->size > nonnull->size)) memset(outval + type->size, -1, (size_t)(type->size - nonnull->size)); else |
