api.odin 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package math_big
  2. /*
  3. Copyright 2021 Jeroen van Rijn <[email protected]>.
  4. Made available under Odin's BSD-2 license.
  5. An arbitrary precision mathematics implementation in Odin.
  6. For the theoretical underpinnings, see Knuth's The Art of Computer Programming, Volume 2, section 4.3.
  7. The code started out as an idiomatic source port of libTomMath, which is in the public domain, with thanks.
  8. This file collects public proc maps and their aliases.
  9. === === === === === === === === === === === === === === === === === === === === === === === ===
  10. Basic arithmetic.
  11. See `public.odin`.
  12. === === === === === === === === === === === === === === === === === === === === === === === ===
  13. */
  14. /*
  15. High-level addition. Handles sign.
  16. */
  17. add :: proc {
  18. /*
  19. int_add :: proc(dest, a, b: ^Int, allocator := context.allocator) -> (err: Error)
  20. */
  21. int_add,
  22. /*
  23. Adds the unsigned `DIGIT` immediate to an `Int`, such that the
  24. `DIGIT` doesn't have to be turned into an `Int` first.
  25. int_add_digit :: proc(dest, a: ^Int, digit: DIGIT, allocator := context.allocator) -> (err: Error)
  26. */
  27. int_add_digit,
  28. };
  29. /*
  30. err = sub(dest, a, b);
  31. */
  32. sub :: proc {
  33. /*
  34. int_sub :: proc(dest, a, b: ^Int) -> (err: Error)
  35. */
  36. int_sub,
  37. /*
  38. int_sub_digit :: proc(dest, a: ^Int, digit: DIGIT) -> (err: Error)
  39. */
  40. int_sub_digit,
  41. };
  42. /*
  43. === === === === === === === === === === === === === === === === === === === === === === === ===
  44. Comparisons.
  45. See `compare.odin`.
  46. === === === === === === === === === === === === === === === === === === === === === === === ===
  47. */
  48. is_initialized :: proc {
  49. /*
  50. int_is_initialized :: proc(a: ^Int) -> bool
  51. */
  52. int_is_initialized,
  53. };
  54. is_zero :: proc {
  55. /*
  56. int_is_zero :: proc(a: ^Int) -> bool
  57. */
  58. int_is_zero,
  59. };
  60. is_positive :: proc {
  61. /*
  62. int_is_positive :: proc(a: ^Int) -> bool
  63. */
  64. int_is_positive,
  65. };
  66. is_pos :: is_positive;
  67. is_negative :: proc {
  68. /*
  69. int_is_negative :: proc(a: ^Int) -> bool
  70. */
  71. int_is_negative,
  72. };
  73. is_neg :: is_negative;
  74. is_even :: proc {
  75. /*
  76. int_is_even :: proc(a: ^Int) -> bool
  77. */
  78. int_is_even,
  79. };
  80. is_odd :: proc {
  81. /*
  82. int_is_odd :: proc(a: ^Int) -> bool
  83. */
  84. int_is_odd,
  85. };
  86. is_power_of_two :: proc {
  87. /*
  88. platform_int_is_power_of_two :: proc(a: int) -> bool
  89. */
  90. platform_int_is_power_of_two,
  91. /*
  92. int_is_power_of_two :: proc(a: ^Int) -> (res: bool)
  93. */
  94. int_is_power_of_two,
  95. };
  96. compare :: proc {
  97. /*
  98. Compare two `Int`s, signed.
  99. int_compare :: proc(a, b: ^Int) -> Comparison_Flag
  100. */
  101. int_compare,
  102. /*
  103. Compare an `Int` to an unsigned number upto the size of the backing type.
  104. int_compare_digit :: proc(a: ^Int, u: DIGIT) -> Comparison_Flag
  105. */
  106. int_compare_digit,
  107. };
  108. cmp :: compare;
  109. compare_magnitude :: proc {
  110. /*
  111. Compare the magnitude of two `Int`s, unsigned.
  112. */
  113. int_compare_magnitude,
  114. };
  115. cmp_mag :: compare_magnitude;
  116. /*
  117. === === === === === === === === === === === === === === === === === === === === === === === ===
  118. Initialization and other helpers.
  119. See `helpers.odin`.
  120. === === === === === === === === === === === === === === === === === === === === === === === ===
  121. */
  122. destroy :: proc {
  123. /*
  124. Clears one or more `Int`s and dellocates their backing memory.
  125. int_destroy :: proc(integers: ..^Int)
  126. */
  127. int_destroy,
  128. };