5.8 Class INTEGER |

indexing

description:"Integer values"

expanded class interface

INTEGER

-- Accessfeature

hash_code:INTEGER-- Hash code value -- (FromisHASHABLE.)ensuregood_hash_value:Result>=0

one:likeCurrent-- Neutral element for "*" and "/" -- (FromNUMERIC.)ensureResult_exists:Result/=Void;value:Result=1

sign:INTEGER-- Sign value (0, -1 or 1)ensurethree_way:Result=three_way_comparison(zero)

zero:likeCurrent-- Neutral element for "+" and "-" -- (FromNUMERIC.)ensureResult_exists:Result/=Void;value:Result=0

-- Comparisonfeature

infix"<"(other:likeCurrent):BOOLEAN-- Isothergreater than current integer? -- (FromCOMPARABLE.)requireother_exists:other/=Voidensureasymmetric:Resultimplies(notother<Current)

infix"<="(other:likeCurrent):BOOLEAN-- Is current object less than or equal toother? -- (FromCOMPARABLE.)requireother_exists:other/=Voidensuredefinition:Result= (Current<other)oris_equal(other);

">=" (infixother:likeCurrent):BOOLEAN-- Is current object greater than or equal toother? -- (FromCOMPARABLE.)requireother_exists:other/=Voidensuredefinition:Result= (other<=Current)

infix">"(other:likeCurrent):BOOLEAN-- Is current object greater thanother? -- (FromCOMPARABLE.)requireother_exists:other/=Voidensuredefinition:Result= (other <Current)

max(other:likeCurrent):likeCurrent-- The greater of current object andother-- (FromCOMPARABLE.)requireother_exists:other/=Voidensurecurrent_if_not_smaller: (Current>=other)(impliesResult=Current)other_if_smaller: (Current< other)(impliesResult= other)

min(other:likeCurrent):likeCurrent-- The smaller of current object andother-- (FromCOMPARABLE.)requireother_exists:other/=Voidensurecurrent_if_not_greater: (Current<=other)(impliesResult=Current)other_if_greater: (Current>other)(impliesResult=other)

three_way_comparison(other:likeCurrent):INTEGER-- If current object equal toother, 0; if smaller, -- -1; if greater, 1. -- (FromCOMPARABLE.)requireother_exists:other/=Voidensureequal_zero: (Result=0) =is_equal(other);smaller: (Result=1) =Current<other;greater_positive: (Result= -1) =Current>other

-- Status reportfeature

divisible(other:likeCurrent):BOOLEAN-- May current object be divided byother? -- (FromNUMERIC.)requireother_exists:other/=Voidensurevalue:Result= (other/=0)

exponentiable(other:NUMERIC):BOOLEAN-- May current object be elevated to the powerother? -- (FromNUMERIC.)requireother_exists:other/=Voidensuresafe_values: (other.conforms_to(Current)(orother.conforms_to(0.0)(andCurrent>=0)))impliesResult

-- Basic operationsfeature

abs:likeCurrent-- Absolute valueensurenon_negative:Result>=0;same_absolute_value: (Result=Current)(orResult= -Current)

infix"*"(other:likeCurrent):likeCurrent-- Product byother-- (FromNUMERIC.)requireother_exists:other/=Void

infix"+"(other:likeCurrent):likeCurrent-- Sum withother-- (FromNUMERIC.)requireother_exists:other/=Voidensureresult_exists:Result/=Void;commutative:equal(Result,other+Current)

infix"-"(other:likeCurrent):likeCurrent-- Result of subtractingother-- (FromNUMERIC.)requireother_exists:other/=Voidensureresult_exists:Result/=Void

infix"/"(other:likeCurrent):DOUBLE-- Division byotherrequireother_exists:other/=Void;good_divisor:divisible(other)ensureresult_exists:Result/=Void

infix"//"(other:likeCurrent):likeCurrent-- Integer division ofCurrentbyother-- (From "/" inNUMERIC.)requireother_exists:other/=Void;good_divisor:divisible(other)ensureresult_exists:divisible(other)

infix"\\"(other:likeCurrent):likeCurrent-- Remainder of the integer division ofCurrentbyotherrequireother_exists:other/=Void;good_divisor:divisible(other)ensureresult_exists:Result/=Void

infix"^"(other:NUMERIC):DOUBLE-- Integer power ofCurrentbyother-- (FromNUMERIC.)requireother_exists:other/=Void;good_exponent:exponentiable(other)ensureresult_exists:Result/=Void

prefix"+":likeCurrent-- Unary plus -- (FromNUMERIC.)ensureresult_exists:Result/=Void

prefix"-":likeCurrent-- Unary minus -- (FromNUMERIC.)ensureresult_exists:Result/=Void

-- Outputfeature

out:STRING-- Printable representation of current object -- (FromGENERAL.)

invariant

irreflexive_comparison:(notCurrent<Current);neutral_addition:equal(Current+zero,Current);self_subtraction:equal(Current-Current,zero);neutral_multiplication:equal(Current* one,Current);self_division:divisible(Current)impliesequal(Current/Current, one)sign_times_abs:equal(sign*abs,Current)

end

Copyright © 1995, Nonprofit
International Consortium for Eiffelmailto:nice@atlanta.twr.comLast Updated: 26 October 1997 |