<div dir="rtl"><div dir="ltr">(this is slightly modfied version of patch posted on 4 Oct 2013)</div><div dir="ltr"><br></div><div dir="ltr">Long ago Microsoft had decided (<a href="http://msdn.microsoft.com/en-us/library/9cx8xs15.aspx">http://msdn.microsoft.com/en-us/library/9cx8xs15.aspx</a>) to make thelong double type in Visual C++ same as double, 64 bit. This was an incredibly stupid decision, at least for those of us who actually care about numeric accuracy.<br>

<br>MingW, gcc-based port for Windows, had kept 80-bit long doubles and so does clang. This is a good decision which enable using these compilers in numeric code where 80 bit long doubles are required.<br><br>However, MingW uses the Microsoft runtime DLL msvcrt.dll. Here lies a problem: while gcc creates 80 bits long doubles, the MS runtime accepts 64 bit long doubles only. The problem is usually not obvious since the long double is casted to a double, as in:<br>

<br><font face="courier new, monospace"> exp(10.0L)<br></font><br>where the 10.0L will be silently cast to 10.0 and the routine will seem to work.<br><br>However, in the *printf and *scanf family of functions arguments are not downcasted from long double to double (float does cast to double). For instance, naively compiling<br>

<br><font face="courier new, monospace"> printf("%Lf\n",2345.0L);<br></font><br>with gcc or clang with the MingW runtime will print garbage results.<br><br>The MingW developers did develop a solution to the problem, namely alternative __mingw_printf and __mingw_scanf family of functions that accept long double 80 bit arguments properly.  In order to use the correct routines, one has to<br>

<br><font face="courier new, monospace">#define __USE_MINGW_ANSI_STDIO 1<br></font><br>which is not the default in libc but it is defined in gcc libstdc++ library header "os_defines.h" as default. </div><div dir="ltr">

<b><br></b></div><div dir="ltr">However, for snprintf_l there is no MingW alternative, it is simply #defined to _snprintf_l, a function from msvcrt.dll which does not support 80 bit long doubles. <br></div><div dir="ltr">

<br>This patch implements snprintf_l  function in a way similar to the other functions in src/support/win32/locale_win32.cpp and locale_win32.h, calling upon vsnprintf for which there is a MingW correct alternative.</div>

<div dir="ltr"><br></div><div dir="ltr"><div dir="ltr"><b>Note! </b><span style="font-family:'courier new',monospace">__USE_MINGW_ANSI_STDIO </span>is not modified in this patch. In order to use the __mingw version it must be defined before including the MingW headers.</div>

<div dir="ltr"><br></div></div></div>