Skip to content

Commit

Permalink
so it turns out inf and nan do work...
Browse files Browse the repository at this point in the history
  • Loading branch information
micsthepick committed Feb 28, 2024
1 parent 9a2e823 commit 15a7fd0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
11 changes: 10 additions & 1 deletion REAPERDenoiser
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function store_noise_profile(buffer) global(SIZE, noiseBuffer) local(index, norm

// calculate an attenuation given the yNorm, and nNorm, and kSquared to approximate sNorm
function denoise(yNorm, nNorm, kSquared) (
yNorm / (yNorm + kSquared * nNorm);
yNorm > 0 ? yNorm / (yNorm + kSquared * nNorm);
);

// helpful functions to get/set the right sample given an index
Expand Down Expand Up @@ -306,6 +306,15 @@ function sum_first_pdc_samples(s0val, s1val) (
);
);

//DEBUGPRINT("TEST_denoise_0_yNorm\n");
assert_equal_exact(0, denoise(0, 0, 0));

//DEBUGPRINT("TEST_denoise_really_small_yNorm\n");
assert_equal_exact(1, denoise(2^-140, 0, 0));

//DEBUGPRINT("TEST_denoise_really_small_yNorm_and_nNorm\n");
assert_equal_exact(0.5, denoise(2^-140, 2^-140, 1));

//DEBUGPRINT("SAMPLE_1_1_STRESS_TEST\n");
// spl0=1 spl1=1 for many samples
sum_first_pdc_samples(1, 1);
Expand Down
43 changes: 40 additions & 3 deletions testing_defines.eel2
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@

// Helper functions to check for positive infinity, negative infinity, and nan
function is_pos_inf(x) (x == 1/0);
function is_neg_inf(x) (x == -1/0);
function is_nan(x) (x != x;);
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 :
Expand Down Expand Up @@ -62,6 +70,35 @@ 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 :
Expand Down

0 comments on commit 15a7fd0

Please sign in to comment.