Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Core::Real Class Reference

This class represents a native double. More...

#include <Real.h>

Inheritance diagram for Core::Real:

Inheritance graph
[legend]
Collaboration diagram for Core::Real:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual StringclassName (void) const
 Answer receiver class name.
virtual double asDouble (void) const
virtual long long asLongLong (void) const
virtual Integerrounded (void) const
 Round the receiver and answer an Integer.
virtual Integertruncated (void) const
 Answer the integer part as an Integer.
virtual long hash (void) const
 Answer object hash value.
virtual bool isEqual (const Object *object) const
 Compare receiver with given object.
virtual bool isEqual (const Object &object) const
 Compare receiver with given object.
virtual bool isEqual (int arg) const
virtual bool isEqual (double arg) const
virtual bool isEqualToLongLong (long long arg) const
virtual bool isEqualToDouble (double arg) const
virtual Numbernegate (void)
virtual void printOn (Stream *stream) const
 Print object identification into the stream.
virtual bool isReal (void) const
virtual bool isPositive (void) const
 Answer whether the recevier is positive (including zero).
virtual bool isZero (void) const
 Answer whether the receiver represents a zero in it's domain.

Static Public Member Functions

static Realvalue (double val)

Protected Member Functions

 Real (double v)

Protected Attributes

double _value

Detailed Description

This class represents a native double.

Generally a wrapper for operations with other numbers. See method comments in the Number class.

See also:
Number

Definition at line 42 of file Real.h.


Constructor & Destructor Documentation

Real::Real double  v  )  [protected]
 

Definition at line 32 of file Real.cc.

References _value.

Referenced by value().

00033 {
00034     _value = v;
00035 }


Member Function Documentation

double Real::asDouble void   )  const [virtual]
 

Reimplemented from Core::Number.

Definition at line 50 of file Real.cc.

References _value.

00051 {
00052     return _value;
00053 }

long long Real::asLongLong void   )  const [virtual]
 

Reimplemented from Core::Number.

Definition at line 55 of file Real.cc.

References _value.

00056 {
00057     return (long long) _value;
00058 }

String * Real::className void   )  const [virtual]
 

Answer receiver class name.

Because there isn't any standard way to obtain class name this method comes to place.

Every class should rewrite this method but many didn't (yet).

Reimplemented from Core::Number.

Definition at line 38 of file Real.cc.

00039 {
00040     return new String("Real");
00041 }

long Real::hash void   )  const [virtual]
 

Answer object hash value.

The value should be same for objects found equal with isEqual() method. So if you rewrite this method you should rewrite isEqual() method too.

Reimplemented from Core::Object.

Definition at line 71 of file Real.cc.

References _value.

00072 {
00073     return (long) _value;
00074 }

virtual bool Core::Real::isEqual double  arg  )  const [inline, virtual]
 

Reimplemented from Core::Number.

Definition at line 74 of file Real.h.

References Core::Number::isEqual().

00075       { return Number::isEqual(arg); }

virtual bool Core::Real::isEqual int  arg  )  const [inline, virtual]
 

Reimplemented from Core::Number.

Definition at line 72 of file Real.h.

References Core::Number::isEqual().

00073       { return Number::isEqual(arg); }

virtual bool Core::Real::isEqual const Object object  )  const [inline, virtual]
 

Compare receiver with given object.

Do not rewrite this method. It just a sugar for Object::isEqual(Object *).

  • object - object to compare receiver with

Reimplemented from Core::Number.

Definition at line 70 of file Real.h.

References Core::Number::isEqual().

00071       { return Number::isEqual(object); }

bool Real::isEqual const Object object  )  const [virtual]
 

Compare receiver with given object.

This method could compare objects with more sophisticated algorithm (eg. based on instance variables comparing or so).

If you rewrite this method you should rewrite hash() too.

  • object - object to compare receiver with

Reimplemented from Core::Number.

Definition at line 76 of file Real.cc.

References _value.

00077 {
00078     if (!object->isNumber()) return false;
00079 
00080     return ((Number *) object)->isEqualToDouble(_value);
00081 }

bool Real::isEqualToDouble double  arg  )  const [virtual]
 

Reimplemented from Core::Number.

Definition at line 89 of file Real.cc.

References _value.

00090 {
00091     return _value == arg;
00092 }

bool Real::isEqualToLongLong long long  arg  )  const [virtual]
 

Reimplemented from Core::Number.

Definition at line 84 of file Real.cc.

References _value.

00085 {
00086     return _value == arg;
00087 }

bool Real::isPositive void   )  const [virtual]
 

Answer whether the recevier is positive (including zero).

Reimplemented from Core::Number.

Definition at line 115 of file Real.cc.

References _value.

00116 {
00117     return _value >= 0;
00118 }

bool Real::isReal void   )  const [virtual]
 

Reimplemented from Core::Number.

Definition at line 110 of file Real.cc.

00111 {
00112     return true;
00113 }

bool Real::isZero void   )  const [virtual]
 

Answer whether the receiver represents a zero in it's domain.

Reimplemented from Core::Number.

Definition at line 120 of file Real.cc.

References _value.

Referenced by negate().

00121 {
00122     return _value == 0;
00123 }

Number * Real::negate void   )  [virtual]
 

Reimplemented from Core::Number.

Definition at line 95 of file Real.cc.

References _value, isZero(), and value().

00096 {
00097     if (isZero()) return this;
00098     return Real::value(-_value);
00099 }

void Real::printOn Stream stream  )  const [virtual]
 

Print object identification into the stream.

Object identification is formed from its className() by default. But complicated classes (eg. collections) may print some other information.

  • stream - stream to print to.

Reimplemented from Core::Object.

Definition at line 102 of file Real.cc.

References _value, and Core::Stream::nextPutAll().

00103 {
00104     char number[30];
00105     sprintf(number, "%f", _value);
00106     stream->nextPutAll(number);
00107 }

Integer * Real::rounded void   )  const [virtual]
 

Round the receiver and answer an Integer.

Definition at line 60 of file Real.cc.

References _value, and Core::Integer::value().

00061 {
00062     return Integer::value((long long) (_value + 0.5));
00063 }

Integer * Real::truncated void   )  const [virtual]
 

Answer the integer part as an Integer.

Definition at line 65 of file Real.cc.

References Core::Integer::value().

00066 {
00067     return Integer::value(this->asLongLong());
00068 }

Real * Real::value double  val  )  [static]
 

Definition at line 44 of file Real.cc.

References Real().

Referenced by Core::Number::fromStringRadix(), and negate().

00045 {
00046     return new Real(val);
00047 }


Member Data Documentation

double Core::Real::_value [protected]
 

Definition at line 45 of file Real.h.

Referenced by asDouble(), asLongLong(), hash(), isEqual(), isEqualToDouble(), isEqualToLongLong(), isPositive(), isZero(), negate(), printOn(), Real(), and rounded().


The documentation for this class was generated from the following files:
Generated on Mon Nov 27 09:51:53 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2