|
Boost-Commit : |
From: johnmaddock_at_[hidden]
Date: 2007-06-07 13:36:32
Author: johnmaddock
Date: 2007-06-07 13:36:31 EDT (Thu, 07 Jun 2007)
New Revision: 4485
URL: http://svn.boost.org/trac/boost/changeset/4485
Log:
Added acos, and changed asin to use Halley iteration rather than Newton Raphson.
Text files modified:
sandbox/math_toolkit/boost/math/tools/ntl.hpp | 36 ++++++++++++++++++++++++++++++++----
1 files changed, 32 insertions(+), 4 deletions(-)
Modified: sandbox/math_toolkit/boost/math/tools/ntl.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/ntl.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/ntl.hpp 2007-06-07 13:36:31 EDT (Thu, 07 Jun 2007)
@@ -278,11 +278,13 @@
{
asin_root(NTL::RR const& target) : t(target){}
- std::tr1::tuple<NTL::RR, NTL::RR> operator()(NTL::RR const& p)
+ std::tr1::tuple<NTL::RR, NTL::RR, NTL::RR> operator()(NTL::RR const& p)
{
- NTL::RR f0 = sin(p) - t;
+ NTL::RR f0 = sin(p);
NTL::RR f1 = cos(p);
- return std::tr1::make_tuple(f0, f1);
+ NTL::RR f2 = -f0;
+ f0 -= t;
+ return std::tr1::make_tuple(f0, f1, f2);
}
private:
NTL::RR t;
@@ -290,7 +292,7 @@
inline NTL::RR asin(NTL::RR z)
{
- return boost::math::tools::newton_raphson_iterate(
+ return boost::math::tools::halley_iterate(
asin_root(z),
NTL::RR(std::asin(boost::math::tools::real_cast<double>(z))),
NTL::RR(-boost::math::constants::pi<NTL::RR>()/2),
@@ -298,6 +300,32 @@
boost::math::tools::digits<NTL::RR>());
}
+ struct acos_root
+ {
+ acos_root(NTL::RR const& target) : t(target){}
+
+ std::tr1::tuple<NTL::RR, NTL::RR, NTL::RR> operator()(NTL::RR const& p)
+ {
+ NTL::RR f0 = cos(p);
+ NTL::RR f1 = -sin(p);
+ NTL::RR f2 = -f0;
+ f0 -= t;
+ return std::tr1::make_tuple(f0, f1, f2);
+ }
+ private:
+ NTL::RR t;
+ };
+
+ inline NTL::RR acos(NTL::RR z)
+ {
+ return boost::math::tools::halley_iterate(
+ acos_root(z),
+ NTL::RR(std::acos(boost::math::tools::real_cast<double>(z))),
+ NTL::RR(-boost::math::constants::pi<NTL::RR>()/2),
+ NTL::RR(boost::math::constants::pi<NTL::RR>()/2),
+ boost::math::tools::digits<NTL::RR>());
+ }
+
struct atan_root
{
atan_root(NTL::RR const& target) : t(target){}
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