Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2002-02

urgent: double + integer question

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

raoul s

Hi,

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.

2)can one way would be?:
a := b + 0.0;

i like to keep the results for a as double.

raoul

__________________________________________________ Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com

Reply by email

Michael Van Canneyt
to raoul s
raoul s wrote 7 lines
Hi, 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.

Just write

  a:=b;

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.

Michael.

Reply by email

Konstantin Muenning
to Michael Van Canneyt
Michael Van Canneyt wrote 6 lines
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)

Show quoted text 12 lines
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 )
--------------------------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

Reply by email

Jonas Maebe
to Konstantin Muenning
Konstantin Muenning wrote
By the way, about types in calculations and assignments. What types are used in FPC for doing the actual calculations.

All binary expressions are evaluated as

a) extended if one of the operands is a floating point type (single, real/double, extended)
b) qword if both are qword
c) int64 if one of them is an int64, or if one is cardinal and the other is signed and range or overflow checking is on
d) cardinal if both are cardinal
e) longint in all other cases (so word + word is evaluated as longint)

Jonas

Reply by email