25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3. Data Type Definitions<br />

Operator Name Type<br />

-x Unary minus real → real<br />

abs x Absolute value real → real<br />

floor x Floor real → int<br />

x + y Sum real * real → real<br />

x - y Difference real * real → real<br />

x * y Product real * real → real<br />

x / y Division real * real → real<br />

x div y Integer division int * int → int<br />

x rem y Remainder int * int → int<br />

x mod y Modulus int * int → int<br />

x**y Power real * real → real<br />

x < y Less than real * real → bool<br />

x > y Greater than real * real → bool<br />

x = y Greater or equal real * real → bool<br />

x = y Equal real * real → bool<br />

x y Not equal real * real → bool<br />

The types stated for operands are the most general types allowed. This means for instance<br />

that unary minus works for operands of all five types (nat1, nat, int rat and real).<br />

Semantics of Operators: The operators Unary minus, Sum, Difference, Product, Division, Less<br />

than, Greater than, Less or equal, Greater or equal, Equal and Not equal have the usual<br />

semantics of such operators.<br />

Operator Name Semantics Description<br />

Floor<br />

yields the greatest integer which is equal to or smaller<br />

than x.<br />

Absolute value yields the absolute value of x, i.e. x itself if x >= 0<br />

and -x if x < 0.<br />

Power<br />

yields x raised to the y’th power.<br />

There is often confusion on how integer division, remainder and modulus work on negative<br />

numbers. In fact, there are two valid answers to -14 div 3: either (the intuitive) -4 as in<br />

the Toolbox, or -5 as in e.g. Standard ML [Paulson91]. It is therefore appropriate to explain<br />

these operations in some detail.<br />

Integer division is defined using floor and real number division:<br />

✞<br />

✡✝<br />

x/y < 0: x div y = -floor(abs(-x/y))<br />

x/y >= 0: x div y = floor(abs(x/y))<br />

✆<br />

9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!