2013/4/25 David MacMahon <davidm / astro.berkeley.edu>:
>
> On Apr 24, 2013, at 7:03 PM, Heesob Park wrote:
>
>> 2013/4/25 David MacMahon <davidm / astro.berkeley.edu>
>>>
>>> Nice work tracking this down!
>>>
>>> I don't understand how it fixes the compiler specific aspect of the
>>> problem you found where gcc 4.5.2 on MinGW had the problem but gcc 4.7.2 on
>>> MinGW did not.  Does gcc 4.7.2 on MinGW already automatically do whatever
>>> "_control87(_PC_53, _MCW_PC)" does, but gcc 4,5,2 on MinGW does not
>>> automatically do it so it needs to be done explicitly?
>>>
>> The console application built with mingw32 compiler  calls _fpreset
>> funciton at startup.
>> The _fpreset function is defined in MSVCRT.dll which set FP default
>> precision to 53 bit mantissa.
>>
>> But in mingwrt-3.18 library which bundled in mingw32 4.7.2 redefined
>> _fpreset function to change FP default precision from 53 to 64-bit
>> mantissa.
>> Actually, the "_control87(_PC_53, _MCW_PC)" means lowering precision
>> from 64 to 53-bit mantissa.
>
> Thanks for the information, but I'm still confused.  The above sounds like gcc 4.7.2 uses a higher precision (64 bit mantissa) than strtod expects (53 bit mantissa), yet in an earlier message you wrote:

The higher precision produce the undesired result in the magic number
(-1.1505945E-5).
 -1.1505945000000001e-05 instead of -1.1505945e-05.

>> gcc 4.5.2 built version(rubyinstaller version) shows not disired result.
>> But gcc 4.7.2 and MSVC v16.0 built version shows a correct result.
>
> Not a big problem, I'm just trying to understand things.  Am I misreading/misinterpreting things?

I just mentioned the issue is occurred on mingw32 gcc 4.5.2 compiler
due to the excess precision.

>
>> BTW, why we should consider  FP precision?
>> When converting string value to double value, ruby calls ruby_strtod
>> function instead of native strtod function.
>> The ruby_strtod function is based on David M. Gay's netlib library
>> which requires double-precision (53-bit) rounding precision.
>
> This raises the question of whether Ruby really supports "the native architecture's double-precision floating point representation" as described on Float's RDoc.  Does strtod work properly on systems that use something other than IEEE 754 binary64 (e.g. VAX)?

I have no idea why ruby call David M. Gay's strtod instead of native
strtod funciton.

>>> Is the __MINGW32__ macro enough of a check?  I wonder if it could enable
>>> the _control87 call on system where it is not present.
>>>
>> Ruby 1.9.x requires Windows 2000 or later OS which requires Pentium CPU.
>> And most x86 processors since the Intel 80486 have had x87
>> instructions implemented in the main CPU.
>> I cannot imagine a system with Windows 2000 and not present x87 instructions.
>
> There is Windows RT...
>
> http://en.wikipedia.org/wiki/Windows_RT
>
> ...but I don't know whether Ruby runs on it. :-)
>
The patch can be more strict like this:
#if defined(__MINGW32__) && defined(_M_IX86)
    _control87(_PC_53, _MCW_PC);
#endif


Regards,
Park Heesob