Double.cpp 5.1 KB

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