home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-04-13 | 2.2 KB | 114 lines | [TEXT/ttxt] |
- -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C)
- -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
- --
- class DOUBLE_REF
-
- inherit
- NUMERIC
- undefine out_in_tagged_out_memory, fill_tagged_out_memory
- redefine
- infix "^", prefix "+", prefix "-"
- end;
- COMPARABLE
- redefine
- compare, out_in_tagged_out_memory, fill_tagged_out_memory
- end;
-
- creation make
-
- feature
-
- item: DOUBLE;
-
- make(value: DOUBLE) is
- do
- item := value
- end;
-
- feature
-
- set_item(value: like item) is
- do
- item := value;
- end;
-
- infix "+" (other: like Current): like Current is
- -- Add `other' to Current.
- do
- !!Result.make (item + other.item)
- end;
-
- infix "-" (other: like Current): like Current is
- -- Subtract `other' from Current.
- do
- !!Result.make (item - other.item);
- end;
-
- infix "*" (other: like Current): like Current is
- -- Multiply `other' by Current.
- do
- !!Result.make (item * other.item)
- end;
-
- infix "/" (other: like Current): like Current is
- -- Divide Current by `other'.
- do
- !!Result.make (item / other.item)
- end;
-
- infix "^" (exp: INTEGER): like Current is
- -- Raise Current to `exp'-th power.
- do
- !!Result.make (item ^ exp)
- end;
-
- prefix "+" : like Current is
- do
- !!Result.make (item)
- end;
-
- prefix "-" : like Current is
- do
- !!Result.make (-item);
- end;
-
- infix "<" (other: like Current): BOOLEAN is
- -- Is Current less than `other'?
- do
- Result := item < other.item
- end;
-
- compare (other: like Current): INTEGER is
- -- Compare Current with `other'.
- -- '<' <==> Result < 0
- -- '>' <==> Result > 0
- -- Otherwise Result = 0
- do
- Result := item.compare (other.item)
- end;
-
- valid_divisor (other: like Current): BOOLEAN is
- do
- Result := (other.item /= 0.0)
- end;
-
- one: like Current is
- do
- !!Result.make (1.0)
- end;
-
- zero: like Current is
- do
- !!Result.make (0.0)
- end;
-
- feature -- Object Printing :
-
- out_in_tagged_out_memory, fill_tagged_out_memory is
- do
- tagged_out_memory.append("item: ");
- item.fill_tagged_out_memory;
- end;
-
- end -- DOUBLE_REF
-