Float.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2020-08-16
  7. *
  8. * */
  9. #include <cmath>
  10. #include "Float.hpp"
  11. ls_std::Float::Float() : Class("Float"),
  12. epsilon(0.00001f)
  13. {}
  14. ls_std::Float::Float(float _value) : Class("Float"),
  15. epsilon(0.00001f),
  16. value(_value)
  17. {}
  18. ls_std::Float::operator float() const {
  19. return this->value;
  20. }
  21. ls_std::Float & ls_std::Float::operator=(float _value) {
  22. this->value = _value;
  23. return *this;
  24. }
  25. float ls_std::Float::operator-() const {
  26. return -this->value;
  27. }
  28. float ls_std::Float::operator+(const Float &_float) const {
  29. return this->value + _float;
  30. }
  31. float ls_std::Float::operator+(float _value) const {
  32. return this->value + _value;
  33. }
  34. float ls_std::Float::operator*(const Float &_float) const {
  35. return this->value * _float;
  36. }
  37. float ls_std::Float::operator*(float _value) const {
  38. return this->value * _value;
  39. }
  40. float ls_std::Float::operator-(const Float &_float) const {
  41. return this->value - _float;
  42. }
  43. float ls_std::Float::operator-(float _value) const {
  44. return this->value - _value;
  45. }
  46. float ls_std::Float::operator/(const Float &_float) const {
  47. return this->value / _float;
  48. }
  49. float ls_std::Float::operator/(float _value) const {
  50. return this->value / _value;
  51. }
  52. ls_std::Float & ls_std::Float::operator+=(const Float &_float) {
  53. this->value += _float;
  54. return *this;
  55. }
  56. ls_std::Float & ls_std::Float::operator+=(float _value) {
  57. this->value += _value;
  58. return *this;
  59. }
  60. ls_std::Float & ls_std::Float::operator-=(const Float &_float) {
  61. this->value -= _float;
  62. return *this;
  63. }
  64. ls_std::Float & ls_std::Float::operator-=(float _value) {
  65. this->value -= _value;
  66. return *this;
  67. }
  68. ls_std::Float & ls_std::Float::operator*=(const Float &_float) {
  69. this->value *= _float;
  70. return *this;
  71. }
  72. ls_std::Float & ls_std::Float::operator*=(float _value) {
  73. this->value *= _value;
  74. return *this;
  75. }
  76. ls_std::Float & ls_std::Float::operator/=(const Float &_float) {
  77. this->value /= _float;
  78. return *this;
  79. }
  80. ls_std::Float & ls_std::Float::operator/=(float _value) {
  81. this->value /= _value;
  82. return *this;
  83. }
  84. bool ls_std::Float::operator==(const Float &_float) const {
  85. return std::fabs(this->value - _float) < this->epsilon;
  86. }
  87. bool ls_std::Float::operator==(float _value) const {
  88. return std::fabs(this->value - _value) < this->epsilon;
  89. }
  90. bool ls_std::Float::operator!=(const Float &_float) const {
  91. return std::fabs(this->value - _float) >= this->epsilon;
  92. }
  93. bool ls_std::Float::operator!=(float _value) const {
  94. return std::fabs(this->value - _value) >= this->epsilon;
  95. }
  96. bool ls_std::Float::operator>(const Float &_float) const {
  97. return this->value > _float;
  98. }
  99. bool ls_std::Float::operator>(float _value) const {
  100. return this->value > _value;
  101. }
  102. bool ls_std::Float::operator>=(const Float &_float) const {
  103. return this->value >= _float;
  104. }
  105. bool ls_std::Float::operator>=(float _value) const {
  106. return this->value >= _value;
  107. }
  108. bool ls_std::Float::operator<(const Float &_float) const {
  109. return this->value < _float;
  110. }
  111. bool ls_std::Float::operator<(float _value) const {
  112. return this->value < _value;
  113. }
  114. bool ls_std::Float::operator<=(const Float &_float) const {
  115. return this->value <= _float;
  116. }
  117. bool ls_std::Float::operator<=(float _value) const {
  118. return this->value <= _value;
  119. }
  120. void ls_std::Float::operator++() {
  121. this->value += 1.0f;
  122. }
  123. void ls_std::Float::operator--() {
  124. this->value -= 1.0f;
  125. }
  126. void ls_std::Float::parse(std::string _parseText) {
  127. this->value = std::stof(_parseText);
  128. }
  129. std::string ls_std::Float::toString() {
  130. return std::to_string(this->value);
  131. }
  132. float ls_std::Float::getEpsilon() {
  133. return this->epsilon;
  134. }
  135. float ls_std::Float::getValue() {
  136. return this->value;
  137. }
  138. void ls_std::Float::setEpsilon(float _epsilon) {
  139. this->epsilon = _epsilon;
  140. }