Bug #7142

mingw TestFloat#test_round_with_precision failure

Added by Hiroshi Shirosaki over 1 year ago. Updated over 1 year ago.

[ruby-core:47911]
Status:Closed
Priority:Normal
Assignee:-
Category:-
Target version:2.0.0
ruby -v:ruby 2.0.0dev (2012-10-09 trunk 37127) [i386-mingw32] Backport:

Description

=begin
Trunk ruby on Windows XP x86 with mingw-w64 gcc 4.7.2 has the following test failure.

1) Failure:
testroundwithprecision(TestFloat) [C:/Users/Worker/Jenkins/workspace/ruby-trunk-x86-build/test/ruby/testfloat.rb:389]:
expected but was
.

I get the failure with make test-all TESTS="-qv -n test_round_with_precision".

But it's strange that I don't get the failure with make test-all TESTS="-qv ruby/test_float.rb".
And This failure doesn't occur on Win7.

Floating-point precision seems to be changed for some reason. Mingw-w64 has own pow() implementation and the precision of pow(10, ndigits) is not proper.
I found calling (({controlfp(PC64, _MCWPC)})) before pow() improves precision and fixes this failure.

I'll commit this patch if there is no other better fix.

Index: include/ruby/win32.h
===================================================================
--- include/ruby/win32.h (revision 37136)
+++ include/ruby/win32.h (working copy)
@@ -764,7 +764,7 @@
} /* extern "C" { */
#endif

-#ifdef MINGW64
+#if defined(MINGW64)
/*
* Use powl() instead of broken pow() of x8664-w64-mingw32.
* This workaround will fix test failures in test
bignum.rb,
@@ -775,6 +775,24 @@
{
return powl(x, y);
}
+#elif defined(MINGW64VERSIONMAJOR)
+/*
+ * Set floating point precision for pow() of mingw-w64 x86.
+ * With default precision the result is not proper on WinXP.
+ /
+static inline double
+rbw32pow(double x, double y)
+{
+ double r;
+ unsigned int defaultcontrol = _controlfp(0, 0);
+ _controlfp(
PC64, _MCWPC);
+ r = pow(x, y);
+ /
Restore setting */
+ controlfp(defaultcontrol, MCWPC);
+ return r;
+}
+#endif
+#if defined(
MINGW64VERSIONMAJOR) || defined(MINGW64)
#define pow rbw32pow
#endif

=end

Associated revisions

Revision 37168
Added by shirosaki over 1 year ago

win32.h: set floating point precision for pow()

  • include/ruby/win32.h (rbw32pow): set floating point precision for mingw-w64 x86 pow(). This improves the precision of pow() on Windows XP for TestFloat#testroundwith_precision failure. [Bug #7142]

History

#1 Updated by Anonymous over 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r37168.
Hiroshi, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


win32.h: set floating point precision for pow()

  • include/ruby/win32.h (rbw32pow): set floating point precision for mingw-w64 x86 pow(). This improves the precision of pow() on Windows XP for TestFloat#testroundwith_precision failure. [Bug #7142]

Also available in: Atom PDF