123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2020-08-14
- * Changed: 2023-02-23
- *
- * */
- #include <cmath>
- #include <ls-std/boxing/Float.hpp>
- #include <ls-std/core/exception/IllegalArgumentException.hpp>
- using ls::std::boxing::Float;
- using ls::std::core::Class;
- using ls::std::core::IllegalArgumentException;
- using std::fabs;
- using std::stof;
- using std::string;
- using std::to_string;
- Float::Float() : Class("Float"), epsilon(0.00001f)
- {}
- Float::Float(float _value) : Float()
- {
- this->value = _value;
- }
- Float::~Float() noexcept = default;
- Float &Float::operator=(float _value)
- {
- this->value = _value;
- return *this;
- }
- float Float::operator-() const
- {
- return -this->value;
- }
- float Float::operator+(const Float &_float) const
- {
- return this->value + _float.getValue();
- }
- float Float::operator+(float _value) const
- {
- return this->value + _value;
- }
- float Float::operator*(const Float &_float) const
- {
- return this->value * _float.getValue();
- }
- float Float::operator*(float _value) const
- {
- return this->value * _value;
- }
- float Float::operator-(const Float &_float) const
- {
- return this->value - _float.getValue();
- }
- float Float::operator-(float _value) const
- {
- return this->value - _value;
- }
- float Float::operator/(const Float &_float) const
- {
- return this->value / _float.getValue();
- }
- float Float::operator/(float _value) const
- {
- return this->value / _value;
- }
- Float &Float::operator+=(const Float &_float)
- {
- this->value += _float.getValue();
- return *this;
- }
- Float &Float::operator+=(float _value)
- {
- this->value += _value;
- return *this;
- }
- Float &Float::operator-=(const Float &_float)
- {
- this->value -= _float.getValue();
- return *this;
- }
- Float &Float::operator-=(float _value)
- {
- this->value -= _value;
- return *this;
- }
- Float &Float::operator*=(const Float &_float)
- {
- this->value *= _float.getValue();
- return *this;
- }
- Float &Float::operator*=(float _value)
- {
- this->value *= _value;
- return *this;
- }
- Float &Float::operator/=(const Float &_float)
- {
- this->value /= _float.getValue();
- return *this;
- }
- Float &Float::operator/=(float _value)
- {
- this->value /= _value;
- return *this;
- }
- bool Float::operator==(const Float &_float) const
- {
- return fabs(this->value - _float.getValue()) < this->epsilon;
- }
- bool Float::operator==(float _value) const
- {
- return fabs(this->value - _value) < this->epsilon;
- }
- bool Float::operator!=(const Float &_float) const
- {
- return fabs(this->value - _float.getValue()) >= this->epsilon;
- }
- bool Float::operator!=(float _value) const
- {
- return fabs(this->value - _value) >= this->epsilon;
- }
- bool Float::operator>(const Float &_float) const
- {
- return this->value > _float.getValue();
- }
- bool Float::operator>(float _value) const
- {
- return this->value > _value;
- }
- bool Float::operator>=(const Float &_float) const
- {
- return this->value >= _float.getValue();
- }
- bool Float::operator>=(float _value) const
- {
- return this->value >= _value;
- }
- bool Float::operator<(const Float &_float) const
- {
- return this->value < _float.getValue();
- }
- bool Float::operator<(float _value) const
- {
- return this->value < _value;
- }
- bool Float::operator<=(const Float &_float) const
- {
- return this->value <= _float.getValue();
- }
- bool Float::operator<=(float _value) const
- {
- return this->value <= _value;
- }
- void Float::operator++()
- {
- this->value += 1.0f;
- }
- void Float::operator--()
- {
- this->value -= 1.0f;
- }
- void Float::parse(string _parseText)
- {
- this->value = stof(_parseText);
- }
- string Float::toString()
- {
- return to_string(this->value);
- }
- float Float::getEpsilon() const
- {
- return this->epsilon;
- }
- float Float::getValue() const
- {
- return this->value;
- }
- void Float::setEpsilon(float _epsilon)
- {
- this->_assignEpsilon(_epsilon);
- }
- void Float::_assignEpsilon(float _epsilon)
- {
- if (_epsilon <= 0.0)
- {
- throw IllegalArgumentException{"epsilon is less than or equal zero"};
- }
- this->epsilon = _epsilon;
- }
|