### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: [closed]Variable Declaration Completion as Double  (Read 1394 times)

#### m.abudrais

• Jr. Member
• Posts: 51
##### [closed]Variable Declaration Completion as Double
« on: May 02, 2019, 08:32:06 am »
Code: Pascal  [Select][+][-]
1. procedure TForm1.Form1Create(Sender: TObject);
2. begin
3.   MyFloat:=3.1;
4. end;
when I press  ctrl +shift +c  MyFloat is declared as Extended, is there an option to change it to Double?
« Last Edit: May 03, 2019, 10:09:10 am by m.abudrais »

• Hero Member
• Posts: 10449
##### Re: Variable Declaration Completion as Double
« Reply #1 on: May 02, 2019, 10:47:16 am »
Depends on your platform: if it is Windows 64 a double is the exact same as extended......

In general the resolution is chosen as the maximum available, though, for floats, whereas with integers the minimum is chosen.
« Last Edit: May 02, 2019, 10:53:42 am by Thaddy »
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

#### lucamar

• Hero Member
• Posts: 3019
##### Re: Variable Declaration Completion as Double
« Reply #2 on: May 02, 2019, 12:31:30 pm »
Code: Pascal  [Select][+][-]
1. procedure TForm1.Form1Create(Sender: TObject);
2. begin
3.   MyFloat:=3.1;
4. end;
when I press  ctrl +shift +c  MyFloat is declared as Extended, is there an option to change it to Double?

Seems to be fixed: For FP values, Extended, for integers, Integer, etc. Even if you try something like:
Code: Pascal  [Select][+][-]
1.  Big := 5000000000;
which requires a 64 bit integer, completion declares Big as Integer (which in 32 bits, like here, is LongInt).
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!)
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

#### m.abudrais

• Jr. Member
• Posts: 51
##### Re: Variable Declaration Completion as Double
« Reply #3 on: May 02, 2019, 02:29:21 pm »
I use lazarus 2.0.2 32bit, but my OS is win7 64bit

• Hero Member
• Posts: 10449
##### Re: Variable Declaration Completion as Double
« Reply #4 on: May 02, 2019, 02:45:15 pm »
The 32 bit Windows Lazarus  should choose true extended (80 bits) instead of double...Even on a 64 bit Windows system... I can't test this, but that may be a bug.. (I have no 32 bit windows software installed since a very long time).
If this is the case, report it against Lazarus IDE because the compiler does everything correct in your case.
I am not aware of any options you asked for, as per my first answer.
« Last Edit: May 02, 2019, 02:55:04 pm by Thaddy »
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

#### lucamar

• Hero Member
• Posts: 3019
##### Re: Variable Declaration Completion as Double
« Reply #5 on: May 02, 2019, 03:06:06 pm »
The 32 bit Windows Lazarus  should choose true extended (80 bits) instead of double...Even on a 64 bit Windows system... I can't test this, but that may be a bug.. (I have no 32 bit windows software installed since a very long time).
If this is the case, report it against Lazarus IDE because the compiler does everything correct in your case.
I am not aware of any options you asked for, as per my first answer.

It does choose Extended which in 32 bits will be the true 80bit extended and in 64 bits will be an alias for Double, IIRC.

What is "funny" (whether a bug or a simplistic view of the world) is completing as Integer a variable which is being assigned a value greater than MaxLongInt. My guess is that CodeTools looks to see whether it's a float; if it's it declares it as Extended, if not as Integer.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!)
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

• Hero Member
• Posts: 10449
##### Re: Variable Declaration Completion as Double
« Reply #6 on: May 02, 2019, 03:21:59 pm »
What is "funny" (whether a bug or a simplistic view of the world)
That's a feature request....

Anyway, I fear you are right and it is a bug in CodeTools or the IDE.

And quite likely what you implicitly describe..if you mean that the IDE seems to pick platform instead of compiler bitness 64 vs 32 which also means 64 fpu vs 80 bit fpu.
« Last Edit: May 02, 2019, 03:27:25 pm by Thaddy »
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

#### m.abudrais

• Jr. Member
• Posts: 51
##### Re: Variable Declaration Completion as Double
« Reply #7 on: May 02, 2019, 05:38:33 pm »
Quote
It does choose Extended which in 32 bits will be the true 80bit extended
yes the SizeOf(MyFloat) is 10
thank you all.

• Hero Member
• Posts: 10449
##### Re: Variable Declaration Completion as Double
« Reply #8 on: May 02, 2019, 06:11:48 pm »
Plz mark as closed?
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

#### lucamar

• Hero Member
• Posts: 3019
##### Re: Variable Declaration Completion as Double
« Reply #9 on: May 02, 2019, 07:30:38 pm »
And quite likely what you implicitly describe..if you mean that the IDE seems to pick platform instead of compiler bitness 64 vs 32 which also means 64 fpu vs 80 bit fpu.

I doesn't seem to pick much;  just a simple comparison of the style:
Code: [Select]
`If ItLooksLikeANumber then  if ItLooksLikeFloatingPoint then    AddVarType(Extended)  else    AddVarType(Integer)`
Funnier yet, if you do:
Code: Pascal  [Select][+][-]
1. procedure ThatsRight;
2. var
3.   test: Int64
4. begin
5.   i := 1 + test;
6. end;
It completes it as: var test, i: int64
but if you try:
Code: Pascal  [Select][+][-]
1. procedure ThatsRight;
2. var
3.   test: Int64
4. begin
5.   for i := 0 to test do;
6. end;
it completes i as: i: Integer;

A bit squizophrenic, isn't it?
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!)
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

#### Bart

• Hero Member
• Posts: 3904
##### Re: Variable Declaration Completion as Double
« Reply #10 on: May 02, 2019, 10:56:44 pm »
but if you try:
Code: Pascal  [Select][+][-]
1. procedure ThatsRight;
2. var
3.   test: Int64
4. begin
5.   for i := 0 to test do;
6. end;
it completes i as: i: Integer;

A bit squizophrenic, isn't it?

No it's not.
Loop variables must be ordinals.
Int64 is not an ordinal (in that sense, at least for the compiler. It is documented), at least not on 32-bit.
So declaring it as 32-bit integer (or 16-bit on DOS) is the safe thing to do.

Bart

#### m.abudrais

• Jr. Member
• Posts: 51
##### Re: Variable Declaration Completion as Double
« Reply #11 on: May 03, 2019, 10:10:02 am »