[fpc-devel] Overflow checks and Trunc/Round functions

Alexander Klenin klenin at gmail.com
Sat Jun 13 14:27:55 CEST 2009


On Sat, Jun 13, 2009 at 22:47, Jonas Maebe<jonas.maebe at elis.ugent.be> wrote:
>
> On 13 Jun 2009, at 13:31, Alexander Klenin wrote:
>
>> Currently, Round and Trunc functions ignore the state of $OVERFLOWCHECKS
>> compiler directive. The following code prints "-2 -2":
> In Borland-speak, these are not overflow errors, but range errors. Turn on
> range checking, and you will get an error.

Yes, this works.

> The difference between range and overflow errors is as follows:
> * range errors occur when an implicit type conversion occurs from one type
> to another (e.g., when assigning, or when using it as a parameter), and the
> value is not legal for the destination type
> * overflow errors occur when performing a mathematical operation on a value
> and the result cannot be represented in the type used for performing this
> operation (this "operation type" depends both on the target platform and the
> types of the operands)

It is debatable whether "Round" is an operation or conversion,
but I agree that this is a minor thing --
the important one is that there is a way to guard against overflows.

-- 
Alexander S. Klenin



More information about the fpc-devel mailing list