3

At work we have MSVS2010 Ultimate, and I'm writing a program which runs exhaustive simulations using real numbers. I'm getting non-trivial round-off errors and I've already taken reasonable steps to ensure my algorithm is as numerically stable as possible.

I'd like to switch to 128-bit quadruple precision floating point numbers (long double, right?), to see how much of a difference it makes.

I've replaced all relevant instances of double with long double, recompiled, and ran my dummy simulation again but have exactly the same result as before.

These are my (debug) compiler options as per my project property page in C/C++:

/ZI /nologo /W3 /WX- /Od /Oy- /D "_MBCS" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"Debug\FFTU.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze- /errorReport:queue

My dev CPU is a Core2 Duo T7300 but the target machine will be an i7. Both installations are Windows 7 64-bit.

Ozzah
  • 10,631
  • 16
  • 77
  • 116
  • 4
    With Visual C++, `long double` is the same as `double`, hence why the result is the same http://msdn.microsoft.com/en-us/library/s3f49ktz(v=VS.100).aspx – James McNellis Sep 21 '11 at 23:06
  • I see. Is there any other way to get 128-bit quadruple precision in VS2010 in Windows? (without using any 3rd party libraries like GMP. Windows.h is ok though). – Ozzah Sep 21 '11 at 23:11
  • 3
    Do you think your CPU provides 128-bit floating point? x87 only supports 32, 64, and 80 bits (I'm not an expert on the subject, but I don't think SSE provides any uberwise floating point capabilities either). – James McNellis Sep 21 '11 at 23:13
  • 1
    The reply above isn't really fair. C++ libraries used to work with floating point even when an 8087 co-processor wasn't present. So with this in mind, another solution would be to find a math library that allows the precision you want. It would be an awful lot slower, but at least it would work. – Robinson Sep 21 '11 at 23:39
  • Your problem most likely be solved with a wider float. – David Heffernan Sep 21 '11 at 23:57
  • @Robinson Yes, I was a little confused by the comment. I remember doing 64-bit double-precision stuff back on my 386 which didn't have any 64-bit hardware; and `long double` has been part of C since 1989. I don't think software libraries are really suitable since they have a tremendous affect on performance, which is crucial in my application. I will try GCC and 80-bit extended precision like wallyk suggested. – Ozzah Sep 22 '11 at 00:12

1 Answers1

2

You could switch to a non-Microsoft compiler such as gcc, Borland, or Intel. Those all recognize long double as 80-bit extended precision, the native internal format of the 8087.

wallyk
  • 56,922
  • 16
  • 83
  • 148
  • 2
    On gcc-4.3.4 `sizeof(long double)` is 12. [ideone.com](http://ideone.com/TLbiS). VC++ `doubles` use 80-bit registers to hold the intermediate results of floating-point calculations, but are stored with 64-bits in memory. – JohnPS Sep 22 '11 at 00:36