hare

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

commit 7f4caff66655a560108bbf86c7e05a51cd08a67f
parent 2ae399bf86e98bddd358192edaeab4843c44e8c8
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sun,  5 Jun 2022 00:20:16 -0400

math: remove isneginf and isposinf

These didn't serve a purpose, since numbers can be directly compared to
math::INF or -math::INF.

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

Diffstat:
Mmath/fenv+aarch64.ha | 24++++++++++++------------
Mmath/fenv+riscv64.ha | 24++++++++++++------------
Mmath/fenv+x86_64.ha | 24++++++++++++------------
Mmath/floats.ha | 14--------------
Mmath/math.ha | 44++++++++++++++++++++++----------------------
5 files changed, 58 insertions(+), 72 deletions(-)

diff --git a/math/fenv+aarch64.ha b/math/fenv+aarch64.ha @@ -85,8 +85,8 @@ export type fround = enum uint { assert(getround() == fround::TONEAREST); assert(isnan(nearbyintf64(f(0x7ff8000000000000)))); - assert(isposinf(nearbyintf64(f(0x7ff0000000000000)))); - assert(isneginf(nearbyintf64(f(0xfff0000000000000)))); + assert(nearbyintf64(f(0x7ff0000000000000)) == INF); + assert(nearbyintf64(f(0xfff0000000000000)) == -INF); assert(nearbyintf64(f(0x0)) == f(0x0)); assert(nearbyintf64(f(0x8000000000000000)) == f(0x8000000000000000)); assert(nearbyintf64(f(0x3ff0000000000000)) == f(0x3ff0000000000000)); @@ -103,8 +103,8 @@ export type fround = enum uint { setround(fround::DOWNWARD); assert(getround() == fround::DOWNWARD); assert(isnan(nearbyintf64(f(0x7ff8000000000000)))); - assert(isposinf(nearbyintf64(f(0x7ff0000000000000)))); - assert(isneginf(nearbyintf64(f(0xfff0000000000000)))); + assert(nearbyintf64(f(0x7ff0000000000000)) == INF); + assert(nearbyintf64(f(0xfff0000000000000)) == -INF); assert(nearbyintf64(f(0x0)) == f(0x0)); assert(nearbyintf64(f(0x8000000000000000)) == f(0x8000000000000000)); assert(nearbyintf64(f(0x3ff0000000000000)) == f(0x3ff0000000000000)); @@ -121,8 +121,8 @@ export type fround = enum uint { setround(fround::UPWARD); assert(getround() == fround::UPWARD); assert(isnan(nearbyintf64(f(0x7ff8000000000000)))); - assert(isposinf(nearbyintf64(f(0x7ff0000000000000)))); - assert(isneginf(nearbyintf64(f(0xfff0000000000000)))); + assert(nearbyintf64(f(0x7ff0000000000000)) == INF); + assert(nearbyintf64(f(0xfff0000000000000)) == -INF); assert(nearbyintf64(f(0x0)) == f(0x0)); assert(nearbyintf64(f(0x8000000000000000)) == f(0x8000000000000000)); assert(nearbyintf64(f(0x3ff0000000000000)) == f(0x3ff0000000000000)); @@ -141,8 +141,8 @@ export type fround = enum uint { setround(fround::TONEAREST); assert(getround() == fround::TONEAREST); assert(isnan(nearbyintf32(f(0x7fc00000)))); - assert(isposinf(nearbyintf32(f(0x7f800000)))); - assert(isneginf(nearbyintf32(f(0xff800000)))); + assert(nearbyintf32(f(0x7f800000)) == INF); + assert(nearbyintf32(f(0xff800000)) == -INF); assert(nearbyintf32(f(0x0)) == f(0x0)); assert(nearbyintf32(f(0x80000000)) == f(0x80000000)); assert(nearbyintf32(f(0x3f800000)) == f(0x3f800000)); @@ -159,8 +159,8 @@ export type fround = enum uint { setround(fround::DOWNWARD); assert(getround() == fround::DOWNWARD); assert(isnan(nearbyintf32(f(0x7fc00000)))); - assert(isposinf(nearbyintf32(f(0x7f800000)))); - assert(isneginf(nearbyintf32(f(0xff800000)))); + assert(nearbyintf32(f(0x7f800000)) == INF); + assert(nearbyintf32(f(0xff800000)) == -INF); assert(nearbyintf32(f(0x0)) == f(0x0)); assert(nearbyintf32(f(0x80000000)) == f(0x80000000)); assert(nearbyintf32(f(0x3f800000)) == f(0x3f800000)); @@ -177,8 +177,8 @@ export type fround = enum uint { setround(fround::UPWARD); assert(getround() == fround::UPWARD); assert(isnan(nearbyintf32(f(0x7fc00000)))); - assert(isposinf(nearbyintf32(f(0x7f800000)))); - assert(isneginf(nearbyintf32(f(0xff800000)))); + assert(nearbyintf32(f(0x7f800000)) == INF); + assert(nearbyintf32(f(0xff800000)) == -INF); assert(nearbyintf32(f(0x0)) == f(0x0)); assert(nearbyintf32(f(0x80000000)) == f(0x80000000)); assert(nearbyintf32(f(0x3f800000)) == f(0x3f800000)); diff --git a/math/fenv+riscv64.ha b/math/fenv+riscv64.ha @@ -86,8 +86,8 @@ export type fround = enum uint { assert(getround() == fround::TONEAREST); assert(isnan(nearbyintf64(f(0x7ff8000000000000)))); - assert(isposinf(nearbyintf64(f(0x7ff0000000000000)))); - assert(isneginf(nearbyintf64(f(0xfff0000000000000)))); + assert(nearbyintf64(f(0x7ff0000000000000)) == INF); + assert(nearbyintf64(f(0xfff0000000000000)) == -INF); assert(nearbyintf64(f(0x0)) == f(0x0)); assert(nearbyintf64(f(0x8000000000000000)) == f(0x8000000000000000)); assert(nearbyintf64(f(0x3ff0000000000000)) == f(0x3ff0000000000000)); @@ -104,8 +104,8 @@ export type fround = enum uint { setround(fround::DOWNWARD); assert(getround() == fround::DOWNWARD); assert(isnan(nearbyintf64(f(0x7ff8000000000000)))); - assert(isposinf(nearbyintf64(f(0x7ff0000000000000)))); - assert(isneginf(nearbyintf64(f(0xfff0000000000000)))); + assert(nearbyintf64(f(0x7ff0000000000000)) == INF); + assert(nearbyintf64(f(0xfff0000000000000)) == -INF); assert(nearbyintf64(f(0x0)) == f(0x0)); assert(nearbyintf64(f(0x8000000000000000)) == f(0x8000000000000000)); assert(nearbyintf64(f(0x3ff0000000000000)) == f(0x3ff0000000000000)); @@ -122,8 +122,8 @@ export type fround = enum uint { setround(fround::UPWARD); assert(getround() == fround::UPWARD); assert(isnan(nearbyintf64(f(0x7ff8000000000000)))); - assert(isposinf(nearbyintf64(f(0x7ff0000000000000)))); - assert(isneginf(nearbyintf64(f(0xfff0000000000000)))); + assert(nearbyintf64(f(0x7ff0000000000000)) == INF); + assert(nearbyintf64(f(0xfff0000000000000)) == -INF); assert(nearbyintf64(f(0x0)) == f(0x0)); assert(nearbyintf64(f(0x8000000000000000)) == f(0x8000000000000000)); assert(nearbyintf64(f(0x3ff0000000000000)) == f(0x3ff0000000000000)); @@ -142,8 +142,8 @@ export type fround = enum uint { setround(fround::TONEAREST); assert(getround() == fround::TONEAREST); assert(isnan(nearbyintf32(f(0x7fc00000)))); - assert(isposinf(nearbyintf32(f(0x7f800000)))); - assert(isneginf(nearbyintf32(f(0xff800000)))); + assert(nearbyintf32(f(0x7f800000)) == INF); + assert(nearbyintf32(f(0xff800000)) == -INF); assert(nearbyintf32(f(0x0)) == f(0x0)); assert(nearbyintf32(f(0x80000000)) == f(0x80000000)); assert(nearbyintf32(f(0x3f800000)) == f(0x3f800000)); @@ -160,8 +160,8 @@ export type fround = enum uint { setround(fround::DOWNWARD); assert(getround() == fround::DOWNWARD); assert(isnan(nearbyintf32(f(0x7fc00000)))); - assert(isposinf(nearbyintf32(f(0x7f800000)))); - assert(isneginf(nearbyintf32(f(0xff800000)))); + assert(nearbyintf32(f(0x7f800000)) == INF); + assert(nearbyintf32(f(0xff800000)) == -INF); assert(nearbyintf32(f(0x0)) == f(0x0)); assert(nearbyintf32(f(0x80000000)) == f(0x80000000)); assert(nearbyintf32(f(0x3f800000)) == f(0x3f800000)); @@ -178,8 +178,8 @@ export type fround = enum uint { setround(fround::UPWARD); assert(getround() == fround::UPWARD); assert(isnan(nearbyintf32(f(0x7fc00000)))); - assert(isposinf(nearbyintf32(f(0x7f800000)))); - assert(isneginf(nearbyintf32(f(0xff800000)))); + assert(nearbyintf32(f(0x7f800000)) == INF); + assert(nearbyintf32(f(0xff800000)) == -INF); assert(nearbyintf32(f(0x0)) == f(0x0)); assert(nearbyintf32(f(0x80000000)) == f(0x80000000)); assert(nearbyintf32(f(0x3f800000)) == f(0x3f800000)); diff --git a/math/fenv+x86_64.ha b/math/fenv+x86_64.ha @@ -86,8 +86,8 @@ export type fround = enum uint { assert(getround() == fround::TONEAREST); assert(isnan(nearbyintf64(f(0x7ff8000000000000)))); - assert(isposinf(nearbyintf64(f(0x7ff0000000000000)))); - assert(isneginf(nearbyintf64(f(0xfff0000000000000)))); + assert(nearbyintf64(f(0x7ff0000000000000)) == INF); + assert(nearbyintf64(f(0xfff0000000000000)) == -INF); assert(nearbyintf64(f(0x0)) == f(0x0)); assert(nearbyintf64(f(0x8000000000000000)) == f(0x8000000000000000)); assert(nearbyintf64(f(0x3ff0000000000000)) == f(0x3ff0000000000000)); @@ -104,8 +104,8 @@ export type fround = enum uint { setround(fround::DOWNWARD); assert(getround() == fround::DOWNWARD); assert(isnan(nearbyintf64(f(0x7ff8000000000000)))); - assert(isposinf(nearbyintf64(f(0x7ff0000000000000)))); - assert(isneginf(nearbyintf64(f(0xfff0000000000000)))); + assert(nearbyintf64(f(0x7ff0000000000000)) == INF); + assert(nearbyintf64(f(0xfff0000000000000)) == -INF); assert(nearbyintf64(f(0x0)) == f(0x0)); assert(nearbyintf64(f(0x8000000000000000)) == f(0x8000000000000000)); assert(nearbyintf64(f(0x3ff0000000000000)) == f(0x3ff0000000000000)); @@ -122,8 +122,8 @@ export type fround = enum uint { setround(fround::UPWARD); assert(getround() == fround::UPWARD); assert(isnan(nearbyintf64(f(0x7ff8000000000000)))); - assert(isposinf(nearbyintf64(f(0x7ff0000000000000)))); - assert(isneginf(nearbyintf64(f(0xfff0000000000000)))); + assert(nearbyintf64(f(0x7ff0000000000000)) == INF); + assert(nearbyintf64(f(0xfff0000000000000)) == -INF); assert(nearbyintf64(f(0x0)) == f(0x0)); assert(nearbyintf64(f(0x8000000000000000)) == f(0x8000000000000000)); assert(nearbyintf64(f(0x3ff0000000000000)) == f(0x3ff0000000000000)); @@ -142,8 +142,8 @@ export type fround = enum uint { setround(fround::TONEAREST); assert(getround() == fround::TONEAREST); assert(isnan(nearbyintf32(f(0x7fc00000)))); - assert(isposinf(nearbyintf32(f(0x7f800000)))); - assert(isneginf(nearbyintf32(f(0xff800000)))); + assert(nearbyintf32(f(0x7f800000)) == INF); + assert(nearbyintf32(f(0xff800000)) == -INF); assert(nearbyintf32(f(0x0)) == f(0x0)); assert(nearbyintf32(f(0x80000000)) == f(0x80000000)); assert(nearbyintf32(f(0x3f800000)) == f(0x3f800000)); @@ -160,8 +160,8 @@ export type fround = enum uint { setround(fround::DOWNWARD); assert(getround() == fround::DOWNWARD); assert(isnan(nearbyintf32(f(0x7fc00000)))); - assert(isposinf(nearbyintf32(f(0x7f800000)))); - assert(isneginf(nearbyintf32(f(0xff800000)))); + assert(nearbyintf32(f(0x7f800000)) == INF); + assert(nearbyintf32(f(0xff800000)) == -INF); assert(nearbyintf32(f(0x0)) == f(0x0)); assert(nearbyintf32(f(0x80000000)) == f(0x80000000)); assert(nearbyintf32(f(0x3f800000)) == f(0x3f800000)); @@ -178,8 +178,8 @@ export type fround = enum uint { setround(fround::UPWARD); assert(getround() == fround::UPWARD); assert(isnan(nearbyintf32(f(0x7fc00000)))); - assert(isposinf(nearbyintf32(f(0x7f800000)))); - assert(isneginf(nearbyintf32(f(0xff800000)))); + assert(nearbyintf32(f(0x7f800000)) == INF); + assert(nearbyintf32(f(0xff800000)) == -INF); assert(nearbyintf32(f(0x0)) == f(0x0)); assert(nearbyintf32(f(0x80000000)) == f(0x80000000)); assert(nearbyintf32(f(0x3f800000)) == f(0x3f800000)); diff --git a/math/floats.ha b/math/floats.ha @@ -177,26 +177,12 @@ export fn isinf(n: f64) bool = { return exp == F64_EXPONENT_MASK && mant == 0; }; -// Returns true if the given floating-point number is positive infinity. -export fn isposinf(n: f64) bool = { - return isinf(n) && signf64(n) == 1i64; -}; - -// Returns true if the given floating-point number is negative infinity. -export fn isneginf(n: f64) bool = { - return isinf(n) && signf64(n) == -1i64; -}; - @test fn isinf() void = { assert(isinf(INF)); assert(isinf(-INF)); assert(!isinf(NAN)); assert(!isinf(1.23)); assert(!isinf(-1.23f32)); - assert(isposinf(INF)); - assert(!isposinf(-INF)); - assert(isneginf(-INF)); - assert(!isneginf(INF)); }; // Returns true if the given floating-point number is normal. diff --git a/math/math.ha b/math/math.ha @@ -198,7 +198,7 @@ export fn logf64(x: f64) f64 = { const L7 = 1.479819860511658591e-01; // 3fc2f112 df3e5244 // special cases - if (isnan(x) || isposinf(x)) { + if (isnan(x) || x == INF) { return x; } else if (x < 0f64) { return NAN; @@ -237,8 +237,8 @@ export fn logf64(x: f64) f64 = { assert(logf64(E) == 1f64); assert(logf64(54.598150033144239078110261202860878402790f64) == 4f64); assert(isnan(logf64(-1f64))); - assert(isposinf(logf64(INF))); - assert(isneginf(logf64(0f64))); + assert(logf64(INF) == INF); + assert(logf64(0f64) == -INF); assert(isnan(logf64(NAN))); }; @@ -364,7 +364,7 @@ export fn log1pf64(x: f64) f64 = { return NAN; } else if (x == -1f64) { return -INF; - } else if (isposinf(x)) { + } else if (x == INF) { return INF; }; @@ -551,9 +551,9 @@ export fn expf64(x: f64) f64 = { const underflow = -7.45133219101941108420e+02; const near_zero = 1f64 / ((1i64 << 28i64): f64); - if (isnan(x) || isposinf(x)) { + if (isnan(x) || x == INF) { return x; - } else if (isneginf(x)) { + } else if (x == -INF) { return 0f64; } else if (x > overflow) { return INF; @@ -582,9 +582,9 @@ export fn exp2f64(x: f64) f64 = { const overflow = 1.0239999999999999e+03; const underflow = -1.0740e+03; - if (isnan(x) || isposinf(x)) { + if (isnan(x) || x == INF) { return x; - } else if (isneginf(x)) { + } else if (x == -INF) { return 0f64; } else if (x > overflow) { return INF; @@ -700,7 +700,7 @@ export fn exp2f64(x: f64) f64 = { export fn sqrtf64(x: f64) f64 = { if (x == 0f64) { return x; - } else if (isnan(x) || isposinf(x)) { + } else if (isnan(x) || x == INF) { return x; } else if (x < 0f64) { return NAN; @@ -771,7 +771,7 @@ export fn sqrtf64(x: f64) f64 = { assert(sqrtf64(powf64(123f64, 2f64)) == 123f64); assert(sqrtf64(0f64) == 0f64); assert(isnan(sqrtf64(NAN))); - assert(isposinf(sqrtf64(INF))); + assert(sqrtf64(INF) == INF); assert(isnan(sqrtf64(-2f64))); }; @@ -811,12 +811,12 @@ export fn powf64(x: f64, p: f64) f64 = { } else if (isinf(p)) { if (x == -1f64) { return 1f64; - } else if ((absf64(x) < 1f64) == isposinf(p)) { + } else if ((absf64(x) < 1f64) == (p == INF)) { return 0f64; }; return INF; } else if (isinf(x)) { - if (isneginf(x)) { + if (x == -INF) { return powf64(-0f64, -p); } else if (p < 0f64) { return 0f64; @@ -930,17 +930,17 @@ export fn powf64(x: f64, p: f64) f64 = { // pow(x, NaN) = NaN assert(isnan(powf64(123f64, NAN))); // pow(±0, y) = ±Inf for y an odd integer < 0 - assert(isposinf(powf64(0f64, -3f64))); - assert(isneginf(powf64(-0f64, -3f64))); + assert(powf64(0f64, -3f64) == INF); + assert(powf64(-0f64, -3f64) == -INF); // pow(±0, -Inf) = +Inf - assert(isposinf(powf64(0f64, -INF))); - assert(isposinf(powf64(-0f64, -INF))); + assert(powf64(0f64, -INF) == INF); + assert(powf64(-0f64, -INF) == INF); // pow(±0, +Inf) = +0 assert(powf64(0f64, INF) == 0f64); assert(powf64(-0f64, INF) == 0f64); // pow(±0, y) = +Inf for finite y < 0 and not an odd integer - assert(isposinf(powf64(0f64, -2f64))); - assert(isposinf(powf64(-0f64, -2f64))); + assert(powf64(0f64, -2f64) == INF); + assert(powf64(0f64, -2f64) == INF); //pow(±0, y) = ±0 for y an odd integer > 0 assert(powf64(0f64, 123f64) == 0f64); const neg_zero = powf64(-0f64, 123f64); @@ -952,17 +952,17 @@ export fn powf64(x: f64, p: f64) f64 = { assert(powf64(-1f64, INF) == 1f64); assert(powf64(-1f64, -INF) == 1f64); // pow(x, +Inf) = +Inf for |x| > 1 - assert(isposinf(powf64(123f64, INF))); + assert(powf64(123f64, INF) == INF); // pow(x, -Inf) = +0 for |x| > 1 assert(powf64(123f64, -INF) == 0f64); // pow(x, +Inf) = +0 for |x| < 1 assert(powf64(0.5f64, INF) == 0f64); assert(powf64(-0.5f64, INF) == 0f64); // pow(x, -Inf) = +Inf for |x| < 1 - assert(isposinf(powf64(0.5f64, -INF))); - assert(isposinf(powf64(-0.5f64, -INF))); + assert(powf64(0.5f64, -INF) == INF); + assert(powf64(-0.5f64, -INF) == INF); // pow(+Inf, y) = +Inf for y > 0 - assert(isposinf(powf64(INF, 123f64))); + assert(powf64(INF, 123f64) == INF); // pow(+Inf, y) = +0 for y < 0 assert(powf64(INF, -1f64) == 0f64); // pow(-Inf, y) = pow(-0, -y)