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 _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
On Tue, 09 Jan 2018 22:58:01 +0100
Darius Blaszyk <[hidden email]> wrote: > 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 _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
> Comp is Int64 div 10000.
Thanks for the explanation Mathias! _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
In reply to this post by Mattias Gaertner
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 - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
On Wed, 10 Jan 2018 09:04:12 +0100
Jonas Maebe <[hidden email]> wrote: > 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 _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
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 _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
In reply to this post by Jonas Maebe-3
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 On 10/01/18 08:04, Jonas Maebe wrote: > 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 - [hidden email] > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
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 _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
Free forum by Nabble | Edit this page |