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

Mailing lists / fpc-pascal / 2018-01
8 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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
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
Comp is Int64 div 10000.
Thanks for the explanation Mathias!
Mattias Gaertner wroteComp 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
Thanks. Good to know.
I guess I got confused by the 'real' in Darius qeustion.
Mattias
AFAIK there is a small difference between comp and int64
COMP is 63bit + sign bit
int64 is 2s complement.
I hope I am right here.
Markus
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
By the way there was a bug in fpc 3.0.
I am not sure if it is fixed yet.
Dividing a comp number by any other number gives wrong results. Please see my posting from 29.06.2016
Markus