diff options
author | B. Watson <yalhcru@gmail.com> | 2016-01-17 00:42:34 -0500 |
---|---|---|
committer | B. Watson <yalhcru@gmail.com> | 2016-01-17 00:42:34 -0500 |
commit | b9c1931a80c5d700ba356f9090e9a72f075377f7 (patch) | |
tree | 975acab9ea0ddb958485948ecd0b9ac9ea09fa53 /taipan.c | |
parent | 24a2c856400918329e105b1f3ca2bd2ec386c9b0 (diff) | |
download | taipan-b9c1931a80c5d700ba356f9090e9a72f075377f7.tar.gz |
fix final_stats() negative finalcash and score
Diffstat (limited to 'taipan.c')
-rw-r--r-- | taipan.c | 45 |
1 files changed, 20 insertions, 25 deletions
@@ -333,7 +333,14 @@ void cprintfancy_big(bignump b) { unsigned long leftdigits = 0L; unsigned char rightdigits = 0, letter = 'M', leading0 = 0; - if(big_cmp(b, big1T) >= 0) { + big_copy(tmp, b); + + if(big_cmp(tmp, big0) < 0) { + cputc('-'); + big_negate(tmp, tmp); + } + + if(big_cmp(tmp, big1T) >= 0) { revers(1); cputs("1 Trillion+!"); revers(0); @@ -341,16 +348,14 @@ void cprintfancy_big(bignump b) { } /* for >= 1B, divide by 1M */ - if(big_cmp(b, big1B) >= 0) { - big_div(tmp, b, big1K); + if(big_cmp(tmp, big1B) >= 0) { + big_div(tmp, tmp, big1K); letter = 'B'; - } else { - big_copy(tmp, b); } big_to_ulong(tmp, &leftdigits); - if(big_cmp(b, big1M) < 0) { /* 0..999999 */ + if(big_cmp(tmp, big1M) < 0) { /* 0..999999 */ letter = 0; } else if(leftdigits < 10000000L) { /* 1M..10M-1 */ leftdigits /= 10000L; @@ -1707,10 +1712,14 @@ void final_stats(void) ulong_to_big((unsigned long)time, bigtmp); big_div(bigscore, bigscore, bigtmp); - if(big_cmp(bigscore, big1M) > 0) + if(big_cmp(bigscore, big1M) > 0) { score = 1000000L; - else + } else if(big_cmp(bigscore, big0) < 0) { + score = -1; + } else { big_to_ulong(bigscore, (unsigned long*)&score); + } + #else /* TODO: write cprintlong() to print signed value */ long finalcash = cash + bank - debt; @@ -2731,28 +2740,11 @@ void buy(void) { cputs(" "); gotoxy(31, 23); - /* TODO: is this really right? */ if(afford < 100) cputc(' '); if(afford < 10000) cputc(' '); if(afford < 1000000) cputc(' '); if(afford < 100000000) cputc(' '); - /* - if (afford < 100) - { - strcpy(space, " "); - } else if (afford < 10000) { - strcpy(space, " "); - } else if (afford < 1000000) { - strcpy(space, " "); - } else if (afford < 100000000) { - strcpy(space, " "); - } else { - strcpy(space, ""); - } - cputs(space); - */ - cprintulong(afford); revers(0); @@ -2962,6 +2954,9 @@ void bignum_test(void) { for(i = 0; i < 14; i++) { cprintfancy_big(n); + cputc(' '); + big_negate(n, n); + cprintfancy_big(n); cputs("\r\n"); big_mul(n, n, o); } |