|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62533 - in trunk: boost/units boost/units/detail libs/units/test
From: steven_at_[hidden]
Date: 2010-06-07 21:00:28
Author: steven_watanabe
Date: 2010-06-07 21:00:27 EDT (Mon, 07 Jun 2010)
New Revision: 62533
URL: http://svn.boost.org/trac/boost/changeset/62533
Log:
Add overloads of inverse trig functions that take heterogeneous units and return the angles in radians. Fixes #3865
Text files modified:
trunk/boost/units/cmath.hpp | 38 ++++++++++++++++++++++++++++++++++++++
trunk/boost/units/detail/dimensionless_unit.hpp | 18 +++++++++---------
trunk/libs/units/test/test_trig.cpp | 5 +++++
3 files changed, 52 insertions(+), 9 deletions(-)
Modified: trunk/boost/units/cmath.hpp
==============================================================================
--- trunk/boost/units/cmath.hpp (original)
+++ trunk/boost/units/cmath.hpp 2010-06-07 21:00:27 EDT (Mon, 07 Jun 2010)
@@ -24,6 +24,7 @@
#include <boost/units/pow.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/detail/cmath_impl.hpp>
+#include <boost/units/detail/dimensionless_unit.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
@@ -603,6 +604,15 @@
return quantity<unit<plane_angle_dimension, homogeneous_system<System> >,Y>(acos(val.value())*si::radians);
}
+/// acos of dimensionless quantity returning angle in radians
+template<class Y>
+quantity<angle::radian_base_unit::unit_type,Y>
+acos(const quantity<unit<dimensionless_type, heterogeneous_dimensionless_system>,Y>& val)
+{
+ using std::acos;
+ return quantity<angle::radian_base_unit::unit_type,Y>::from_value(acos(val.value()));
+}
+
/// asin of dimensionless quantity returning angle in same system
template<class Y,class System>
quantity<unit<plane_angle_dimension, homogeneous_system<System> >,Y>
@@ -612,6 +622,15 @@
return quantity<unit<plane_angle_dimension, homogeneous_system<System> >,Y>(asin(val.value())*si::radians);
}
+/// asin of dimensionless quantity returning angle in radians
+template<class Y>
+quantity<angle::radian_base_unit::unit_type,Y>
+asin(const quantity<unit<dimensionless_type, heterogeneous_dimensionless_system>,Y>& val)
+{
+ using std::asin;
+ return quantity<angle::radian_base_unit::unit_type,Y>::from_value(asin(val.value()));
+}
+
/// atan of dimensionless quantity returning angle in same system
template<class Y,class System>
quantity<unit<plane_angle_dimension, homogeneous_system<System> >,Y>
@@ -621,6 +640,15 @@
return quantity<unit<plane_angle_dimension, homogeneous_system<System> >,Y>(atan(val.value())*si::radians);
}
+/// atan of dimensionless quantity returning angle in radians
+template<class Y>
+quantity<angle::radian_base_unit::unit_type,Y>
+atan(const quantity<unit<dimensionless_type, heterogeneous_dimensionless_system>, Y>& val)
+{
+ using std::atan;
+ return quantity<angle::radian_base_unit::unit_type,Y>::from_value(atan(val.value()));
+}
+
/// atan2 of @c value_type returning angle in radians
template<class Y, class Dimension, class System>
quantity<unit<plane_angle_dimension, homogeneous_system<System> >, Y>
@@ -631,6 +659,16 @@
return quantity<unit<plane_angle_dimension, homogeneous_system<System> >, Y>(atan2(y.value(),x.value())*si::radians);
}
+/// atan2 of @c value_type returning angle in radians
+template<class Y, class Dimension, class System>
+quantity<angle::radian_base_unit::unit_type,Y>
+atan2(const quantity<unit<Dimension, heterogeneous_system<System> >, Y>& y,
+ const quantity<unit<Dimension, heterogeneous_system<System> >, Y>& x)
+{
+ using std::atan2;
+ return quantity<angle::radian_base_unit::unit_type,Y>::from_value(atan2(y.value(),x.value()));
+}
+
} // namespace units
} // namespace boost
Modified: trunk/boost/units/detail/dimensionless_unit.hpp
==============================================================================
--- trunk/boost/units/detail/dimensionless_unit.hpp (original)
+++ trunk/boost/units/detail/dimensionless_unit.hpp 2010-06-07 21:00:27 EDT (Mon, 07 Jun 2010)
@@ -26,6 +26,14 @@
template<class T1, class T2, class Scale>
struct heterogeneous_system_impl;
+typedef boost::units::heterogeneous_system<
+ boost::units::heterogeneous_system_impl<
+ boost::units::dimensionless_type,
+ boost::units::dimensionless_type,
+ boost::units::dimensionless_type
+ >
+> heterogeneous_dimensionless_system;
+
namespace detail {
template<class System>
@@ -39,15 +47,7 @@
};
template<>
-struct void_if_dimensionless<
- boost::units::heterogeneous_system<
- boost::units::heterogeneous_system_impl<
- boost::units::dimensionless_type,
- boost::units::dimensionless_type,
- boost::units::dimensionless_type
- >
- >
-> {
+struct void_if_dimensionless<heterogeneous_dimensionless_system> {
typedef void type;
};
Modified: trunk/libs/units/test/test_trig.cpp
==============================================================================
--- trunk/libs/units/test/test_trig.cpp (original)
+++ trunk/libs/units/test/test_trig.cpp 2010-06-07 21:00:27 EDT (Mon, 07 Jun 2010)
@@ -35,6 +35,7 @@
using boost::units::degree::degrees;
BOOST_UNITS_STATIC_CONSTANT(degree_dimensionless, boost::units::degree::dimensionless);
using boost::units::si::meters;
+BOOST_UNITS_STATIC_CONSTANT(heterogeneous_dimensionless, boost::units::reduce_unit<boost::units::si::dimensionless>::type);
BOOST_AUTO_TEST_CASE(test_sin) {
BOOST_CHECK_EQUAL(boost::units::sin(2.0 * radians), std::sin(2.0) * si_dimensionless);
@@ -54,20 +55,24 @@
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_CHECK_EQUAL(boost::units::asin(0.2 * heterogeneous_dimensionless).value(), std::asin(0.2));
}
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_CHECK_EQUAL(boost::units::acos(0.2 * heterogeneous_dimensionless).value(), std::acos(0.2));
}
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_CHECK_EQUAL(boost::units::atan(0.2 * heterogeneous_dimensionless).value(), std::atan(0.2));
}
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_CHECK_EQUAL(boost::units::atan2(0.2 * heterogeneous_dimensionless, 0.3 * heterogeneous_dimensionless).value(), std::atan2(0.2, 0.3));
}
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