hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 59144095cf0bfd6f7626059fe41bb98e2939e2cc
parent be3282a8fb21490a425d1ec275b05a0de30c8a3f
Author: Sebastian <sebastian@sebsite.pw>
Date:   Fri, 25 Aug 2023 02:48:50 -0400

Remove assignments from f64 to f32

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mmath/floats.ha | 11++++++-----
Mmath/math.ha | 2+-
Mstrconv/stof.ha | 2+-
3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/math/floats.ha b/math/floats.ha @@ -340,10 +340,10 @@ export fn normalizef64(n: f64) (f64, i64) = { // Takes a potentially subnormal f32 n and returns a normal f32 normal_float // and an exponent exp such that n == normal_float * 2^{exp}. -export fn normalizef32(n: f32) (f64, i64) = { +export fn normalizef32(n: f32) (f32, i64) = { if (issubnormalf32(n)) { const factor = 1i32 << (F32_MANTISSA_BITS: i32); - const normal_float = ((n * (factor: f64)): f64); + const normal_float = n * factor: f32; return (normal_float, -(F32_MANTISSA_BITS: i64)); }; return (n, 0); @@ -369,7 +369,7 @@ export fn frexpf64(n: f64) (f64, i64) = { // Breaks a f32 down into its mantissa and exponent. The mantissa will be // between 0.5 and 1. -export fn frexpf32(n: f32) (f64, i64) = { +export fn frexpf32(n: f32) (f32, i64) = { if (isnan(n) || isinf(n) || n == 0f32) { return (n, 0); }; @@ -393,7 +393,8 @@ export fn frexp(n: types::floating) (f64, i64) = { case let n: f64 => return frexpf64(n); case let n: f32 => - return frexpf32(n); + let (mantissa, exp) = frexpf32(n); + return (mantissa, exp); }; }; @@ -452,7 +453,7 @@ export fn ldexpf32(mantissa: f32, exp: i64) f32 = { let res_exp = exp + normalization_exp + mantissa_exp; // Underflow if (res_exp < -(F32_EXPONENT_BIAS: i32) - (F32_MANTISSA_BITS: i32)) { - return copysign(0.0f32, mantissa); + return copysignf32(0.0f32, mantissa); }; // Overflow if (res_exp > (F32_EXPONENT_BIAS: i32)) { diff --git a/math/math.ha b/math/math.ha @@ -93,7 +93,7 @@ export fn isclosef64(x: f64, y: f64) bool = { // Returns whether x and y are within [[STANDARD_TOL]] of each other. export fn isclosef32(x: f32, y: f32) bool = { - return eqwithinf32(x, y, STANDARD_TOL); + return eqwithinf32(x, y, STANDARD_TOL: f32); }; // Returns whether x and y are within [[STANDARD_TOL]] of each other. diff --git a/strconv/stof.ha b/strconv/stof.ha @@ -524,7 +524,7 @@ fn stof32exact(mant: u32, exp: i32, neg: bool) (f32 | void) = { if (exp >= 0) { n *= f32pow10[exp]; } else { - n /= f64pow10[-exp]; + n /= f64pow10[-exp]: f32; }; } else return; return n;