Big Numbers.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Perform big number arithmetic through BN_prodMod
  2. #define USE_TI89 // Compile for TI-89
  3. #define USE_TI92PLUS // Compile for TI-92 Plus
  4. #define USE_V200 // Compile for V200
  5. #define OPTIMIZE_ROM_CALLS // Use ROM Call Optimization
  6. #define MIN_AMS 101 // Compile for AMS 1.01 or higher
  7. #define SAVE_SCREEN // Save/Restore LCD Contents
  8. #define RETURN_VALUE // Return a Value
  9. #include <tigcclib.h> // Include All Header Files
  10. #define GetBignumArg(ap, bn) \
  11. ({unsigned char __n = *--(unsigned char*)(ap); \
  12. char *__p = (char*)(bn) + __n; \
  13. (bn)->Len = __n; \
  14. while (__n--) *__p-- = *--(ap); \
  15. (void)*(ap)--; })
  16. void push_Bignum(BN *bn)
  17. {
  18. unsigned m, n = bn->Len;
  19. char *p = (char*)bn;
  20. m = n;
  21. while (n--) push_quantum (*++p);
  22. push_quantum_pair (m, POSINT_TAG);
  23. }
  24. void _main(void)
  25. {
  26. ESI argptr = top_estack;
  27. BN *a = malloc (256), *b = malloc (256), *c = malloc (256);
  28. GetBignumArg (argptr, a);
  29. GetBignumArg (argptr, b);
  30. GetBignumArg (argptr, c);
  31. while (GetArgType (top_estack) != END_TAG) // Clean up arguments
  32. top_estack = next_expression_index (top_estack);
  33. top_estack--;
  34. BN_prodMod (a, b, c);
  35. push_Bignum (a);
  36. free (a); free (b); free (c);
  37. }