# HG changeset patch # User Jaroslav Hajek # Date 1251893900 -7200 # Node ID 8bea4e89326f4f59e8630f8432538c3f26eb839f # Parent dba091e1ee39b5feb4e6fd9f3d7c665fb1b89a29 implement FLOAT_STORE to allow safer complex comparisons on x87 diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-09-02 Jaroslav Hajek + + * configure.in (FLOAT_STORE): New config macro. + 2009-09-02 Jaroslav Hajek * acx_blas_f77_func.m4 (ACX_BLAS_F77_FUNC): Check for correct INTEGER diff --git a/configure.in b/configure.in --- a/configure.in +++ b/configure.in @@ -289,6 +289,23 @@ AC_SUBST(CARBON_LIBS) fi +### When compiling math for x87, problems may arise in some code comparing +### floating-point intermediate results. +### Generally, it helps to store the result in a local volatile variable, +### but it also degrades performance. +### Thus, we provide a FLOAT_TRUNCATE macro that may be defined to "volatile" +### when compiling for x87 target, or left empty for modern SSE math, that +### doesn't suffer from this problem at all. +AC_ARG_ENABLE(float-truncate, + [AS_HELP_STRING([--enable-float-truncate], + [enables truncating intermediate FP results.])], + [if test "$enableval" = yes; then ac_float_truncate=volatile; + else ac_float_truncate=; fi], + ac_float_truncate=) + +AC_DEFINE_UNQUOTED(FLOAT_TRUNCATE, $ac_float_truncate, + [Define to volatile if you need truncating intermediate FP results]) + ### On Intel systems with gcc, we may need to compile with -mieee-fp ### and -ffloat-store to get full support for IEEE floating point. ### diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2009-09-02 Jaroslav Hajek + + * oct-cmplx.h: Rewrite the comaprison ops. Use FLOAT_STORE. + 2009-09-01 Jaroslav Hajek * oct-cmplx.h: Correct strict operators in macros. diff --git a/liboctave/oct-cmplx.h b/liboctave/oct-cmplx.h --- a/liboctave/oct-cmplx.h +++ b/liboctave/oct-cmplx.h @@ -2,6 +2,7 @@ Copyright (C) 1995, 1996, 1997, 2000, 2001, 2004, 2005, 2007, 2008, 2009 John W. Eaton +Copyright (C) 2009 VZLU Prague, a.s. This file is part of Octave. @@ -40,21 +41,39 @@ template \ inline bool operator OP (const std::complex& a, const std::complex& b) \ { \ - T ax = std::abs (a), bx = std::abs (b); \ - return ax OPS bx || (ax == bx && std::arg (a) OP std::arg (b)); \ + FLOAT_TRUNCATE const T ax = std::abs (a), bx = std::abs (b); \ + if (ax == bx) \ + { \ + FLOAT_TRUNCATE const T ay = std::arg (a), by = std::arg (b); \ + return ay OP by; \ + } \ + else \ + return ax OPS bx; \ } \ template \ inline bool operator OP (const std::complex& a, T b) \ { \ - T ax = std::abs (a); \ - return ax OPS b || (ax == b && std::arg (a) OP 0); \ + FLOAT_TRUNCATE const T ax = std::abs (a); \ + if (ax == b) \ + { \ + FLOAT_TRUNCATE const T ay = std::arg (a); \ + return ay OP 0; \ + } \ + else \ + return ax OPS b; \ } \ template \ inline bool operator OP (T a, const std::complex& b) \ { \ - T bx = std::abs (b); \ - return a OPS bx || (a == bx && 0 OP std::arg (b)); \ -} \ + FLOAT_TRUNCATE const T bx = std::abs (b); \ + if (a == bx) \ + { \ + FLOAT_TRUNCATE const T by = std::arg (b); \ + return 0 OP by; \ + } \ + else \ + return a OPS bx; \ +} DEF_COMPLEXR_COMP (>, >) DEF_COMPLEXR_COMP (<, <)