fnconst.hpp~

来自「浮点数基本运算 浮点数的基本运算主要有四则运算、符号处理、大小比较」· HPP~ 代码 · 共 119 行

HPP~
119
字号
// Pi implementation -*- C++ -*-//// Copyright (C) 2005 Ben T. Bear//// This file is published under GNU GPL 2.0. See more in "copy.hpp".// #include "copy.hpp"#ifndef __bt2il_fn_const_hpp#define __bt2il_fn_const_hpp#include "fn.hpp"#include "fnmath.hpp"#include "fnexp.hpp"namespace btil{  namespace fn  {    struct pi;    struct e;    struct one;    struct two;    struct three;    struct sqrt_two;    struct sqrt_three;    struct ln_two;        struct one    {      static const double f_val = 1.0;    };    struct two    {      static const double f_val = 2.0;    };    struct three    {      static const double f_val = 3.0;    };    template <typename x>    struct sqrt;    struct sqrt_two    {      static const double f_val = sqrt<two>::value::f_val;    };    struct sqrt_three    {      static const double f_val = sqrt<three>::value::f_val;    };    struct __ln2;    typedef __ln2 ln_two;    template <int n>    struct __pi_item;        template <>    struct __pi_item<0>    {      static const double item = 0.0;      static const double pi_n = 2.0;    };    template <int n>    struct __pi_item    {      static const double a = 2.0 + __pi_item<n-1>::item;      static const double x0 = 2.0;      static const double x1 = (a / x0 + x0) / 2.0;      static const double x2 = (a / x1 + x1) / 2.0;      static const double x3 = (a / x2 + x2) / 2.0;      static const double x4 = (a / x3 + x3) / 2.0;      static const double x5 = (a / x4 + x4) / 2.0;      static const double x6 = (a / x5 + x5) / 2.0;      static const double x7 = (a / x6 + x6) / 2.0;      static const double x8 = (a / x7 + x7) / 2.0;      static const double x = x8;      static const double item = x;      static const double pi_n = __pi_item<n-1>::pi_n * 2.0 / x;    };    struct pi    {      static const double f_val = __pi_item<35>::pi_n;    };    struct e    {      static const double f_val = __e::f_val;    };  }}#endif

⌨️ 快捷键说明

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