NewLang Project
Yet another programm language
|
#include <rational.h>
Public Member Functions | |
Rational () | |
Rational (const int64_t value) | |
Rational (const std::string_view numerator, const std::string_view denominator) | |
std::shared_ptr< Rational > | clone () const |
std::string | GetAsString () const |
int64_t | GetAsBoolean () const |
int64_t | GetAsInteger () const |
double | GetAsNumber () const |
void | reduce () |
Rational & | set_ (const int64_t value) |
Rational & | set_ (const Rational ©) |
Rational & | set_ (const std::string_view numerator, const std::string_view denominator) |
Rational & | operator*= (const Rational &rational) |
Rational & | operator/= (const Rational &rational) |
Rational & | operator-= (const Rational &rational) |
Rational & | operator+= (const Rational &rational) |
Rational & | operator%= (const Rational &rational) |
Rational & | operator^= (const Rational &) |
Rational & | operator|= (const Rational &) |
Rational & | op_lshift_set (const Rational &) |
Rational & | op_rshift_set (const Rational &) |
Rational & | op_pow_ (const Rational &rational) |
Rational & | op_div_ceil_ (Rational &rational) |
const Rational & | op_rrshift_set (const Rational &) |
bool | op_equal (const Rational &rational) const |
int | op_compare (const Rational &rational) const |
Public Attributes | |
BigNum | m_numerator |
BigNum | m_denominator |
Definition at line 54 of file rational.h.
Rational::Rational | ( | ) |
Definition at line 208 of file rational.cpp.
Rational::Rational | ( | const int64_t | value | ) |
Definition at line 211 of file rational.cpp.
References set_().
Rational::Rational | ( | const std::string_view | numerator, |
const std::string_view | denominator ) |
Definition at line 219 of file rational.cpp.
References set_().
std::shared_ptr< Rational > Rational::clone | ( | ) | const |
Definition at line 223 of file rational.cpp.
References result.
Referenced by newlang::Obj::CloneDataTo(), and newlang::Obj::GetValueAsRational().
std::string Rational::GetAsString | ( | ) | const |
Definition at line 229 of file rational.cpp.
References newlang::BigNum::GetAsString(), m_denominator, m_numerator, and result.
Referenced by newlang::Obj::GetValueAsString(), and newlang::Obj::toString().
int64_t Rational::GetAsBoolean | ( | ) | const |
Definition at line 237 of file rational.cpp.
References newlang::BigNum::isZero(), and m_numerator.
Referenced by newlang::Obj::GetValueAsBoolean().
int64_t Rational::GetAsInteger | ( | ) | const |
Definition at line 242 of file rational.cpp.
References newlang::BigNum::div(), newlang::BigNum::GetAsInteger(), newlang::BigNum::isOne(), newlang::BigNum::isZero(), LOG_RUNTIME, m_denominator, m_numerator, and result.
Referenced by newlang::Obj::GetValueAsInteger().
double Rational::GetAsNumber | ( | ) | const |
Definition at line 259 of file rational.cpp.
References newlang::BigNum::GetAsNumber(), newlang::BigNum::isOne(), newlang::BigNum::isZero(), LOG_RUNTIME, m_denominator, and m_numerator.
Referenced by newlang::Obj::GetValueAsNumber().
void Rational::reduce | ( | ) |
Definition at line 272 of file rational.cpp.
References ASSERT, newlang::BigNum::CtxHelper::ctx, newlang::BigNum::div(), newlang::BigNum::isZero(), LOG_RUNTIME, m_denominator, m_numerator, and newlang::BigNum::value.
Referenced by operator*=(), operator+=(), operator-=(), and operator/=().
Rational & Rational::set_ | ( | const int64_t | value | ) |
Definition at line 288 of file rational.cpp.
References m_denominator, m_numerator, and newlang::BigNum::value.
Referenced by newlang::Obj::clear_(), Rational(), Rational(), and newlang::Obj::SetValue_().
Definition at line 300 of file rational.cpp.
References m_denominator, m_numerator, and newlang::BigNum::set_().
Rational & Rational::set_ | ( | const std::string_view | numerator, |
const std::string_view | denominator ) |
Definition at line 307 of file rational.cpp.
References m_denominator, m_numerator, and newlang::BigNum::SetFromString().
Definition at line 314 of file rational.cpp.
References m_denominator, m_numerator, newlang::BigNum::mul(), and reduce().
Definition at line 322 of file rational.cpp.
References m_denominator, m_numerator, newlang::BigNum::mul(), and reduce().
Definition at line 330 of file rational.cpp.
References m_denominator, m_numerator, newlang::BigNum::mul(), reduce(), and newlang::BigNum::sub().
Definition at line 345 of file rational.cpp.
References newlang::BigNum::add(), m_denominator, m_numerator, newlang::BigNum::mul(), and reduce().
Definition at line 359 of file rational.cpp.
References LOG_RUNTIME.
Definition at line 365 of file rational.cpp.
References LOG_RUNTIME.
Definition at line 371 of file rational.cpp.
References LOG_RUNTIME.
Definition at line 376 of file rational.cpp.
References LOG_RUNTIME.
Definition at line 382 of file rational.cpp.
References LOG_RUNTIME.
Definition at line 394 of file rational.cpp.
References LOG_RUNTIME.
Referenced by newlang::Obj::op_pow_().
Definition at line 425 of file rational.cpp.
References LOG_RUNTIME.
Referenced by newlang::Obj::op_div_ceil_().
Definition at line 388 of file rational.cpp.
References LOG_RUNTIME.
bool Rational::op_equal | ( | const Rational & | rational | ) | const |
Definition at line 400 of file rational.cpp.
References m_denominator, m_numerator, and newlang::BigNum::value.
Referenced by newlang::Obj::op_equal().
int Rational::op_compare | ( | const Rational & | rational | ) | const |
Definition at line 406 of file rational.cpp.
References ASSERT, m_denominator, m_numerator, newlang::BigNum::set_(), and newlang::BigNum::value.
Referenced by newlang::VariableOp::__eq__(), and newlang::Obj::op_compare().
BigNum newlang::Rational::m_numerator |
Definition at line 57 of file rational.h.
Referenced by GetAsBoolean(), GetAsInteger(), GetAsNumber(), GetAsString(), op_compare(), op_equal(), operator*=(), operator+=(), operator-=(), operator/=(), reduce(), set_(), set_(), and set_().
BigNum newlang::Rational::m_denominator |
Definition at line 58 of file rational.h.
Referenced by GetAsInteger(), GetAsNumber(), GetAsString(), op_compare(), op_equal(), operator*=(), operator+=(), operator-=(), operator/=(), reduce(), set_(), set_(), and set_().