Skip to content

Commit

Permalink
inf + nan do work!
Browse files Browse the repository at this point in the history
  • Loading branch information
micsthepick committed Feb 28, 2024
1 parent 38c5752 commit a8373ce
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions testing_defines.eel2
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@

// Helper functions to check for positive infinity, negative infinity, and nan
function is_pos_inf(x) (
(x * 2 == x) && x > 0;
);
function is_neg_inf(x) (
is_pos_inf(-x);
);
function is_nan(x) local(z1, z2) (
z2 = x;
z1 = x + 1;
z2 == 0 && z1 == 0;
);

function assert_equal_exact(expected, actual, message) global(failed_asserts, successful_asserts) (
is_nan(expected) && is_nan(actual) ? successful_asserts += 1 :
(is_pos_inf(expected) && is_pos_inf(actual)) || (is_neg_inf(expected) && is_neg_inf(actual)) ? successful_asserts += 1 :
expected !== actual ? (
fprintf(3, "\033[0;31mexpected: %g, was: %g. %s\033[0m\n", expected, actual, message);
failed_asserts += 1;
Expand All @@ -10,6 +26,8 @@ function assert_equal_exact(expected, actual) global() (
);

function assert_near_equal(expected, tolerance, actual, message) global(failed_asserts, successful_asserts) (
is_nan(expected) || is_nan(actual) || is_nan(tolerance) ? successful_asserts += 1 :
(is_pos_inf(expected) || is_neg_inf(expected)) && (is_pos_inf(actual) || is_neg_inf(actual)) ? successful_asserts += 1 :
abs(expected - actual) > tolerance ? (
fprintf(3, "\033[0;31mexpected: %g (±%g), was: %g. %s\033[0m\n", expected, tolerance, actual, message);
failed_asserts += 1;
Expand Down Expand Up @@ -51,3 +69,54 @@ function test_summary() global(failed_asserts successful_asserts) local(total) (
)
)
);

/*
pif = 0;
pif = 1/pif;
nif = 0;
nif = -1/nif;
lg = 2^64;

printf("z/z=%g, pif=%g, nif=%g\n", z/z, pif, nif);

assert_true( is_pos_inf(pif), " +1/0 is +inf");
assert_false(is_neg_inf(pif), " +1/0 is -inf");
assert_false( is_nan(pif), " +1/0 is nan");
assert_false(is_pos_inf(nif), " -1/0 is +inf");
assert_true( is_neg_inf(nif), " -1/0 is -inf");
assert_false( is_nan(nif), " -1/0 is nan");
assert_false(is_pos_inf(z/z), " z/z is +inf");
assert_false(is_neg_inf(z/z), " z/z is -inf");
assert_true( is_nan(z/z), " z/z is nan");
assert_false(is_pos_inf( 0), " 0 is +inf");
assert_false(is_neg_inf( 0), " 0 is -inf");
assert_false( is_nan( 0), " 0 is nan");
assert_false(is_pos_inf( lg), " 2^64 is +inf");
assert_false(is_neg_inf( lg), " 2^64 is -inf");
assert_false( is_nan( lg), " 2^64 is nan");
assert_false(is_pos_inf(-lg), "-2^64 is +inf");
assert_false(is_neg_inf(-lg), "-2^64 is -inf");
assert_false( is_nan(-lg), "-2^64 is nan");
*/

// drop in for spl(channel)
// function spl(channel) (
// 0 == channel ? spl0 :
// 1 == channel ? spl1 :
// 2 == channel ? spl2 :
// 3 == channel ? spl3 :
// 4 == channel ? spl4 :
// 5 == channel ? spl5 :
// 6 == channel ? spl6 :
// 7 == channel ? spl7 :
// 8 == channel ? spl8 :
// 9 == channel ? spl9 :
// 10 == channel ? spl10 :
// 11 == channel ? spl11 :
// 12 == channel ? spl12 :
// 13 == channel ? spl13 :
// 14 == channel ? spl14 :
// 15 == channel ? spl15 :
// 0;
// );
// does not work for writes!

0 comments on commit a8373ce

Please sign in to comment.