📄 fnmath.hpp~
字号:
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -