You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

  1. #include "<%=name.toLowerCase()+".h"%>"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <gmp.h>
  5. void <%=name%>_str2element(P<%=name%>Element pE, char *s) {
  6. mpz_t r;
  7. mpz_init(r);
  8. mpz_set_str(r, s, 10);
  9. pE->type = <%=name%>_LONG;
  10. for (int i=0; i<<%=name%>_N64; i++) pE->longVal[i] = 0;
  11. mpz_export((void *)pE->longVal, NULL, -1, 8, -1, 0, r);
  12. }
  13. char *<%=name%>_element2str(P<%=name%>Element pE) {
  14. mpz_t r;
  15. mpz_t q;
  16. if (pE->type == <%=name%>_SHORT) {
  17. if (pE->shortVal>=0) {
  18. char *r = new char[32];
  19. sprintf(r, "%d", pE->shortVal);
  20. return r;
  21. } else {
  22. mpz_init(q);
  23. mpz_import(q, <%=name%>_N64, -1, 8, -1, 0, (const void *)Fr_q.longVal);
  24. mpz_init_set_si(r, pE->shortVal);
  25. mpz_add(r, r, q);
  26. mpz_clear(q);
  27. }
  28. } else {
  29. <%=name%>_toNormal(pE);
  30. mpz_init(r);
  31. mpz_import(r, <%=name%>_N64, -1, 8, -1, 0, (const void *)pE->longVal);
  32. }
  33. char *res = mpz_get_str (0, 10, r);
  34. mpz_clear(r);
  35. return res;
  36. }