|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71294 - trunk/libs/math/test
From: pbristow_at_[hidden]
Date: 2011-04-15 13:29:27
Author: pbristow
Date: 2011-04-15 13:29:26 EDT (Fri, 15 Apr 2011)
New Revision: 71294
URL: http://svn.boost.org/trac/boost/changeset/71294
Log:
Helper files for nonfinite tests.
Added:
trunk/libs/math/test/S_.ipp (contents, props changed)
trunk/libs/math/test/almost_equal.ipp (contents, props changed)
Added: trunk/libs/math/test/S_.ipp
==============================================================================
--- (empty file)
+++ trunk/libs/math/test/S_.ipp 2011-04-15 13:29:26 EDT (Fri, 15 Apr 2011)
@@ -0,0 +1,64 @@
+#ifndef BOOST_MATH_S__HPP
+#define BOOST_MATH_S__HPP
+
+// Copyright (c) 2006 Johan Rade
+
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// The macro S_ lets you write
+//
+// basic_string<CharType> s = S_("foo");
+// CharType c = S_('a');
+//
+// provided that CharType is char or wchar_t
+
+#include <string>
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable : 4512)
+#endif
+
+//------------------------------------------------------------------------------
+
+#define S_(a) make_literal_helper(a, L##a)
+
+class char_literal_helper {
+public:
+ char_literal_helper(char c, wchar_t wc) : c_(c), wc_(wc) {}
+ operator char() { return c_; }
+ operator wchar_t() { return wc_; }
+private:
+ const char c_;
+ const wchar_t wc_;
+};
+
+class string_literal_helper {
+public:
+ string_literal_helper(const char* s, const wchar_t* ws) : s_(s), ws_(ws) {}
+ operator std::string() { return s_; }
+ operator std::wstring() { return ws_; }
+private:
+ const char* s_;
+ const wchar_t* ws_;
+};
+
+inline char_literal_helper make_literal_helper(char c, wchar_t wc)
+{
+ return char_literal_helper(c, wc);
+}
+
+inline string_literal_helper make_literal_helper(char* s, wchar_t* ws)
+{
+ return string_literal_helper(s, ws);
+}
+
+//------------------------------------------------------------------------------
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
Added: trunk/libs/math/test/almost_equal.ipp
==============================================================================
--- (empty file)
+++ trunk/libs/math/test/almost_equal.ipp 2011-04-15 13:29:26 EDT (Fri, 15 Apr 2011)
@@ -0,0 +1,20 @@
+#ifndef BOOST_MATH_ALMOST_EQUAL_HPP
+#define BOOST_MATH_ALMOST_EQUAL_HPP
+
+// Copyright (c) 2006 Johan Rade
+
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cmath>
+
+template<class ValType>
+bool almost_equal(ValType a, ValType b)
+{
+ const ValType e = static_cast<ValType>(0.00001);
+ return (a - e * std::abs(a) <= b + e * std::abs(b))
+ && (a + e * std::abs(a) >= b - e * std::abs(b));
+}
+
+#endif
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk