integer.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * This file is part of Gomu.
  3. *
  4. * Copyright 2016 by Jean Fromentin <jean.fromentin@math.cnrs.fr>
  5. *
  6. * Gomu is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Gomu is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Gomu. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "integer.hpp"
  20. //------------------------------
  21. // Integer add(Integer,Integer)
  22. //------------------------------
  23. void* integer_add(void* a,void* b){
  24. fmpz* res=new fmpz;
  25. fmpz_init(res);
  26. fmpz_add(res,(fmpz*)a,(fmpz*)b);
  27. return (void*)res;
  28. }
  29. //------------------------------
  30. // Integer mul(Integer,Integer)
  31. //------------------------------
  32. void* integer_mul(void* a,void* b){
  33. fmpz* res=new fmpz;
  34. fmpz_init(res);
  35. fmpz_mul(res,(fmpz*)a,(fmpz*)b);
  36. return (void*)res;
  37. }
  38. //-------------------------
  39. // Integer negate(Integer)
  40. //-------------------------
  41. void* integer_negate(void* a){
  42. fmpz* res=new fmpz;
  43. fmpz_init(res);
  44. fmpz_neg(res,(fmpz*)a);
  45. return (void*)res;
  46. }
  47. //------------------------------
  48. // Integer quo(Integer,Integer)
  49. //------------------------------
  50. void* integer_quo(void* a,void* b){
  51. fmpz* res=new fmpz;
  52. fmpz_init(res);
  53. fmpz_fdiv_q(res,(fmpz*)a,(fmpz*)b);
  54. return (void*)res;
  55. }
  56. //------------------------------
  57. // Integer rem(Integer,Integer)
  58. //------------------------------
  59. void* integer_rem(void* a,void* b){
  60. fmpz* res=new fmpz;
  61. fmpz_init(res);
  62. fmpz_fdiv_r(res,(fmpz*)a,(fmpz*)b);
  63. return (void*)res;
  64. }
  65. //------------------------------
  66. // Integer sub(Integer,Integer)
  67. //------------------------------
  68. void* integer_sub(void* a,void* b){
  69. fmpz* res=new fmpz;
  70. fmpz_init(res);
  71. fmpz_sub(res,(fmpz*)a,(fmpz*)b);
  72. return (void*)res;
  73. }