aboutsummaryrefslogtreecommitdiff
path: root/bignum.h
diff options
context:
space:
mode:
Diffstat (limited to 'bignum.h')
-rw-r--r--bignum.h36
1 files changed, 22 insertions, 14 deletions
diff --git a/bignum.h b/bignum.h
index 185d118..67ae902 100644
--- a/bignum.h
+++ b/bignum.h
@@ -24,6 +24,7 @@
#define bignum(x) char x[6]
#define bignump char *
+/****** constants ******/
/* zero */
#define BIG_0 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
@@ -41,17 +42,36 @@
/* max value for a ulong */
#define BIG_MAX_ULONG { 0x44, 0x42, 0x94, 0x96, 0x72, 0x95 }
+/****** functions ******/
+
+/* copy dest to src. could be a wrapper for memcpy() */
extern void __fastcall__ big_copy(bignump dest, bignump src);
+/* these 2 would be easy to implement, but aren't really needed */
// void int_to_big(int i, bignum *b);
// void uint_to_big(unsigned int i, bignum *b);
+/* convert an unsigned long to a bignum */
extern void __fastcall__ ulong_to_big(const unsigned long l, bignump b);
-/* returns 0 for success, nonzero for fail (overflow or negative) */
+/* convert a bignum to an unsigned long
+ returns 0 for success, nonzero for fail (overflow or negative) */
extern char __fastcall__ big_to_ulong(bignump b, unsigned long *l);
-// extern unsigned long __fastcall__ cformat_big(char *magnitude, const bignum *b);
+/* compare two bignums. like Perl's spaceship operator, <=>
+ returns | if
+ ---------+----------------
+ 0 | a == b
+ positive| a > b
+ negative| a < b
+
+BEWARE: unlike perl's <=>, the return value is *not* guaranteed to
+ be 0, 1, or -1. This is more like C's strcmp() or memcmp().
+ 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. */
+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.
@@ -74,19 +94,7 @@ extern char __cdecl__ big_div(bignump dest, bignump dividend, bignump divisor);
*/
extern char __fastcall__ bank_maxed_out(bignump b);
-/* comparison. Perl spaceship operator, <=>
- returns | if
- ---------+----------------
- 0 | a == b
- positive| a > b
- negative| a < b
-
-BEWARE: unlike perl's <=>, the return value is *not* guaranteed to
- be 0, 1, or -1. This is more like C's strcmp() or memcmp().
- */
// signed char big_cmp(const bignum *a, const bignum *b)
-extern signed char __fastcall__ big_cmp(bignump a, bignump b);
-
extern unsigned long cformat_big(char *magnitude, bignump b);
extern void cprintfancy_big(bignump b);