code_junkie

How does one calculate 2 ^ -18 using GMP?

Nov 13th, 2011
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. void mpz_powm (mpz_t rop, mpz_t base, mpz_t exp, mpz_t mod)
  2. void mpz_powm_ui (mpz_t rop, mpz_t base, unsigned long int exp, mpz_t mod)
  3. Set _rop_ to _base_^_exp_ mod _mod_.
  4. Negative exp is supported if an inverse base-1 mod mod exists (see mpz_invert in Section 5.9 [Number Theoretic Functions], page 35). If an inverse doesn’t exist then a divide by zero is raised.
  5.  
  6. #define Z(x) mpz_t x; mpz_init( x );
  7.  
  8. BSTR __stdcall IBIGPOWER(BSTR p1, long p2 ) {
  9. USES_CONVERSION;
  10.  
  11. Z(n1);
  12. Z(res);
  13.  
  14. LPSTR sNum1 = W2A( p1 );
  15.  
  16. mpz_set_str( n1, sNum1, 10 );
  17.  
  18. mpz_pow_ui( res, n1, p2 );
  19.  
  20. char * buff = (char *) _alloca( mpz_sizeinbase( res, 10 ) + 2 );
  21.  
  22. mpz_get_str(buff, 10, res);
  23.  
  24. BSTR bResult = _com_util::ConvertStringToBSTR( buff );
  25. return bResult;
  26. }
  27.  
  28. 2 ^ -18
  29.  
  30. 1 / (2 ^ 18)
Add Comment
Please, Sign In to add comment