5.10 Class DOUBLE |

indexing

description:"Real values, double precision"

expanded class interface

DOUBLE

-- Accessfeature

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

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

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.0

-- Comparisonfeature

infix"<"(other:likeCurrent):BOOLEAN-- Isothergreater than current double? -- (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.requireother_exists:other/=Void-- (FromCOMPARABLE.)ensureequal_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/=Voidensurenot_exact_zero:Result(impliesother/=0.0)

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

-- Conversionfeature

ceiling:INTEGER-- Smallest integral value no smaller than current objectensureresult_no_smaller:Result>=Current;close_enough:Result-Current<one

floor:INTEGER-- Greatest integral value no greater than current objectensureresult_no_greater:Result<=Current;close_enough:Current-Result<one

rounded:INTEGER-- Rounded integral valueensuredefinition:Result=sign* ((abs+0.5).floor)

truncated_to_integer:INTEGER-- Integer part (same sign, largest absolute -- value no greater than current object's)truncated_to_real:REAL-- Real part (same sign, largest absolute -- value no greater than current object's)

-- 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/=Voidensureresult_exists:Result/=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):likeCurrent-- Division byother-- (FromNUMERIC.)requireother_exists:other/=Void;good_divisor:divisible(other)ensureresult_exists:Result/=Void

infix"^"(other:likeCurrent):likeCurrent-- Current double to powerother-- (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 double value -- (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 |