#include <number_impl.hpp>
Public Member Functions | |
number_rational (rational< long > value) | |
number_rational (long num) | |
number_rational (long num, long den) | |
rational< long > | value () const |
virtual number_impl * | promote_to_void () |
virtual number_impl * | promote_to_double () |
Private Member Functions | |
virtual std::string | do_to_string () const |
virtual void | do_save (std::ostream &stream) const |
virtual bool | do_equals (number_impl const &rhs) const |
virtual bool | do_less (number_impl const &rhs) const |
virtual number_impl * | do_add (number_impl const &rhs) |
virtual number_impl * | do_subtract (number_impl const &rhs) |
virtual number_impl * | do_multiply (number_impl const &rhs) |
virtual number_impl * | do_divide (number_impl const &rhs) |
virtual number_impl * | do_promote (number_impl &rhs) const |
Private Attributes | |
rational< long > | value_ |
long
to represent the numerator and denominator.
Definition at line 119 of file number_impl.hpp.
number_rational::number_rational | ( | rational< long > | value | ) | [inline] |
Definition at line 121 of file number_impl.hpp.
Referenced by do_add(), do_divide(), do_multiply(), and do_subtract().
00121 : number_impl(), value_(value) {}
number_rational::number_rational | ( | long | num | ) | [inline] |
number_rational::number_rational | ( | long | num, | |
long | den | |||
) | [inline] |
rational<long> number_rational::value | ( | ) | const [inline] |
Definition at line 124 of file number_impl.hpp.
References value_.
Referenced by do_add(), do_divide(), do_equals(), do_less(), do_multiply(), do_save(), do_subtract(), do_to_string(), and promote_to_double().
00124 { return value_; }
number_impl * number_rational::promote_to_void | ( | ) | [virtual] |
Reimplemented from number_impl.
Definition at line 336 of file number_impl.cpp.
00337 { 00338 return new number_void(); 00339 }
number_impl * number_rational::promote_to_double | ( | ) | [virtual] |
Reimplemented from number_impl.
Definition at line 341 of file number_impl.cpp.
References value().
00342 { 00343 return new number_double(value().as<double>()); 00344 }
std::string number_rational::do_to_string | ( | ) | const [private, virtual] |
Implements number_impl.
Definition at line 265 of file number_impl.cpp.
References value().
00267 { 00268 std::ostringstream stream; 00269 stream << value(); 00270 return stream.str(); 00271 }
void number_rational::do_save | ( | std::ostream & | stream | ) | const [private, virtual] |
Implements number_impl.
Definition at line 273 of file number_impl.cpp.
References value().
00275 { 00276 stream << "rational " << value() << ' '; 00277 }
bool number_rational::do_equals | ( | number_impl const & | rhs | ) | const [private, virtual] |
Implements number_impl.
Definition at line 279 of file number_impl.cpp.
References value().
00281 { 00282 return value() == dynamic_cast<number_rational const&>(rhs).value(); 00283 }
bool number_rational::do_less | ( | number_impl const & | rhs | ) | const [private, virtual] |
Implements number_impl.
Definition at line 285 of file number_impl.cpp.
References value().
00287 { 00288 return value() < dynamic_cast<number_rational const&>(rhs).value(); 00289 }
number_impl * number_rational::do_add | ( | number_impl const & | rhs | ) | [private, virtual] |
Implements number_impl.
Definition at line 291 of file number_impl.cpp.
References rational< T >::denominator(), number_rational(), rational< T >::numerator(), value(), and value_.
00292 { 00293 rational<long> result = value_ + dynamic_cast<number_rational const&>(rhs).value(); 00294 if (result.denominator() == 1) 00295 return new number_long(result.numerator()); 00296 else 00297 return new number_rational(result); 00298 }
number_impl * number_rational::do_subtract | ( | number_impl const & | rhs | ) | [private, virtual] |
Implements number_impl.
Definition at line 300 of file number_impl.cpp.
References rational< T >::denominator(), number_rational(), rational< T >::numerator(), value(), and value_.
00301 { 00302 rational<long> result = value_ - dynamic_cast<number_rational const&>(rhs).value(); 00303 if (result.denominator() == 1) 00304 return new number_long(result.numerator()); 00305 else 00306 return new number_rational(result); 00307 }
number_impl * number_rational::do_multiply | ( | number_impl const & | rhs | ) | [private, virtual] |
Implements number_impl.
Definition at line 309 of file number_impl.cpp.
References rational< T >::denominator(), number_rational(), rational< T >::numerator(), value(), and value_.
00310 { 00311 rational<long> result = value_ * dynamic_cast<number_rational const&>(rhs).value(); 00312 if (result.denominator() == 1) 00313 return new number_long(result.numerator()); 00314 else 00315 return new number_rational(result); 00316 }
number_impl * number_rational::do_divide | ( | number_impl const & | rhs | ) | [private, virtual] |
Implements number_impl.
Definition at line 318 of file number_impl.cpp.
References rational< T >::denominator(), number_rational(), rational< T >::numerator(), value(), and value_.
00319 { 00320 rational<long> right = dynamic_cast<number_rational const&>(rhs).value(); 00321 if (right == 0L) 00322 throw calc_error("division by zero"); 00323 rational<long> result = value_ / right; 00324 if (result.denominator() == 1) 00325 return new number_long(result.numerator()); 00326 else 00327 return new number_rational(result); 00328 }
number_impl * number_rational::do_promote | ( | number_impl & | rhs | ) | const [private, virtual] |
Implements number_impl.
Definition at line 330 of file number_impl.cpp.
References number_impl::promote_to_rational().
00332 { 00333 return rhs.promote_to_rational(); 00334 }
rational<long> number_rational::value_ [private] |
Definition at line 138 of file number_impl.hpp.
Referenced by do_add(), do_divide(), do_multiply(), do_subtract(), and value().