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

Jonas Maebe jonas.maebe at elis.ugent.be
Sat Jun 13 17:18:07 CEST 2009


On 13 Jun 2009, at 14:27, Alexander Klenin wrote:

> On Sat, Jun 13, 2009 at 22:47, Jonas  
> Maebe<jonas.maebe at elis.ugent.be> wrote:
>>
>> 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.

Round itself does not cause any error, as it returns an int64. It's  
the assignment of the result of round() to your longint variable that  
triggers the range check (error).


Jonas



More information about the fpc-devel mailing list