1. /* sninline.h by K.Tsuru */
  2. #ifndef SN_INLINE_H
  3. #define SN_INLINE_H
  4. /***************************************************************
  5. inline functions comparing operator for SLong and SDouble
  6. neither not member nor friend functions.
  7. Note that XXCompare(m, n) for |m| and |n|.
  8. ****************************************************************/
  9. /*****************************
  10. operator for SLong class
  11. ******************************/
  12. // Return values are changed "int" to "bool" type. ver.2.17
  13. // relational operator
  14. // LLCompare(m, n) = sgn(|m| - |n|)
  15. inline bool operator>(const SLong& m, const SLong& n){
  16. if(m.Sign() != n.Sign()) return m.Sign() > n.Sign();
  17. return (LLCompare(m, n) * m.Sign()) > 0;
  18. }
  19. inline bool operator<(const SLong& m, const SLong& n){
  20. if(m.Sign() != n.Sign()) return m.Sign() < n.Sign();
  21. return (LLCompare(m, n) * m.Sign()) < 0;
  22. }
  23. inline bool operator==(const SLong& m, const SLong& n){
  24. if(m.Sign() != n.Sign()) return false; // ver. 2.17
  25. return LLCompare(m, n) == 0;
  26. }
  27. inline bool operator!=(const SLong& m, const SLong& n){
  28. return !(m == n);
  29. }
  30. inline bool operator>=(const SLong& m, const SLong& n){
  31. if(m.Sign() != n.Sign()) return m.Sign() > n.Sign();
  32. return (LLCompare(m, n) * m.Sign()) >= 0;
  33. // return (m > n) || (m == n); LLCompare() is called twice.
  34. }
  35. inline bool operator<=(const SLong& m, const SLong& n){
  36. if(m.Sign() != n.Sign()) return m.Sign() < n.Sign();
  37. return (LLCompare(m, n) * m.Sign()) <= 0;
  38. // return (m < n) || (m == n);
  39. }
  40. inline bool operator==(const Ldiv_t& m, const Ldiv_t& n){
  41. return (m.quot == n.quot) && (m.rem == n.rem);
  42. }
  43. inline bool operator!=(const Ldiv_t& m, const Ldiv_t& n){
  44. return !(m == n);
  45. }
  46. /*****************************
  47. operator for SDouble class
  48. ******************************/
  49. // relational operator
  50. inline bool operator>(const SDouble& m, const SDouble& n){
  51. if(m.Sign() != n.Sign()) return m.Sign() > n.Sign();
  52. return (DDCompare(m, n) * m.Sign()) > 0;
  53. }
  54. inline bool operator<(const SDouble& m, const SDouble& n){
  55. if(m.Sign() != n.Sign()) return m.Sign() < n.Sign();
  56. return (DDCompare(m, n) * m.Sign()) < 0;
  57. }
  58. inline bool operator==(const SDouble& m, const SDouble& n){
  59. if(m.Sign() != n.Sign()) return false; // ver. 2.17
  60. return DDCompare(m, n) == 0;
  61. }
  62. inline bool operator!=(const SDouble& m, const SDouble& n){
  63. return !(m == n);
  64. }
  65. inline bool operator>=(const SDouble& m, const SDouble& n){
  66. if(m.Sign() != n.Sign()) return m.Sign() > n.Sign();
  67. return (DDCompare(m, n) * m.Sign()) >= 0;
  68. // return (m > n) || (m == n);
  69. }
  70. inline bool operator<=(const SDouble& m, const SDouble& n){
  71. if(m.Sign() != n.Sign()) return m.Sign() < n.Sign();
  72. return (DDCompare(m, n) * m.Sign()) <= 0;
  73. // return (m < n) || (m == n);
  74. }
  75. // returns ceil( log10(x) ) ver.2.18
  76. inline long CeilLog10(const SLong& x) {
  77. return x.DFigures();
  78. }
  79. inline long CeilLog10(const SDouble& x) {
  80. return x.DExp();
  81. }
  82. /***************************************
  83. logical functions for SNumber class
  84. derived classes can use
  85. ***************************************/
  86. inline bool operator||(const SNumber& m, const SNumber& n){
  87. return (m.Sign() || n.Sign());
  88. }
  89. inline bool operator&&(const SNumber& m, const SNumber& n){
  90. return (m.Sign() && n.Sign());
  91. }
  92. inline bool operator!(const SNumber& m){ return !m.Sign(); }
  93. #endif // SN_INLINE_H

sninline.h : last modifiled at 2016/01/08 14:40:46(3,371 bytes)
created at 2016/04/11 11:18:59
The creation time of this html file is 2017/10/11 16:07:52 (Wed Oct 11 16:07:52 2017).