Double.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2022-05-20
  7. *
  8. * */
  9. #include <cmath>
  10. #include <ls_std/boxing/Double.hpp>
  11. #include <ls_std/core/exception/IllegalArgumentException.hpp>
  12. ls::std::boxing::Double::Double() : ls::std::core::Class("Double")
  13. {
  14. this->_assignEpsilon(0.00000001);
  15. }
  16. ls::std::boxing::Double::Double(double _value)
  17. : ls::std::core::Class("Double"),
  18. value(_value)
  19. {
  20. this->_assignEpsilon(0.00000001);
  21. }
  22. ls::std::boxing::Double::operator double() const
  23. {
  24. return this->value;
  25. }
  26. ls::std::boxing::Double &ls::std::boxing::Double::operator=(double _value)
  27. {
  28. this->value = _value;
  29. return *this;
  30. }
  31. double ls::std::boxing::Double::operator-() const
  32. {
  33. return -this->value;
  34. }
  35. double ls::std::boxing::Double::operator+(const ls::std::boxing::Double &_double) const
  36. {
  37. return this->value + _double;
  38. }
  39. double ls::std::boxing::Double::operator+(double _value) const
  40. {
  41. return this->value + _value;
  42. }
  43. double ls::std::boxing::Double::operator*(const ls::std::boxing::Double &_double) const
  44. {
  45. return this->value * _double;
  46. }
  47. double ls::std::boxing::Double::operator*(double _value) const
  48. {
  49. return this->value * _value;
  50. }
  51. double ls::std::boxing::Double::operator-(const ls::std::boxing::Double &_double) const
  52. {
  53. return this->value - _double;
  54. }
  55. double ls::std::boxing::Double::operator-(double _value) const
  56. {
  57. return this->value - _value;
  58. }
  59. double ls::std::boxing::Double::operator/(const ls::std::boxing::Double &_double) const
  60. {
  61. return this->value / _double;
  62. }
  63. double ls::std::boxing::Double::operator/(double _value) const
  64. {
  65. return this->value / _value;
  66. }
  67. ls::std::boxing::Double &ls::std::boxing::Double::operator+=(const ls::std::boxing::Double &_double)
  68. {
  69. this->value += _double;
  70. return *this;
  71. }
  72. ls::std::boxing::Double &ls::std::boxing::Double::operator+=(double _value)
  73. {
  74. this->value += _value;
  75. return *this;
  76. }
  77. ls::std::boxing::Double &ls::std::boxing::Double::operator-=(const ls::std::boxing::Double &_double)
  78. {
  79. this->value -= _double;
  80. return *this;
  81. }
  82. ls::std::boxing::Double &ls::std::boxing::Double::operator-=(double _value)
  83. {
  84. this->value -= _value;
  85. return *this;
  86. }
  87. ls::std::boxing::Double &ls::std::boxing::Double::operator*=(const ls::std::boxing::Double &_double)
  88. {
  89. this->value *= _double;
  90. return *this;
  91. }
  92. ls::std::boxing::Double &ls::std::boxing::Double::operator*=(double _value)
  93. {
  94. this->value *= _value;
  95. return *this;
  96. }
  97. ls::std::boxing::Double &ls::std::boxing::Double::operator/=(const ls::std::boxing::Double &_double)
  98. {
  99. this->value /= _double;
  100. return *this;
  101. }
  102. ls::std::boxing::Double &ls::std::boxing::Double::operator/=(double _value)
  103. {
  104. this->value /= _value;
  105. return *this;
  106. }
  107. bool ls::std::boxing::Double::operator==(const ls::std::boxing::Double &_double) const
  108. {
  109. return ::std::fabs(this->value - _double) < this->epsilon;
  110. }
  111. bool ls::std::boxing::Double::operator==(double _value) const
  112. {
  113. return ::std::fabs(this->value - _value) < this->epsilon;
  114. }
  115. bool ls::std::boxing::Double::operator!=(const ls::std::boxing::Double &_double) const
  116. {
  117. return ::std::fabs(this->value - _double) >= this->epsilon;
  118. }
  119. bool ls::std::boxing::Double::operator!=(double _value) const
  120. {
  121. return ::std::fabs(this->value - _value) >= this->epsilon;
  122. }
  123. bool ls::std::boxing::Double::operator>(const ls::std::boxing::Double &_double) const
  124. {
  125. return this->value > _double;
  126. }
  127. bool ls::std::boxing::Double::operator>(double _value) const
  128. {
  129. return this->value > _value;
  130. }
  131. bool ls::std::boxing::Double::operator>=(const ls::std::boxing::Double &_double) const
  132. {
  133. return this->value >= _double;
  134. }
  135. bool ls::std::boxing::Double::operator>=(double _value) const
  136. {
  137. return this->value >= _value;
  138. }
  139. bool ls::std::boxing::Double::operator<(const ls::std::boxing::Double &_double) const
  140. {
  141. return this->value < _double;
  142. }
  143. bool ls::std::boxing::Double::operator<(double _value) const
  144. {
  145. return this->value < _value;
  146. }
  147. bool ls::std::boxing::Double::operator<=(const ls::std::boxing::Double &_double) const
  148. {
  149. return this->value <= _double;
  150. }
  151. bool ls::std::boxing::Double::operator<=(double _value) const
  152. {
  153. return this->value <= _value;
  154. }
  155. void ls::std::boxing::Double::operator++()
  156. {
  157. this->value += 1.0f;
  158. }
  159. void ls::std::boxing::Double::operator--()
  160. {
  161. this->value -= 1.0f;
  162. }
  163. void ls::std::boxing::Double::parse(::std::string _parseText)
  164. {
  165. this->value = ::std::stod(_parseText);
  166. }
  167. ::std::string ls::std::boxing::Double::toString()
  168. {
  169. return ::std::to_string(this->value);
  170. }
  171. double ls::std::boxing::Double::getEpsilon()
  172. {
  173. return this->epsilon;
  174. }
  175. double ls::std::boxing::Double::getValue()
  176. {
  177. return this->value;
  178. }
  179. void ls::std::boxing::Double::setEpsilon(double _epsilon)
  180. {
  181. this->_assignEpsilon(_epsilon);
  182. }
  183. void ls::std::boxing::Double::_assignEpsilon(double _epsilon)
  184. {
  185. if (_epsilon <= 0.0)
  186. {
  187. throw ls::std::core::IllegalArgumentException{};
  188. }
  189. this->epsilon = _epsilon;
  190. }