Double.cpp 5.0 KB

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