Calculator Step 6

- Main Page
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Member Functions | Private Attributes | List of all members
number_double Class Reference

`#include <number_impl.hpp>`

Inheritance diagram for number_double:

## Public Member Functions
| number_double (double value)
double | value () const
virtual std::shared_ptr < number_impl > | promote_to_void ()
Public Member Functions inherited from number_impl
virtual | ~number_impl ()
void | print (std::ostream &stream) const
std::string | to_string () const
void | save (std::ostream &stream) const
bool | equals (number_impl const &rhs) const
bool | less (number_impl const &rhs) const
std::shared_ptr< number_impl > | add (number_impl const &rhs)
std::shared_ptr< number_impl > | subtract (number_impl const &rhs)
std::shared_ptr< number_impl > | multiply (number_impl const &rhs)
std::shared_ptr< number_impl > | divide (number_impl const &rhs)
void | add_ref ()
void | del_ref ()
std::shared_ptr< number_impl > | promote (number_impl &rhs) const
virtual std::shared_ptr < number_impl > | promote_to_long ()
virtual std::shared_ptr < number_impl > | promote_to_rational ()
virtual std::shared_ptr < 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 std::shared_ptr < number_impl > | do_add (number_impl const &rhs)
virtual std::shared_ptr < number_impl > | do_subtract (number_impl const &rhs)
virtual std::shared_ptr < number_impl > | do_multiply (number_impl const &rhs)
virtual std::shared_ptr < number_impl > | do_divide (number_impl const &rhs)
virtual std::shared_ptr < number_impl > | do_promote (number_impl &rhs) const

## Private Attributes
double | value_

## Additional Inherited Members
Static Public Member Functions inherited from number_impl
static std::shared_ptr < number_impl > | read_library (std::istream &stream)
Protected Member Functions inherited from number_impl
| number_impl ()

## Detailed Description

Represent a floating-point value. Always use `double` to represent floating-point values.

Definition at line 147 of file number_impl.hpp.

## Constructor & Destructor Documentation

number_double::number_double | ( | double | value | ) |
| inline

Definition at line 149 of file number_impl.hpp.

149 : number_impl(), value_(value) {}
number_impl::number_impl
number_impl()
Definition: number_impl.hpp:54
number_double::value_
double value_
Definition: number_impl.hpp:163
number_double::value
double value() const
Definition: number_impl.hpp:150

## Member Function Documentation

std::shared_ptr< number_impl > number_double::do_add | ( | number_impl const & | rhs | ) |
| private virtual

Implements number_impl.

Definition at line 354 of file number_impl.cpp.

References value(), and value_.

355 {
356 return std::make_shared<number_double>(value_ + dynamic_cast<number_double const&>(rhs).value());
357 }
number_double
Definition: number_impl.hpp:147
number_double::value_
double value_
Definition: number_impl.hpp:163
number_double::value
double value() const
Definition: number_impl.hpp:150

std::shared_ptr< number_impl > number_double::do_divide | ( | number_impl const & | rhs | ) |
| private virtual

Implements number_impl.

Definition at line 369 of file number_impl.cpp.

References value(), and value_.

370 {
371 double right{ dynamic_cast<number_double const&>(rhs).value() };
372 if (right == 0.0)
373 throw calc_error{"division by zero"};
374 return std::make_shared<number_double>(value_ / right);
375 }
calc_error
Definition: calc_error.hpp:11
number_double
Definition: number_impl.hpp:147
number_double::value_
double value_
Definition: number_impl.hpp:163
number_double::value
double value() const
Definition: number_impl.hpp:150

bool number_double::do_equals | ( | number_impl const & | rhs | ) | const
| private virtual

Implements number_impl.

Definition at line 342 of file number_impl.cpp.

References value().

344 {
345 return value() == dynamic_cast<number_double const&>(rhs).value();
346 }
number_double
Definition: number_impl.hpp:147
number_double::value
double value() const
Definition: number_impl.hpp:150

bool number_double::do_less | ( | number_impl const & | rhs | ) | const
| private virtual

Implements number_impl.

Definition at line 348 of file number_impl.cpp.

References value().

350 {
351 return value() < dynamic_cast<number_double const&>(rhs).value();
352 }
number_double
Definition: number_impl.hpp:147
number_double::value
double value() const
Definition: number_impl.hpp:150

std::shared_ptr< number_impl > number_double::do_multiply | ( | number_impl const & | rhs | ) |
| private virtual

Implements number_impl.

Definition at line 364 of file number_impl.cpp.

References value(), and value_.

365 {
366 return std::make_shared<number_double>(value_ * dynamic_cast<number_double const&>(rhs).value());
367 }
number_double
Definition: number_impl.hpp:147
number_double::value_
double value_
Definition: number_impl.hpp:163
number_double::value
double value() const
Definition: number_impl.hpp:150

std::shared_ptr< number_impl > number_double::do_promote | ( | number_impl & | rhs | ) | const
| private virtual

Implements number_impl.

Definition at line 377 of file number_impl.cpp.

References number_impl::promote_to_double().

379 {
380 return rhs.promote_to_double();
381 }
number_impl::promote_to_double
virtual std::shared_ptr< number_impl > promote_to_double()
Definition: number_impl.cpp:112

void number_double::do_save | ( | std::ostream & | stream | ) | const
| private virtual

Implements number_impl.

Definition at line 336 of file number_impl.cpp.

References value().

338 {
339 stream << "double " << value() << ' ';
340 }
number_double::value
double value() const
Definition: number_impl.hpp:150

std::shared_ptr< number_impl > number_double::do_subtract | ( | number_impl const & | rhs | ) |
| private virtual

Implements number_impl.

Definition at line 359 of file number_impl.cpp.

References value(), and value_.

360 {
361 return std::make_shared<number_double>(value_ - dynamic_cast<number_double const&>(rhs).value());
362 }
number_double
Definition: number_impl.hpp:147
number_double::value_
double value_
Definition: number_impl.hpp:163
number_double::value
double value() const
Definition: number_impl.hpp:150

std::string number_double::do_to_string | ( |  | ) | const
| private virtual

Implements number_impl.

Definition at line 328 of file number_impl.cpp.

References value().

330 {
331 std::ostringstream stream{};
332 stream << value();
333 return stream.str();
334 }
number_double::value
double value() const
Definition: number_impl.hpp:150

std::shared_ptr< number_impl > number_double::promote_to_void | ( |  | ) |
| virtual

Reimplemented from number_impl.

Definition at line 383 of file number_impl.cpp.

384 {
385 return std::make_shared<number_void>();
386 }

double number_double::value | ( |  | ) | const
| inline

Definition at line 150 of file number_impl.hpp.

References value_.

Referenced by do_add(), do_divide(), do_equals(), do_less(), do_multiply(), do_save(), do_subtract(), and do_to_string().

150 { return value_; }
number_double::value_
double value_
Definition: number_impl.hpp:163

## Member Data Documentation

double number_double::value_
| private

Definition at line 163 of file number_impl.hpp.

Referenced by do_add(), do_divide(), do_multiply(), do_subtract(), and value().

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

- number_impl.hpp
- number_impl.cpp