lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 0b31777 4/5: Include both <cmath> and <math.h


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 0b31777 4/5: Include both <cmath> and <math.h> in a unit test
Date: Tue, 2 May 2017 14:56:23 -0400 (EDT)

branch: master
commit 0b317771104494ecdce8d48093e0c9ab20bfa4a4
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Include both <cmath> and <math.h> in a unit test
    
    Both C99 ::round() and C++11 ::std::round are tested, so it is
    apparently necessary to include both <cmath> and <math.h>; cf.:
      https://gcc.gnu.org/ml/gcc-help/2017-03/msg00018.html
---
 round_test.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/round_test.cpp b/round_test.cpp
index d6f948e..8a0b571 100644
--- a/round_test.cpp
+++ b/round_test.cpp
@@ -38,10 +38,11 @@
 #include "test_tools.hpp"
 
 #include <algorithm>                    // std::max()
+#include <cmath>                        // std::round()
 #include <cstddef>                      // std::size_t
 #include <ios>
 #include <iostream>
-#include <math.h>                       // C99 round() and kin
+#include <math.h>                       // ::round[,f,l]() and kin
 #include <ostream>
 
 // Print name of software rounding style for diagnostics.
@@ -171,6 +172,13 @@ void print_hex_val(T t, char const* name)
 // GWC modifications end
 }
 
+/// Emulate std::round() in order to test it. This may seem somewhat
+/// silly, because elsewhere a conforming C++11 implementation is
+/// presumed. However, std::round() calls for extraordinary testing
+/// because its MinGW-w64 CRT implementation is known to be defective,
+/// so it is not to be assumed that its C++ overloads are flawless
+/// (even though they probably come from an unmarred libstdc++).
+
 template<typename T> T roundFDL(T) {throw std::domain_error("Unknown float 
type.");}
 template<> float       roundFDL<float      >(float       t) {return roundf(t);}
 template<> double      roundFDL<double     >(double      t) {return round (t);}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]