api.odin 3.3 KB

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