|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54873 - in trunk: boost/units libs/units/test
From: steven_at_[hidden]
Date: 2009-07-10 17:26:58
Author: steven_watanabe
Date: 2009-07-10 17:26:57 EDT (Fri, 10 Jul 2009)
New Revision: 54873
URL: http://svn.boost.org/trac/boost/changeset/54873
Log:
Loosen the requirements on atan2. Fixes #3258
Added:
trunk/libs/units/test/test_trig.cpp (contents, props changed)
Text files modified:
trunk/boost/units/cmath.hpp | 6 +++---
trunk/libs/units/test/Jamfile.v2 | 1 +
2 files changed, 4 insertions(+), 3 deletions(-)
Modified: trunk/boost/units/cmath.hpp
==============================================================================
--- trunk/boost/units/cmath.hpp (original)
+++ trunk/boost/units/cmath.hpp 2009-07-10 17:26:57 EDT (Fri, 10 Jul 2009)
@@ -623,10 +623,10 @@
}
/// atan2 of @c value_type returning angle in radians
-template<class Y, class System>
+template<class Y, class Dimension, class System>
quantity<unit<plane_angle_dimension, homogeneous_system<System> >, Y>
-atan2(const quantity<unit<dimensionless_type, homogeneous_system<System> >, Y>& y,
- const quantity<unit<dimensionless_type, homogeneous_system<System> >, Y>& x)
+atan2(const quantity<unit<Dimension, homogeneous_system<System> >, Y>& y,
+ const quantity<unit<Dimension, homogeneous_system<System> >, Y>& x)
{
using std::atan2;
return quantity<unit<plane_angle_dimension, homogeneous_system<System> >, Y>(atan2(y.value(),x.value())*si::radians);
Modified: trunk/libs/units/test/Jamfile.v2
==============================================================================
--- trunk/libs/units/test/Jamfile.v2 (original)
+++ trunk/libs/units/test/Jamfile.v2 2009-07-10 17:26:57 EDT (Fri, 10 Jul 2009)
@@ -40,6 +40,7 @@
run test_lambda.cpp ;
run test_scaled_unit.cpp test_framework ;
run test_output.cpp test_framework ;
+run test_trig.cpp test_framework ;
compile-fail fail_implicit_conversion.cpp ;
compile-fail fail_quantity_construct.cpp ;
Added: trunk/libs/units/test/test_trig.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/units/test/test_trig.cpp 2009-07-10 17:26:57 EDT (Fri, 10 Jul 2009)
@@ -0,0 +1,73 @@
+// Boost.Units - A C++ library for zero-overhead dimensional analysis and
+// unit/quantity manipulation and conversion
+//
+// Copyright (C) 2009 Steven Watanabe
+//
+// 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)
+
+/**
+\file
+
+\brief test_trig.cpp
+
+\detailed
+Test trigonometric functions.
+
+Output:
+@verbatim
+@endverbatim
+**/
+
+#include <cmath>
+#include <boost/units/cmath.hpp>
+#include <boost/units/systems/si/plane_angle.hpp>
+#include <boost/units/systems/si/length.hpp>
+#include <boost/units/systems/si/dimensionless.hpp>
+#include <boost/units/systems/angle/degrees.hpp>
+
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp>
+
+using boost::units::si::radians;
+using boost::units::si::si_dimensionless;
+using boost::units::degree::degrees;
+BOOST_UNITS_STATIC_CONSTANT(degree_dimensionless, boost::units::degree::dimensionless);
+using boost::units::si::meters;
+
+BOOST_AUTO_TEST_CASE(test_sin) {
+ BOOST_CHECK_EQUAL(boost::units::sin(2.0 * radians), std::sin(2.0) * si_dimensionless);
+ BOOST_CHECK_CLOSE_FRACTION(static_cast<double>(boost::units::sin(15.0 * degrees)), 0.2588, 0.0004);
+}
+
+BOOST_AUTO_TEST_CASE(test_cos) {
+ BOOST_CHECK_EQUAL(boost::units::cos(2.0 * radians), std::cos(2.0) * si_dimensionless);
+ BOOST_CHECK_CLOSE_FRACTION(static_cast<double>(boost::units::cos(75.0 * degrees)), 0.2588, 0.0004);
+}
+
+BOOST_AUTO_TEST_CASE(test_tan) {
+ BOOST_CHECK_EQUAL(boost::units::tan(2.0 * radians), std::tan(2.0) * si_dimensionless);
+ BOOST_CHECK_CLOSE_FRACTION(static_cast<double>(boost::units::tan(45.0 * degrees)), 1.0, 0.0001);
+}
+
+BOOST_AUTO_TEST_CASE(test_asin) {
+ BOOST_CHECK_EQUAL(boost::units::asin(0.2 * si_dimensionless), std::asin(0.2) * radians);
+ BOOST_CHECK_CLOSE_FRACTION(boost::units::asin(0.5 * degree_dimensionless).value(), 30.0, 0.0001);
+}
+
+BOOST_AUTO_TEST_CASE(test_acos) {
+ BOOST_CHECK_EQUAL(boost::units::acos(0.2 * si_dimensionless), std::acos(0.2) * radians);
+ BOOST_CHECK_CLOSE_FRACTION(boost::units::acos(0.5 * degree_dimensionless).value(), 60.0, 0.0001);
+}
+
+BOOST_AUTO_TEST_CASE(test_atan) {
+ BOOST_CHECK_EQUAL(boost::units::atan(0.2 * si_dimensionless), std::atan(0.2) * radians);
+ BOOST_CHECK_CLOSE_FRACTION(boost::units::atan(1.0 * degree_dimensionless).value(), 45.0, 0.0001);
+}
+
+BOOST_AUTO_TEST_CASE(test_atan2) {
+ BOOST_CHECK_EQUAL(boost::units::atan2(0.2 * si_dimensionless, 0.3 * si_dimensionless), std::atan2(0.2, 0.3) * radians);
+ BOOST_CHECK_EQUAL(boost::units::atan2(0.2 * meters, 0.3 * meters), std::atan2(0.2, 0.3) * radians);
+ BOOST_CHECK_CLOSE_FRACTION(boost::units::atan2(0.8660*degree_dimensionless,0.5*degree_dimensionless).value(), 60., 0.0002);
+}
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