From a726a68dfce160a70670025da25f187b3a5e1d4d Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 10 Mar 2015 12:49:11 -0400 Subject: [PATCH] sane tests for inf/nan num2dec / dec2str --- test/test_sane.c | 166 +++++++++++++++++++++++++++++++---------------- 1 file changed, 109 insertions(+), 57 deletions(-) diff --git a/test/test_sane.c b/test/test_sane.c index 786d3fe..b2f57ed 100644 --- a/test/test_sane.c +++ b/test/test_sane.c @@ -12,6 +12,105 @@ void dump_decimal(const decimal *d) } +void test_inf(void) +{ + + decimal d; + decform df; + char buffer[80+1]; + + printf("\nInfinity\n"); + + df.style = 1; + df.digits = 10; + num2dec(&df,-inf(), &d); + dump_decimal(&d); + // + dec2str(&df, &d, buffer); + fprintf(stdout, "%s\n", buffer); + + df.style = 0; + df.digits = 10; + num2dec(&df, -inf(), &d); + dump_decimal(&d); + // + dec2str(&df, &d, buffer); + fprintf(stdout, "%s\n", buffer); + + df.style = 1; + df.digits = 0; + num2dec(&df, inf(), &d); + dump_decimal(&d); + // + dec2str(&df, &d, buffer); + fprintf(stdout, "%s\n", buffer); + + df.style = 0; + df.digits = 0; + num2dec(&df, inf(), &d); + dump_decimal(&d); + // + dec2str(&df, &d, buffer); + fprintf(stdout, "%s\n", buffer); + +} + +void test_nan(void) +{ + + + // num2dec generates N[16-digit] + // str2dec generates NAN(001) -- NAN(255) + + decimal d; + decform df; + char buffer[80+1]; + + printf("\nNaN\n"); + + df.style = 1; + df.digits = 0; + num2dec(&df,nan(1), &d); + dump_decimal(&d); + // 7 : N4001000000000000 + dec2str(&df, &d, buffer); + fprintf(stdout, "%s\n", buffer); + + df.style = 0; + df.digits = 0; + num2dec(&df, nan(2), &d); + dump_decimal(&d); + // + dec2str(&df, &d, buffer); + fprintf(stdout, "%s\n", buffer); + + + df.style = 1; + df.digits = 10; + num2dec(&df,-nan(3), &d); + dump_decimal(&d); + // + dec2str(&df, &d, buffer); + fprintf(stdout, "%s\n", buffer); + + df.style = 0; + df.digits = 10; + num2dec(&df, nan(4), &d); + dump_decimal(&d); + // + dec2str(&df, &d, buffer); + fprintf(stdout, "%s\n", buffer); + + df.style = 0; + df.digits = 10; + num2dec(&df, nan(255), &d); + dump_decimal(&d); + // 7 : N40FF000000000000 + + dec2str(&df, &d, buffer); + fprintf(stdout, "%s\n", buffer); +} + void test_fxc2dec(void) { decimal d; @@ -125,55 +224,9 @@ void test_fxc2dec(void) // - df.style = 1; - df.digits = 0; - num2dec(&df,nan(1), &d); - dump_decimal(&d); - // - - df.style = 0; - df.digits = 0; - num2dec(&df, nan(2), &d); - dump_decimal(&d); - // - df.style = 1; - df.digits = 10; - num2dec(&df,-nan(3), &d); - dump_decimal(&d); - // - - df.style = 0; - df.digits = 10; - num2dec(&df, nan(4), &d); - dump_decimal(&d); - // - - - df.style = 1; - df.digits = 10; - num2dec(&df,-inf(), &d); - dump_decimal(&d); - // - - df.style = 0; - df.digits = 10; - num2dec(&df, -inf(), &d); - dump_decimal(&d); - - - df.style = 1; - df.digits = 0; - num2dec(&df, inf(), &d); - dump_decimal(&d); - // - - df.style = 0; - df.digits = 0; - num2dec(&df, inf(), &d); - dump_decimal(&d); df.style = 0; @@ -200,28 +253,27 @@ void test_fxc2dec(void) dump_decimal(&d); // s/b -4 0 - - - } int main(int argc, char **argv) { - extended x; - decimal d; + //extended x; + //decimal d; - short index; - short valid; + //short index; + //short valid; (void)argc; (void)argv; - index = 0; - valid = 0; - str2dec("1.125", &index, &d, &valid); - x = dec2num(&d); + //index = 0; + //valid = 0; + //str2dec("1.125", &index, &d, &valid); + //x = dec2num(&d); + test_inf(); + test_nan(); test_fxc2dec();