00001 #include "Deserializer.H"
00002 #include "Double.H"
00003 #include "Integer.H"
00004 #include "Serializer.H"
00005 #include "String/String.H"
00006 #include "String/StringBuffer.H"
00007
00008 #include <stdio.h>
00009 #include <string.h>
00010
00011 Double::Double(const Integer &d) : value(double((int)d)) {}
00012
00013 Object *Double::Copy() const {
00014 return new Double(value);
00015 }
00016
00017 void Double::Serialize(Serializer &out) const {
00018 out << value;
00019 }
00020
00021 void Double::Deserialize(Deserializer &in) {
00022 in >> value;
00023 }
00024
00025 unsigned int Double::hash() const {
00026 union {
00027 unsigned int a[2];
00028 double b;
00029 } v;
00030 v.b=value;
00031 return (unsigned int)(v.a[0]^v.a[1]);
00032 }
00033
00034 unsigned int Double::hash(double value) {
00035 union {
00036 unsigned int a[2];
00037 double b;
00038 } v;
00039 v.b=value;
00040 return (unsigned int)(v.a[0]^v.a[1]);
00041 }
00042
00043 String Double::toString() const {
00044 char buf[20];
00045 sprintf(buf,"%g",value);
00046 return String(buf);
00047 }
00048
00049 bool Double::Equals(const Object &o) const {
00050 const Double *other=dynamic_cast<const Double *>(&o);
00051 if (other) {
00052 return ::operator==(*this,*other);
00053 }
00054 else {
00055 const Integer *otheri=dynamic_cast<const Integer *>(&o);
00056 if (otheri) return ::operator==(*this,Double(*otheri));
00057 }
00058 return false;
00059 }
00060
00061 bool Double::lessThan(const Object &o) const {
00062 const Double *other=dynamic_cast<const Double *>(&o);
00063 if (other) {
00064 return ::operator<(*this,*other);
00065 }
00066 else {
00067 const Integer *otheri=dynamic_cast<const Integer *>(&o);
00068 if (otheri) return ::operator<(*this,Double(*otheri));
00069 }
00070 return false;
00071 }
00072
00073 bool Double::lessThanEquals(const Object &o) const {
00074 const Double *other=dynamic_cast<const Double *>(&o);
00075 if (other) {
00076 return ::operator<=(*this,*other);
00077 }
00078 else {
00079 const Integer *otheri=dynamic_cast<const Integer *>(&o);
00080 if (otheri) return ::operator<=(*this,Double(*otheri));
00081 }
00082 return false;
00083 }