2

I'm programming a Tool which allows you to convert a given Numbers (Dec, Bin, Hex) in a specific Date Format (Unix Time, HFS, Fat-Time,...) into an human readable date-string.

I have a problem with Windows OLE-Date, which represents the Date and Time in an double value. Now I get different output in Windows and Unix. It is only a second difference in the Outputdate, but I want to generate the same output on Windows and Unix platforms.

I'm using long double to store the value. I know that Visual Studio C++ compiler and gcc use different precisions for long double. Is there an alternative which uses the same precision on both platforms?

phuclv
  • 37,963
  • 15
  • 156
  • 475
user2071938
  • 2,055
  • 6
  • 28
  • 60
  • What CPUs do you need to support? Only x86_64, or anything more? – Tadeusz A. Kadłubowski Feb 24 '14 at 10:44
  • Microsoft C / C++ compilers dropped support for long doubles (80 bit) when they first started making 32 bit compilers. long doubles are cast to regular doubles (64 bit). Regular doubles should be the same with most X86 compilers. – rcgldr Feb 24 '14 at 11:05
  • why don't you use a different date data type? Dates format are different on different platforms. Also, GCC has windows version, in which long double is still 10 bytes – phuclv Feb 24 '14 at 12:07

1 Answers1

0

Why is it necessary to use long double when Windows OLE-Date is a double? Just use double for all platforms and it'll still be good for decades or even centuries

In case a higher resolution is really needed then there are many solutions

  • Use a struct with 2 fields for second and fractional second, just like struct timespec

    struct timespec {
        time_t    tv_sec;
        long      tv_nsec;
    };
    

    When a double is returned, just split it into the int part and fractional part and store them internally in the struct. Convert the struct back to double when required

  • Use 80-bit extended precision long double on all platforms. On Windows this can be easily done by using other compilers like GCC, Clang or ICC. They allow you to change the format or long double, for example in GCC there are the -mlong-double-64/80/128 and -m96/128bit-long-double flags and ICC has /Qlong-double

phuclv
  • 37,963
  • 15
  • 156
  • 475