fnmath.hpp~
来自「浮点数基本运算 浮点数的基本运算主要有四则运算、符号处理、大小比较」· HPP~ 代码 · 共 118 行
HPP~
118 行
// Float number math 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_math_hpp
#define __bt2il_fn_math_hpp
#include "fn.hpp"
#include "fnexp.hpp"
namespace btil
{
namespace fn
{
template <typename a>
struct sqrt;
template <int n>
struct factorial;
template <typename x, typename y>
struct pow;
template <typename x, int n>
struct pow_n;
template <typename a>
struct sqrt
{
struct value
{
static const double f_val = __sqrt<a>::f_val;
};
};
template <int n>
struct factorial
{
static const double f_val = __factorial<n>::f_val;
};
template <typename x, typename y>
struct pow
{
struct __x
{
static const double f_val = y::f_val * ln<x>::value::f_val;
};
struct value
{
static const double f_val = exp<__x>::value::f_val;
};
};
template <typename x, int n>
struct __pow_n_p
{
static const double e = __pow_n_p<x, n/2>::f_val;
static const double b = (n % 2 == 0) ? 1.0 : x::f_val;
static const double f_val = e * e * b;
};
template <typename x>
struct __pow_n_p<x, 0>
{
static const double f_val = 1.0;
};
template <bool neg, typename x, int n>
struct __pow_n_bool;
template <typename x, int n>
struct __pow_n_bool<true, x, n>
{
static const double f_val = 1.0 / __pow_n_p<x, -n>::f_val;
};
template <typename x, int n>
struct __pow_n_bool<false, x, n>
{
static const double f_val = __pow_n_p<x, n>::f_val;
};
template <typename x, int n>
struct __pow_n
{
static const double f_val = __pow_n_bool<(n < 0), x, n>::f_val;
};
template <typename x, int n>
struct pow_n
{
struct value
{
static const double f_val = __pow_n<x, n>::f_val;
};
};
}
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?