CMath.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /////////////// CDivisionWarning.proto ///////////////
  2. static int __Pyx_cdivision_warning(const char *, int); /* proto */
  3. /////////////// CDivisionWarning ///////////////
  4. static int __Pyx_cdivision_warning(const char *filename, int lineno) {
  5. #if CYTHON_COMPILING_IN_PYPY
  6. // avoid compiler warnings
  7. filename++; lineno++;
  8. return PyErr_Warn(PyExc_RuntimeWarning,
  9. "division with oppositely signed operands, C and Python semantics differ");
  10. #else
  11. return PyErr_WarnExplicit(PyExc_RuntimeWarning,
  12. "division with oppositely signed operands, C and Python semantics differ",
  13. filename,
  14. lineno,
  15. __Pyx_MODULE_NAME,
  16. NULL);
  17. #endif
  18. }
  19. /////////////// DivInt.proto ///////////////
  20. static CYTHON_INLINE %(type)s __Pyx_div_%(type_name)s(%(type)s, %(type)s); /* proto */
  21. /////////////// DivInt ///////////////
  22. static CYTHON_INLINE %(type)s __Pyx_div_%(type_name)s(%(type)s a, %(type)s b) {
  23. %(type)s q = a / b;
  24. %(type)s r = a - q*b;
  25. q -= ((r != 0) & ((r ^ b) < 0));
  26. return q;
  27. }
  28. /////////////// ModInt.proto ///////////////
  29. static CYTHON_INLINE %(type)s __Pyx_mod_%(type_name)s(%(type)s, %(type)s); /* proto */
  30. /////////////// ModInt ///////////////
  31. static CYTHON_INLINE %(type)s __Pyx_mod_%(type_name)s(%(type)s a, %(type)s b) {
  32. %(type)s r = a %% b;
  33. r += ((r != 0) & ((r ^ b) < 0)) * b;
  34. return r;
  35. }
  36. /////////////// ModFloat.proto ///////////////
  37. static CYTHON_INLINE %(type)s __Pyx_mod_%(type_name)s(%(type)s, %(type)s); /* proto */
  38. /////////////// ModFloat ///////////////
  39. static CYTHON_INLINE %(type)s __Pyx_mod_%(type_name)s(%(type)s a, %(type)s b) {
  40. %(type)s r = fmod%(math_h_modifier)s(a, b);
  41. r += ((r != 0) & ((r < 0) ^ (b < 0))) * b;
  42. return r;
  43. }
  44. /////////////// IntPow.proto ///////////////
  45. static CYTHON_INLINE %(type)s %(func_name)s(%(type)s, %(type)s); /* proto */
  46. /////////////// IntPow ///////////////
  47. static CYTHON_INLINE %(type)s %(func_name)s(%(type)s b, %(type)s e) {
  48. %(type)s t = b;
  49. switch (e) {
  50. case 3:
  51. t *= b;
  52. CYTHON_FALLTHROUGH;
  53. case 2:
  54. t *= b;
  55. CYTHON_FALLTHROUGH;
  56. case 1:
  57. return t;
  58. case 0:
  59. return 1;
  60. }
  61. #if %(signed)s
  62. if (unlikely(e<0)) return 0;
  63. #endif
  64. t = 1;
  65. while (likely(e)) {
  66. t *= (b * (e&1)) | ((~e)&1); /* 1 or b */
  67. b *= b;
  68. e >>= 1;
  69. }
  70. return t;
  71. }