home *** CD-ROM | disk | FTP | other *** search
- -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C)
- -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
- --
- class DOUBLE_REF
-
- inherit
- NUMERIC
- redefine
- infix "+", infix "-", infix "*", infix "/", infix "^",
- prefix "+", prefix "-", valid_divisor, one, zero
- end;
- COMPARABLE
- redefine
- infix "<", compare
- end;
-
- creation {ANY}
- make
-
- feature {ANY}
-
- item: DOUBLE;
-
- make(value: DOUBLE) 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;
-
- end -- DOUBLE_REF
-