Sign in Join

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

Mailing lists / fpc-pascal / 2018-01

Comp type

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Darius Blaszyk

By accident I noticed the comp type for the first time. It's an Int64 but is considered to be a real type. Just out of curiosity, what is the use case of such a type, or is this just implemented for compatibility reasons?

Rgds, Darius

Reply by email

Mattias Gaertner
to Darius Blaszyk
By accident I noticed the comp type for the first time. It's an Int64 but is considered to be a real type. Just out of curiosity, what is the use case of such a type, or is this just implemented for compatibility reasons?

Comp is Int64 div 10000. So it is a real, but not a float. This has some advantages computing things like money. For example it can represent numbers like 0.3 exactly, which is not possible with double.
Also computing integers is often faster than doubles.

Mattias

Reply by email

Jonas Maebe
Mattias Gaertner wrote
Comp is Int64 div 10000.

No, that is currency. Comp is a plain 64 bit integer. It originally comes from Turbo Pascal, which did not have a regular 64 bit integer type. The x87 fpu can be used to perform 64 bit integer math though, so it was originally a 64 bit integer type whose calculations were performed using the fpu.

In FPC, it's the same on platforms that still use the x87 fpu. On other platforms, comp is an alias for the int64 type.

Jonas

Reply by email

Mattias Gaertner
to Jonas Maebe
Show quoted text 11 lines
Mattias Gaertner wrote: > Comp is Int64 div 10000. No, that is currency. Comp is a plain 64 bit integer. It originally comes from Turbo Pascal, which did not have a regular 64 bit integer type. The x87 fpu can be used to perform 64 bit integer math though, so it was originally a 64 bit integer type whose calculations were performed using the fpu. In FPC, it's the same on platforms that still use the x87 fpu. On other platforms, comp is an alias for the int64 type.

Thanks. Good to know.

I guess I got confused by the 'real' in Darius qeustion.

Mattias

Reply by email

Tony Whyman
to Jonas Maebe: No, that is currency. Comp is a plain 64 bit integer. It originally comes from Turbo…

Thanks for the history. Comp has always puzzled me before, especially with these two functions from the RTL

function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;

I assume that these have come down from Turbo Pascal - but it still seems odd that milliseconds is represented by a "real" type.

Tony Whyman

Jonas Maebe wrote 17 lines
Mattias Gaertner wrote: > Comp is Int64 div 10000. No, that is currency. Comp is a plain 64 bit integer. It originally comes from Turbo Pascal, which did not have a regular 64 bit integer type. The x87 fpu can be used to perform 64 bit integer math though, so it was originally a 64 bit integer type whose calculations were performed using the fpu. In FPC, it's the same on platforms that still use the x87 fpu. On other platforms, comp is an alias for the int64 type. Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email