expanded class
	INTEGER_NUMBER_IMPL

inherit
	INTEGER_NUMBER
		redefine
			default_create,
			complex_anchor,
			real_anchor
		end

create
	default_create,
	make

convert
	make ({INTEGER}),
	value: {INTEGER, INTEGER_REF, NUMERIC, COMPARABLE, HASHABLE},
	as_real: {REAL_NUMBER_IMPL},
	real_value: {REAL, REAL_REF},
	as_complex: {COMPLEX_NUMBER_IMPL}

feature {NONE} -- Initialization

	default_create
			-- <Precursor>
		do
			value := 0
		ensure then
			value: value = 0
		end

	make (v: INTEGER)
			-- Create an integer number with value `v'.
		do
			value := normalized_value (v)
		ensure
			value: value = normalized_value (v)
		end

feature -- Primitive

	real_value: REAL
			-- <Precursor>
		do
			Result := value
		end

	value: INTEGER
			-- <Precursor>

feature -- Access

	Zero: INTEGER_NUMBER_IMPL
			-- <Precursor>
		once
		end

	Two: INTEGER_NUMBER_IMPL
			-- <Precursor>
		once
			Result := 2
		ensure then
			class
		end

	Min_value: INTEGER = - 8
			-- Minimum value representable by this implementation of integer numbers

	Max_value: INTEGER = 7
			-- Maximum value representable by this implementation of integer numbers

feature -- Operation

	real_opposite: like real_anchor
			-- <Precursor>
		do
			Result := - as_real
		end

	complex_product (z: COMPLEX_NUMBER): like complex_anchor
			-- <Precursor>
		do
			Result := as_complex * z
		end

feature -- Conversion

	as_complex: like complex_anchor
			-- This integer number represented as a complex number
		do
			create Result.make_from_integer (Current)
		ensure
			real: Result.a ≍ Current
			Imaginary: Result.b ≍ Zero
		end

	as_real: like real_anchor
			-- This integer number represented as a real number
		do
			create Result.make_from_integer (Current)
		ensure
			value: Result.value = real_value
		end

feature -- Factory

	real_normalized_value (v: REAL): REAL
			-- <Precursor>
		do
			Result := {REAL_NUMBER_IMPL}.normalized_value (v)
		ensure then
			definition: Result = {REAL_NUMBER_IMPL}.normalized_value (v)
		end

	normalized_value (v: INTEGER): INTEGER
			-- The integer value represented by the first `value_bits' significant bits of `v'
		do
			Result := (v |<< ({PLATFORM}.Integer_32_bits - Value_bits)) |>> ({PLATFORM}.Integer_32_bits - Value_bits)
		ensure then
			class
			definition: Result = (v |<< ({PLATFORM}.Integer_32_bits - Value_bits)) |>> ({PLATFORM}.Integer_32_bits - Value_bits)
		end

feature -- Anchor

	complex_anchor: COMPLEX_NUMBER_IMPL
			-- <Precursor>
		do
			Result := Current
		end

	real_anchor: REAL_NUMBER_IMPL
			-- <Precursor>
		do
			Result := Current
		end

	integer_anchor: INTEGER_NUMBER_IMPL
			-- <Precursor>
		do
			Result := Current
		end

feature {NONE} -- Implementation

	Value_bits: INTEGER = 4
			-- Number of significant bits in `value'

invariant
	Min_value: Min_value = {INTEGER}.Min_value |>> ({PLATFORM}.Integer_32_bits - Value_bits)
	Max_value: Max_value = {INTEGER}.Max_value |>> ({PLATFORM}.Integer_32_bits - Value_bits)

end
