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

📄 fnem.hpp~

📁 浮点数基本运算 浮点数的基本运算主要有四则运算、符号处理、大小比较
💻 HPP~
字号:
// Float Number exp implementation -*- C++ -*-// Copyright (C) 2005 Ben T. Bear//// This file is part of the BTB's Template<Integer> Library.  This// library is free software; you can redistribute it and/or modify it// under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2, or (at your option)// any later version.// This library is distributed in the hope that it will be useful, but// WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU// General Public License for more details.// You should have received a copy of the GNU General Public License// along with this library; see the file COPYING.  If not, write to// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,// MA 02111-1307, USA.// As a special exception, you may use this file as part of a free// software library without restriction.  Specifically, if other files// instantiate templates or use macros or inline functions from this// file, or you compile this file and link it with other files to// produce an executable, this file does not by itself cause the// resulting executable to be covered by the GNU General Public// License.  This exception does not however invalidate any other// reasons why the executable file might be covered by the GNU General// Public License.#ifndef __bt2il_fn_fnem_hpp#define __bt2il_fn_fnem_hppnamespace btil{  namespace fn  {    template <typename f, int k = 10>    struct fn2em;        template <int n, int k>    struct __em_exp;        template <int n, int k>    struct ____em_exp_p              // n > 0    {      static const double __e = ____em_exp_p<n/2, k>::f_val;      static const double __b = (n % 2 == 0) ? 1.0 : k;      static const double f_val = __e * __e * __b;    };        template <int k>    struct ____em_exp_p<0, k>    {      static const double f_val = 1.0;    };    template <int t, int n, int k>    struct ____em_exp;        template <int n, int k>    struct ____em_exp<-1, n, k>    {      static const double f_val = 1.0 / ____em_exp_p<-n, k>::f_val;    };        template <int n, int k>    struct ____em_exp<0, n, k>    {      static const double f_val = ____em_exp_p<n, k>::f_val;    };        template <int n, int k>    struct __em_exp    {      static const int __s = (n < 0) ? -1 : 0;      struct value      {        static const double f_val = ____em_exp<__s, n, k>::f_val;      };    };    template <int t, typename f, int k>    struct __fn2em;            template <typename f, int k>    struct fn2em    {      static const double __f = f::f_val;      static const int sign = (__f < 0.0) ? -1 : (__f != 0.0);      static const double __x = (sign == -1) ? -__f : __f;      static const int __t = ((__x == 0.0) ? 0			      : ((__x < 1.0) ? 1				 : ((__x < k) ? 2 : 3)));      struct x      {	static const double f_val = __x;      };      static const int e = __fn2em<__t, x, k>::e;      typedef typename __fn2em<__t, x, k>::m m;    };        template <typename f, int k>    struct __fn2em<0, f, k>           // less than 1    {      static const int e = 0;      struct m      {	static const double f_val = 0.0;      };    };        template <typename f, int k>    struct __fn2em<2, f, k>          // [1.0, k)    {      static const int e = 0;      typedef f m;    };        template <typename f, int k>    struct __fn2em_s;		// small than 1.0    template <typename f, int k>    struct __fn2em<1, f, k>	// (0.0, 1.0)    {      static const int e = __fn2em_s<f, k>::e;      typedef typename __fn2em_s<f, k>::m m;    };        template <typename f, int k>    struct __fn2em_b;		// big & equal than k    template <typename f, int k>    struct __fn2em<3, f, k>	// [k, .....    {      static const int e = __fn2em_b<f, k>::e;      typedef typename __fn2em_b<f, k>::m m;    };        template <int n, typename f, int k>    struct __fn2em_s_n;          // get __em_exp<2n> < f        template <int n, typename f, int k>    struct __fn2em_s_e;        template <typename f, int k>    struct __fn2em_s                 // small    {      static const int __n = __fn2em_s_n<1, f, k>::value;            static const int e = -__fn2em_s_e<__n, f, k>::e-1;      //typedef typename __fn2em_s_e<__n, f, k>::m m;      struct m      {	static const double __m =  __fn2em_s_e<__n, f, k>::m::f_val * k;	static const double f_val = (__m < 1.0) ? 1.0 : __m;      };    };        template <bool b, int n, typename f, int k>    struct __fn2em_s_n_bool;        template <int n, typename f, int k>    struct __fn2em_s_n    {      static const double __en = __em_exp<-n, k>::value::f_val;      static const double __h = f::f_val / __en;      static const bool __b = __h >= __en;      static const int value = __fn2em_s_n_bool<__b, n, f, k>::value;    };        template <int n, typename f, int k>    struct __fn2em_s_n_bool<true, n, f, k>    {      static const int value = n;    };        template <int n, typename f, int k>    struct __fn2em_s_n_bool<false, n, f, k>    {      static const int value = __fn2em_s_n<2*n, f, k>::value;    };        template <int n, typename f, int k>    struct __fn2em_s_e    {      static const double __f = f::f_val;      static const double __en = __em_exp<-n, k>::value::f_val;      static const bool __s = __en > __f;      struct __h      {	static const double f_val = __s ? __f / __en : __f;      };            static const int e = __fn2em_s_e<n/2, __h, k>::e + (__s ? n : 0);      typedef typename __fn2em_s_e<n/2, __h, k>::m m;    };        template <typename f, int k>    struct __fn2em_s_e<0, f, k>    {      static const int e = 0;      typedef f m;    };        template <int n, typename f, int k>    struct __fn2em_b_n;    template <int n, typename f, int k>    struct __fn2em_b_e;        template <typename f, int k>    struct __fn2em_b    {      static const int __n = __fn2em_b_n<1, f, k>::value;            static const int e = __fn2em_b_e<__n, f, k>::e;      typedef typename __fn2em_b_e<__n, f, k>::m m;    };        template <bool b, int n, typename f, int k>    struct __fn2em_b_n_bool;        template <int n, typename f, int k>    struct __fn2em_b_n    {      static const double __en = __em_exp<n, k>::value::f_val;      static const double __h = f::f_val / __en;      static const bool __b = __h < __en;            static const int value = __fn2em_b_n_bool<__b, n, f, k>::value;    };        template <int n, typename f, int k>    struct __fn2em_b_n_bool<true, n, f, k>    {      static const int value = n;    };        template <int n, typename f, int k>    struct __fn2em_b_n_bool<false, n, f, k>    {      static const int value = __fn2em_b_n<2*n, f, k>::value;    };        template <int n, typename f, int k>    struct __fn2em_b_e    {      static const double __f = f::f_val;      static const double __en = __em_exp<n, k>::value::f_val;      static const bool __s = __f >= __en;            struct __h      {        static const double f_val = __s ? __f / __en : __f;      };      static const int e = __fn2em_b_e<n/2, __h, k>::e + (__s ? n : 0);      typedef typename __fn2em_b_e<n/2, __h, k>::m m;    };        template <typename f, int k>    struct __fn2em_b_e<0, f, k>    {      static const int e = 0;      typedef f m;    };  }}#endif

⌨️ 快捷键说明

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