Double and LongWord

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Double and LongWord

Carsten Bager
Hi
This Function works on Intel platforms but when compiled to Arm (Linux) the right side is
calculated as a LongWord.

Const
  cSecondsPerDay=86400.0;
  cTimeDate2UnixFiledateStart=25569.0;
  cUnixFileDateDateTimeStart=cSecondsPerDay*cTimeDate2UnixFiledateStart;

Function UnPackUnixTime2DateTime(UnixTime:LongWord):TDateTime;
Begin
  UnPackUnixTime2DateTime:=(UnixTime+cUnixFileDateDateTimeStart)/cSecondsPerDay;
End;

---

If I change the line to

UnPackUnixTime2DateTime:=(UnixTime+Double(cUnixFileDateDateTimeStart))/Double(cSe
condsPerDay);

It works

I am not sure if this is an error or not, but al previous compilers I have worked with, change to
real calculation on the right side when constants included, is defined as real constants.

---

What do you think?


The compiler used is
Free Pascal Compiler version 2.6.2 [2013/07/16] for arm
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Linux for ARM


Regards
Carsten

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Double and LongWord

Jonas Maebe-2

On 22 Nov 2013, at 10:56, Carsten Bager wrote:

> This Function works on Intel platforms but when compiled to Arm  
> (Linux) the right side is
> calculated as a LongWord.
>
> Const
>  cSecondsPerDay=86400.0;
>  cTimeDate2UnixFiledateStart=25569.0;
>  
> cUnixFileDateDateTimeStart=cSecondsPerDay*cTimeDate2UnixFiledateStart;
>
> Function UnPackUnixTime2DateTime(UnixTime:LongWord):TDateTime;
> Begin
>  UnPackUnixTime2DateTime:=(UnixTime+cUnixFileDateDateTimeStart)/
> cSecondsPerDay;
> End;

On all platforms the compiler will evaluate this expression using  
single precision, because all used floating point constants fit in  
single precision. The x87 is however limited in the sense that it can  
only perform calculations using extended precision, so you won't  
notice it there. You should probably also typecast  
cUnixFileDateDateTimeStart to double precision because otherwise you  
may encounter overflows if UnixTime is too large.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal