Permalink
Browse files

Added bigIntToInt for (lossy) conversion

  • Loading branch information...
Edwin Brady
Edwin Brady committed Feb 23, 2012
1 parent 350a7ea commit 406a1041393c283ad31cf04fcd6f9cd499a388ed
Showing with 12 additions and 1 deletion.
  1. +1 −1 epic.cabal
  2. +10 −0 evm/stdfuns.c
  3. +1 −0 evm/stdfuns.h
View
@@ -1,5 +1,5 @@
Name: epic
-Version: 0.9.2
+Version: 0.9.2.1
Author: Edwin Brady
License: BSD3
License-file: LICENSE
View
@@ -383,6 +383,16 @@ void* intToBigInt(int x)
return MKINT(INTTOEINT(x));
}
+int bigIntToInt(void* big)
+{
+ // if it's overflowed, return 0
+ if (ISINT(big)) {
+ return GETINT(big);
+ } else {
+ return mpz_get_ui(*((mpz_t*)(GETBIGINT(big))));
+ }
+}
+
char* bigIntToStr(mpz_t x)
{
char* str = mpz_get_str(NULL,10,x);
View
@@ -65,6 +65,7 @@ double intToFloat(int x);
int floatToInt(double x);
void* intToBigInt(int x);
+int bigIntToInt(void* big);
mpz_t* strToBigInt(char* str);
char* bigIntToStr(mpz_t x);

0 comments on commit 406a104

Please sign in to comment.