[fpc-devel]urgent: double + integer question/types in calculations

Konstantin Muenning koko at muenning.com
Wed Feb 6 18:27:29 CET 2002


On Wed, 6 Feb 2002, Michael Van Canneyt wrote:

>On Wed, 6 Feb 2002, raoul s wrote:
>
>> I have "a" as double and "b" as integer.
>> 1) how may I say "a := b" in pascal. "a" on left and
>> "b" on the
>> right.
(snip)

>The compiler does the typeconversion.
>
>
>> 2)can one way would be?:
>> a := b + 0.0;
>
>You can do that but it is not necessary.
>
>>
>> i like to keep the results for a as double.
>
>An assignment cannot change the type of the left side.

By the way, about types in calculations and assignments. What types are
used in FPC for doing the actual calculations. I have the experience with
Borland Pascal that I have to be carefull in some cases. P.ex.

VAR
 a:Integer;b,c:Word;
:
a:=b-c;
:

BP would use Word for the calculation so if c>b there would be (I think) a
range check error (if enabled). Changing it to

a:=-c+b;

would make BP to use Integer or LongInt (I'm not shure which) and the
result would be OK. In my opinion the calculation should base on the
result type, not on the types on the right side but that's what BP is
doing. hat does FPC?

Have a nice day,
Konstantin Münning              ,,,
-------------------------------/'^'\------------------------------------
www.muenning.com              ( o o )                  koko at muenning.com
--------------------------oOOO--(_)--OOOo-------------------------------
            Beware of Programmers who carry screwdrivers.
                                    -- Leonard Brandwein
                               (-O-)
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places no one has
ever been.                          -- Alan Ashley-Pitt





More information about the fpc-devel mailing list