⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqrt.hpp

📁 矩阵运算源码最新版本
💻 HPP
字号:
// Software License for MTL// // Copyright (c) 2007 The Trustees of Indiana University. All rights reserved.// Authors: Peter Gottschling and Andrew Lumsdaine// // This file is part of the Matrix Template Library// // See also license.mtl.txt in the distribution.#ifndef META_MATH_SQRT_INCLUDE#define META_MATH_SQRT_INCLUDE#include <boost/numeric/meta_math/abs.hpp>namespace meta_math {template <long int root, long int x>struct sqrt_check{    static bool const value = root * root <= x && (root+1) * (root+1) > x;};namespace impl {    template <long int guess, long int x, bool Converged>    struct sqrt_impl    {	typedef long int type;	typedef sqrt_impl   self;	static long int const quotient = x / guess,	                      new_value = (quotient + guess) / 2;	static bool const converging = abs<guess - quotient>::value < 2;	static long int const value = sqrt_impl<new_value, x, converging>::value;    };    // If the condition becomes true the guessed root will be the returned value    template <long int guess, long int x>    struct sqrt_impl<guess, x, true>     {	static long int const value = guess;    };}template <long int x>struct sqrt {  typedef long int type;  static long int const value = impl::sqrt_impl<1, x, false>::value;};  } // namespace meta_math#endif // META_MATH_SQRT_INCLUDE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -