NewLang Project
Yet another programm language
Loading...
Searching...
No Matches
newlang::Rational Class Reference

#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< Rationalclone () const
 
std::string GetAsString () const
 
int64_t GetAsBoolean () const
 
int64_t GetAsInteger () const
 
double GetAsNumber () const
 
void reduce ()
 
Rationalset_ (const int64_t value)
 
Rationalset_ (const Rational &copy)
 
Rationalset_ (const std::string_view numerator, const std::string_view denominator)
 
Rationaloperator*= (const Rational &rational)
 
Rationaloperator/= (const Rational &rational)
 
Rationaloperator-= (const Rational &rational)
 
Rationaloperator+= (const Rational &rational)
 
Rationaloperator%= (const Rational &rational)
 
Rationaloperator^= (const Rational &)
 
Rationaloperator|= (const Rational &)
 
Rationalop_lshift_set (const Rational &)
 
Rationalop_rshift_set (const Rational &)
 
Rationalop_pow_ (const Rational &rational)
 
Rationalop_div_ceil_ (Rational &rational)
 
const Rationalop_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
 

Detailed Description

Definition at line 54 of file rational.h.

Constructor & Destructor Documentation

◆ Rational() [1/3]

Rational::Rational ( )

Definition at line 208 of file rational.cpp.

◆ Rational() [2/3]

Rational::Rational ( const int64_t value)

Definition at line 211 of file rational.cpp.

References set_().

◆ Rational() [3/3]

Rational::Rational ( const std::string_view numerator,
const std::string_view denominator )

Definition at line 219 of file rational.cpp.

References set_().

Member Function Documentation

◆ clone()

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().

◆ GetAsString()

std::string Rational::GetAsString ( ) const

◆ GetAsBoolean()

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().

◆ GetAsInteger()

◆ GetAsNumber()

double Rational::GetAsNumber ( ) const

◆ reduce()

◆ set_() [1/3]

Rational & Rational::set_ ( const int64_t value)

◆ set_() [2/3]

Rational & Rational::set_ ( const Rational & copy)

Definition at line 300 of file rational.cpp.

References m_denominator, m_numerator, and newlang::BigNum::set_().

◆ set_() [3/3]

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().

◆ operator*=()

Rational & Rational::operator*= ( const Rational & rational)

Definition at line 314 of file rational.cpp.

References m_denominator, m_numerator, newlang::BigNum::mul(), and reduce().

◆ operator/=()

Rational & Rational::operator/= ( const Rational & rational)

Definition at line 322 of file rational.cpp.

References m_denominator, m_numerator, newlang::BigNum::mul(), and reduce().

◆ operator-=()

Rational & Rational::operator-= ( const Rational & rational)

◆ operator+=()

Rational & Rational::operator+= ( const Rational & rational)

◆ operator%=()

Rational & Rational::operator%= ( const Rational & rational)

Definition at line 359 of file rational.cpp.

References LOG_RUNTIME.

◆ operator^=()

Rational & Rational::operator^= ( const Rational & )

Definition at line 365 of file rational.cpp.

References LOG_RUNTIME.

◆ operator|=()

Rational & Rational::operator|= ( const Rational & )

Definition at line 371 of file rational.cpp.

References LOG_RUNTIME.

◆ op_lshift_set()

Rational & Rational::op_lshift_set ( const Rational & )

Definition at line 376 of file rational.cpp.

References LOG_RUNTIME.

◆ op_rshift_set()

Rational & Rational::op_rshift_set ( const Rational & )

Definition at line 382 of file rational.cpp.

References LOG_RUNTIME.

◆ op_pow_()

Rational & Rational::op_pow_ ( const Rational & rational)

Definition at line 394 of file rational.cpp.

References LOG_RUNTIME.

Referenced by newlang::Obj::op_pow_().

◆ op_div_ceil_()

Rational & Rational::op_div_ceil_ ( Rational & rational)

Definition at line 425 of file rational.cpp.

References LOG_RUNTIME.

Referenced by newlang::Obj::op_div_ceil_().

◆ op_rrshift_set()

const Rational & Rational::op_rrshift_set ( const Rational & )

Definition at line 388 of file rational.cpp.

References LOG_RUNTIME.

◆ op_equal()

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().

◆ op_compare()

int Rational::op_compare ( const Rational & rational) const

Member Data Documentation

◆ m_numerator

◆ m_denominator

BigNum newlang::Rational::m_denominator

The documentation for this class was generated from the following files: