diff options
author | tlatorre <tlatorre@uchicago.edu> | 2018-09-13 10:04:56 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2018-09-13 10:04:56 -0500 |
commit | cf903578dab6002be56fa00f3e2064f904c95fba (patch) | |
tree | b483084dd63d63fe16e95fba8e7663ebd5237269 /src/test.c | |
parent | 8beebac19b9351cdc6108ea31eeda6531d75540b (diff) | |
download | sddm-cf903578dab6002be56fa00f3e2064f904c95fba.tar.gz sddm-cf903578dab6002be56fa00f3e2064f904c95fba.tar.bz2 sddm-cf903578dab6002be56fa00f3e2064f904c95fba.zip |
add a function to compute log(n) for integer n
This commit adds the function ln() to compute log(n) for integer n. It uses a
lookup table for n < 100 to speed things up.
Diffstat (limited to 'src/test.c')
-rw-r--r-- | src/test.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -489,6 +489,28 @@ err: return 1; } +int test_ln(char *err) +{ + /* Tests the lnfact() function. */ + size_t i; + double x, expected; + + for (i = 1; i < 1000; i++) { + x = ln(i); + expected = log(i); + + if (!isclose(x, expected, 1e-9, 1e-9)) { + sprintf(err, "ln(%zu) returned %.5g, but expected %.5g", i, x, expected); + goto err; + } + } + + return 0; + +err: + return 1; +} + struct tests { testFunction *test; char *name; @@ -505,6 +527,7 @@ struct tests { {test_interp1d, "test_interp1d"}, {test_kahan_sum, "test_kahan_sum"}, {test_lnfact, "test_lnfact"}, + {test_ln, "test_ln"}, }; int main(int argc, char **argv) |