2828
2929using namespace Java ::Lang;
3030
31- /* *
32- * Float initialization
33- *
34- * @param original
35- */
3631Float::Float () {
37- this ->original = 0 ;
38- this ->originalString = string_from_float (this ->original );
32+ this ->original = 0 ;
33+ this ->originalString = string_from_float (this ->original );
3934}
4035
41- /* *
42- * Float initialization
43- *
44- * @param original
45- */
4636Float::Float (float original) {
47- this ->original = original;
48- this ->originalString = string_from_float (this ->original );
37+ this ->original = original;
38+ this ->originalString = string_from_float (this ->original );
4939}
5040
51- /* *
52- * Float initialization
53- *
54- * @param original
55- */
5641Float::Float (const Float &floatNumber) {
57- this ->original = floatNumber.original ;
58- this ->originalString = string_from_float (this ->original );
42+ this ->original = floatNumber.original ;
43+ this ->originalString = string_from_float (this ->original );
5944}
6045
6146Float::~Float () {
62- if (this ->originalString != NULL ) {
63- free (this ->originalString );
64- }
47+ if (this ->originalString != NULL ) {
48+ free (this ->originalString );
49+ }
6550}
6651
67- /* *
68- * Float value
69- *
70- * @return float
71- */
72- float Float::floatValue () const {
73- return this ->original ;
52+ Float Float::operator +(const Float &target) {
53+ return Float (this ->original + target.original );
54+ }
55+
56+ Float Float::operator -(const Float &target) {
57+ return Float (this ->original - target.original );
58+ }
59+
60+ Float Float::operator *(const Float &target) {
61+ return Float ( this ->original * target.original );
62+ }
63+
64+ Float Float::operator /(const Float &target) {
65+ return Float ( this ->original / target.original );
66+ }
67+
68+ boolean Float::operator ==(const Float &target) const {
69+ return (boolean) (this ->original == target.original );
70+ }
71+
72+ // TODO(thoangminh): enable after finish method equals , compare
73+ // boolean Float::operator==(const Float &target) const {
74+ // return (boolean) equals(target.original);
75+ // }
76+ //
77+ // boolean Float::operator!=(const Float &target) const {
78+ // return (boolean) !equals(target.original);
79+ // }
80+ //
81+ // boolean Float::operator<(const Float &target) const {
82+ // if (compare(this->doubleValue(), target.doubleValue()) == -1) {
83+ // return true;
84+ // }
85+ // return false;
86+ // }
87+ //
88+ // boolean Float::operator>(const Float &target) const {
89+ // if (compare(this->doubleValue(), target.doubleValue()) == 1) {
90+ // return true;
91+ // }
92+ // return false;
93+ // }
94+ //
95+ // boolean Float::operator>=(const Float &target) const {
96+ // if (compare(this->doubleValue(), target.doubleValue()) == 1
97+ // || compare(this->doubleValue(), target.doubleValue()) == 0) {
98+ //
99+ // return true;
100+ // }
101+ // return false;
102+ // }
103+ //
104+ // boolean Float::operator<=(const Float &target) const {
105+ //
106+ // if (compare(this->doubleValue(), target.doubleValue()) == -1
107+ // || compare(this->doubleValue(), target.doubleValue()) == 0) {
108+ //
109+ // return true;
110+ // }
111+ // return false;
112+ // }
113+
114+ boolean Float::operator &&(const Float &target) const {
115+ return (boolean) (this ->original && target.original );
116+ }
117+
118+ boolean Float::operator ||(const Float &target) const {
119+ return (boolean) (this ->original || target.original );
120+ }
121+
122+ Float Float::operator =(const Float &target) {
123+ this ->original = target.original ;
124+ free (this ->originalString );
125+ this ->originalString = string_from_float (this ->original );
126+ return *this ;
127+ }
128+
129+ Float Float::operator +=(const Float &target) const {
130+ return (Float) (this ->original + target.original );
131+ }
132+
133+ Float Float::operator -=(const Float &target) const {
134+ return (Float) (this ->original - target.original );
135+ }
136+
137+ Float Float::operator *=(const Float &target) const {
138+ return (Float) (this ->original * target.original );
139+ }
140+
141+ Float Float::operator /=(const Float &target) const {
142+ return (Float) (this ->original / target.original );
74143}
75144
76- /* *
77- * Char value
78- *
79- * @return char
80- */
81145char Float::charValue () const {
82- string stringFromFloatResult = string_from_float (this ->original );
83- char floatCharValueResult = string_to_char (stringFromFloatResult);
84- free (stringFromFloatResult);
85- return floatCharValueResult;
146+ string convertResult = string_from_float (this ->original );
147+ char charValueResult = string_to_char (convertResult);
148+ free (convertResult);
149+ return charValueResult;
150+ }
151+ // TODO(thoangminh): enable after finish toString()
152+ // string Float::stringValue() const {
153+ // return (string) this->toString();
154+ // }
155+
156+ float Float::floatValue () const {
157+ return this ->original ;
86158}
87159
88- /* *
89- * Short value
90- *
91- * @return short
92- */
93160short Float::shortValue () const {
94- return (short ) this ->original ;
161+ return (short ) this ->original ;
95162}
96163
97- /* *
98- * Int value
99- *
100- * @return int
101- */
102164int Float::intValue () const {
103- return (int ) this ->original ;
165+ return (int ) this ->original ;
104166}
105167
106168/* *
@@ -109,16 +171,16 @@ int Float::intValue() const {
109171 * @return long
110172 */
111173long Float::longValue () const {
112- return (long ) this ->original ;
174+ return (long ) this ->original ;
113175}
114176
115177/* *
116- * Double value
178+ * Float value
117179 *
118180 * @return
119181 */
120182double Float::doubleValue () const {
121- return this ->original ;
183+ return this ->original ;
122184}
123185
124186/* *
@@ -127,7 +189,7 @@ double Float::doubleValue() const {
127189 * @return String
128190 */
129191string Float::toString () const {
130- return this ->originalString ;
192+ return this ->originalString ;
131193}
132194
133195/* *
@@ -136,115 +198,12 @@ string Float::toString() const {
136198 * @param target
137199 * @return Float
138200 */
139- Float Float::parseFloat (String target) {
140- Float result = string_to_float (target.toString ());
141- return result;
142- }
143201
144- /* *
145- * Assign value of this object same as target value
146- *
147- * @param target
148- * @return Float
149- */
150- Float &Float::operator =(const Float &target) {
151- this ->original = target.original ;
152- free (this ->originalString );
153- this ->originalString = string_from_float (this ->original );
154- return *this ;
155- }
156-
157- /* *
158- * Sum of this and target
159- *
160- * @param target
161- * @return Float
162- */
163- Float Float::operator +(const Float &target) {
164- return this ->original + target.original ;
165- }
166-
167- /* *
168- * Make a subtraction with target Float
169- *
170- * @return float
171- */
172- Float Float::operator -(const Float &target) {
173- return this ->original - target.original ;
174- }
175-
176- /* *
177- * Make a multiplication with target Float
178- *
179- * @return float
180- */
181- Float Float::operator *(const Float &target) {
182- return this ->original * target.original ;
183- }
184-
185- /* *
186- * Make a division with target Float
187- *
188- * @return float
189- */
190- Float Float::operator /(const Float &target) {
191- return this ->original / target.original ;
192- }
193-
194- /* *
195- * Compare this Float is equal target
196- *
197- * @return bool
198- */
199- boolean Float::operator ==(const Float &target) const {
200- return this ->original == target.original ;
201- }
202-
203- /* *
204- * Compare this Float is not equal target
205- *
206- * @return bool
207- */
208- boolean Float::operator !=(const Float &target) const {
209- return this ->original != target.original ;
210- }
211-
212- /* *
213- * Compare this Float is less than target
214- *
215- * @return bool
216- */
217- boolean Float::operator <(const Float &target) const {
218- return this ->original < target.original ;
219- }
220-
221- /* *
222- * Compare this Float is more than target
223- *
224- * @return bool
225- */
226- boolean Float::operator >(const Float &target) const {
227- return this ->original > target.original ;
228- }
229-
230- /* *
231- * Compare this Float is equal or less than target
232- *
233- * @return bool
234- */
235- boolean Float::operator <=(const Float &target) const {
236- return this ->original <= target.original ;
237- }
238-
239- /* *
240- * Compare this Float is equal or more than target
241- *
242- * @return bool
243- */
244- boolean Float::operator >=(const Float &target) const {
245- return this ->original >= target.original ;
246- }
202+ // Float Float::parseFloat(String target) {
203+ // Float result = string_to_float(target.toString());
204+ // return result;
205+ // }
247206
248207boolean Float::isNaN (float v) {
249- return v != v;
250- }
208+ return v != v;
209+ }
0 commit comments