Recent

Author Topic: How to turn on FPC_HAS_TYPE_COMP  (Read 5556 times)

staroski

  • Newbie
  • Posts: 2
    • Staroski
How to turn on FPC_HAS_TYPE_COMP
« on: September 26, 2016, 08:24:02 pm »
Hello there

I'm working on the migration of a legacy Delphi source code to Lazarus.
The legacy code has many references to the 'MinComp' and 'MaxComp' constants declared in 'math' unit.

Looking at math.pp I saw that the contants are defined this way:
{$ifdef FPC_HAS_TYPE_COMP}
    const
      MinComp      = -9.223372036854775807e+18;
      MaxComp      =  9.223372036854775807e+18;
{$endif FPC_HAS_TYPE_COMP}

 
I tried to enable the 'ifdef' with the option:
-dFPC_HAS_TYPE_COMP

But it looks like that -d doesn't work for 'FPC_HAS_TYPE_COMP'.

How should I proceed to enable it?

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: How to turn on FPC_HAS_TYPE_COMP
« Reply #1 on: September 26, 2016, 08:35:05 pm »
FPC_HAS_TYPE_COMP is automatically defined when FPDOC_MATH definition is available.

And that rings an alarm bell. It is only present when the documentation is generated.

A peek into the documentation states:
Quote
The Comp type is, in effect, a 64-bit integer and is not available on all target platforms.
So, the question becomes for which target are you compiling ? It might be that type comp is not available for that target, and since it is something declared inside RTL you would need to enable it inside there.

staroski

  • Newbie
  • Posts: 2
    • Staroski
Re: How to turn on FPC_HAS_TYPE_COMP
« Reply #2 on: September 27, 2016, 07:32:39 pm »
Hello molly, thank you for the answer, I'm compiling for 32 bit.

I guess that Delphi 5 did not concern about the processor's Comp type support and allows developers to use it even if the processor doesn't support it.

In fact I'm a Java developer evaluating if it's affordable to use Lazarus to maintain a system that was written 20 years ago in Delphi 5.

The company doesn't want to rewrite the system in other language neither want to acquire a newer Delphi version nor wants to continue paying Borland's Delphi 5 license.

Regards.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: How to turn on FPC_HAS_TYPE_COMP
« Reply #3 on: September 27, 2016, 07:50:08 pm »
Would it perhaps be possible to rewrite using another one of the Free Pascal's available floating point types ?

If there is specific tampering with the internal storage format you would have to rewrite that but, otherwise it could be a simple case of declaring your own comp type as one of the existing available floating point types. But mathematical calculations/rounding etc. can be very specific in certain circumstances so that trick might perhaps not work as expected.

There's only one way to find out :)

Thaddy

  • Hero Member
  • *****
  • Posts: 14369
  • Sensorship about opinions does not belong here.
Re: How to turn on FPC_HAS_TYPE_COMP
« Reply #4 on: September 27, 2016, 08:08:48 pm »
http://wiki.freepascal.org/Variables_and_Data_Types
Comp is supported by default on all platforms that can express it, icluding linux, windows,arm, whatever.
Code: Pascal  [Select][+][-]
  1. program untitled;
  2. {$apptype console}
  3. begin
  4. writeln(Low(comp),' and ',High(comp));
  5. end.

Output on Raspberry Pi/Raspbian:
Code: [Select]
-9223372036854775808 and 9223372036854775807
Which is correct. Same on win32/64 and linux debian 64



That specific define is just for compiling the compiler and parsing docs, not for plain usage.

So I guess it is a bit of a non-issue. Comp just works. I guess you will have more problems translating your D5 code to more modern Delphi or FPC equivalents like D2007/FPC3.0

« Last Edit: September 27, 2016, 08:21:57 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Thaddy

  • Hero Member
  • *****
  • Posts: 14369
  • Sensorship about opinions does not belong here.
Re: How to turn on FPC_HAS_TYPE_COMP
« Reply #5 on: September 27, 2016, 08:24:18 pm »
Delphi or FPC equivalents like D2007/FPC3.0 I wrote that because these are more than 99.9% compatible in most but the real exotic cases. Very high.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11449
  • FPC developer.
Re: How to turn on FPC_HAS_TYPE_COMP
« Reply #6 on: September 27, 2016, 08:40:10 pm »
comp and extended are additional types of the x87 floating point processor. They are only supported on targets where such fpu unit is supported.

The have_* are mostly set in the compiler (and the fpdoc parser has to set them to emulate that), they can't be turned on or off anyway.

Since D4 and FPC 2.0.0 there is a new type, int64 that can be used as replacement, and the use of comp is discouraged.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: How to turn on FPC_HAS_TYPE_COMP
« Reply #7 on: September 27, 2016, 08:41:35 pm »
So I guess it is a bit of a non-issue. Comp just works.
Well, on both links presented it is listed as the type not present for other processors. So it seems that documentation needs an update. Consider it my bad.

However, TS problem is existent in that mincomp and maxcomp does not seem defined/present for all platforms (just checked).

If that is TS only problem, then simply define them yourself ?
« Last Edit: September 27, 2016, 08:50:41 pm by molly »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11449
  • FPC developer.
Re: How to turn on FPC_HAS_TYPE_COMP
« Reply #8 on: September 27, 2016, 08:52:41 pm »
If that is TS only problem, then simply define them yourself ?

If the type is not available, then neither is the corresponding memory format (for constants and literals), so they will be represented in a different type.

Thaddy

  • Hero Member
  • *****
  • Posts: 14369
  • Sensorship about opinions does not belong here.
Re: How to turn on FPC_HAS_TYPE_COMP
« Reply #9 on: September 27, 2016, 08:54:39 pm »
comp and extended are additional types of the x87 floating point processor. They are only supported on targets where such fpu unit is supported.
...
Since D4 and FPC 2.0.0 there is a new type, int64 that can be used as replacement, and the use of comp is discouraged.
I was under the same impression, but:
That's why I added example code on an arm-debian platform/
OP should have no problems with his code.

maybe:
Code: Pascal  [Select][+][-]
  1. program untitled;
  2. const
  3.   mincomp  = low(comp);
  4.   maxcomp = high(comp);
  5. begin
  6. writeln(mincomp,' and ',maxcomp);
  7. end.
  8.  
is enough.
Note this is porting, so backwards deprecated features are still allowed ;)
« Last Edit: September 27, 2016, 08:58:56 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018