aboutsummaryrefslogtreecommitdiff
path: root/bignum.h
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2016-03-08 17:39:22 -0500
committerB. Watson <yalhcru@gmail.com>2016-03-08 17:39:22 -0500
commit57f2e66c1740eb97034d2cae3fe04d841c305c9d (patch)
treedca5afca0dee2008b0b1690f424f014abcea8718 /bignum.h
parent742808e762c95c77b942b710431a55200f28b5b3 (diff)
downloadtaipan-57f2e66c1740eb97034d2cae3fe04d841c305c9d.tar.gz
initial bigint48 implementation, will be used for the 5200 port
Diffstat (limited to 'bignum.h')
-rw-r--r--bignum.h26
1 files changed, 20 insertions, 6 deletions
diff --git a/bignum.h b/bignum.h
index 535ea65..06fbd8b 100644
--- a/bignum.h
+++ b/bignum.h
@@ -19,6 +19,15 @@
to use the constants:
bignum(foo) = BIG_0;
which looks a little weird I admit.
+
+ Notice that our bignum type is signed, even though we
+ only have functions to convert to/from unsigned long.
+ Only final_stats() and cprintfancy_big() ever deal with
+ negative bignums. Actually, big_div() and big_mul() are
+ unsigned, as they will never be called with negative
+ args. The only signed behaviour we care about here:
+ - big_sub() needs to be able to give a negative result.
+ - big_cmp() needs to be a signed compare.
*/
/* list all our implementations here */
@@ -65,11 +74,11 @@ BEWARE: unlike perl's <=>, the return value is *not* guaranteed to
Do not depend on any particular positive or negative return
value from this:
if(big_cmp(a, b) == -1) // WRONG!
- if(big_cmp(a, b) < 0) // Right. */
+ if(big_cmp(a, b) < 0) // Right. */
extern signed char __fastcall__ big_cmp(bignump a, bignump b);
/* basic math functions. conceptually they return a boolean for
- success, but only division has error checking.
+ success, but currently there is no error checking.
all can be read as: dest = arg2 OP arg3;
modulus isn't implemented as taipan doesn't use it for the bank.
These are __cdecl__ *not* __fastcall__ !!
@@ -85,12 +94,17 @@ extern void __fastcall__ big_negate(bignump b);
/* returns true if the bank is maxed out. We do this by checking the exponent
byte, so the "max" is tied to the bignum implementation, which is why its
prototype is here rather than bank.h. For Atari floats, it's 1.0e+14, or
- 100 trillion.
+ 100 trillion. For bigint48 it would be something like, bit 46 is nonzero,
+ 140.7 trillion.
- If you deposit 1 in the bank at the start of the game and never deposit
- more, the interest will max it out in 1915 (661 turns of play).
- */
+ With floats, if you deposit 1 in the bank at the start of the game and never deposit
+ more, the interest would max it out in 1915 (661 turns of play).
+
+ ended up not implementing this, I don't think anyone will ever have the patience
+ to play long enough to overflow an A8 float (9.0e+97) or a 48-bit int (2**48-1,
+ or 281.5 trillion).
extern char __fastcall__ bank_maxed_out(bignump b);
+ */
/* print a bignum, Taipan-style. Code for this lives in taipan.c actually. */
extern void cprintfancy_big(bignump b);