NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
数学函数

基本数学运算函数 更多...

函数

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 uint64_t fibonacci (const uint32_t n) noexcept
 计算斐波那契数
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 uint64_t leonardo (const uint32_t n) noexcept
 计算莱昂纳多数
template<typename T>
NEFORCE_PURE_FUNCTION constexpr T angular2radian (const T angular) noexcept
 角度转弧度
template<typename T>
NEFORCE_PURE_FUNCTION constexpr T radian2angular (const T radian) noexcept
 弧度转角度
template<typename T>
NEFORCE_CONST_FUNCTION constexpr enable_if_t< is_signed_v< T >, T > absolute (const T x) noexcept
 取绝对值(有符号数版本)
template<typename T>
NEFORCE_CONST_FUNCTION constexpr const T & sum (const T &x) noexcept
 单参数求和
template<typename First, typename... Rests, enable_if_t<(sizeof...(Rests) > 0), int > = 0>
NEFORCE_CONST_FUNCTION constexpr decltype(auto) sum (First first, Rests... args)
 多参数求和
template<typename... Args, enable_if_t<(sizeof...(Args) > 0), int > = 0>
NEFORCE_CONST_FUNCTION constexpr decltype(auto) average (Args... args)
 计算平均值
template<typename T>
NEFORCE_CONSTEXPR14 int sign (const T &value) noexcept
 获取数值的符号
template<typename T>
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 T gcd (const T &m, const T &n) noexcept
 计算最大公约数
template<typename T>
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 T lcm (const T &m, const T &n) noexcept
 计算最小公倍数
template<typename T>
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 enable_if_t< is_floating_point_v< T >, T > mod (const T x, const T y)
 浮点数取模运算
template<typename T>
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 T power (const T &x, uint32_t n) noexcept
 幂运算
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t exponential (const uint32_t n) noexcept
 计算e的n次幂
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t logarithm_e (const decimal_t x) noexcept
 计算自然对数
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t logarithm (const decimal_t x, const uint32_t base)
 计算任意底数的对数
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t logarithm_2 (const decimal_t x)
 计算以2为底的对数
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t logarithm_10 (const decimal_t x)
 计算以10为底的对数
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t square_root (const decimal_t x, const decimal_t precise=constants::DEFAULT_TOLERANCE) noexcept
 计算平方根
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t cube_root (const decimal_t x, const decimal_t precise=constants::DEFAULT_TOLERANCE) noexcept
 计算立方根
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 uint64_t factorial (const uint32_t n) noexcept
 计算阶乘
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t floor (const decimal_t x) noexcept
 向下取整
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t floor (const decimal_t x, const uint32_t bit) noexcept
 向下取整到指定位数
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t ceil (const decimal_t x) noexcept
 向上取整
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t ceil (const decimal_t x, const uint32_t bit) noexcept
 向上取整到指定位数
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t round (const decimal_t x) noexcept
 四舍五入
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t floor_bit (const decimal_t x, const uint32_t bit) noexcept
 向下舍入到指定位数
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t ceil_bit (const decimal_t x, const uint32_t bit) noexcept
 向上舍入到指定位数
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t round_bit (const decimal_t x, const uint32_t bit) noexcept
 四舍五入到指定位数
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t truncate_bit (const decimal_t x, const uint32_t bit) noexcept
 截断到指定位数
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t round (const decimal_t x, const uint32_t bit) noexcept
 四舍五入到指定位数
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t truncate (const decimal_t x, const int bit) noexcept
 截断
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t truncate (const decimal_t x) noexcept
 截断到整数位
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 bool around_multiple (const decimal_t x, const decimal_t axis, const decimal_t toler=constants::DEFAULT_TOLERANCE)
 判断是否接近某个倍数值
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 bool around_pi (const decimal_t x, const decimal_t toler=constants::LOOSE_TOLERANCE)
 判断是否接近π的整数倍
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 bool around_zero (const decimal_t x, const decimal_t toler=constants::LOOSE_TOLERANCE) noexcept
 判断是否接近零
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t remainder (const decimal_t x, const decimal_t y) noexcept
 计算余数
NEFORCE_CONST_FUNCTION constexpr decimal_t float_part (const decimal_t x) noexcept
 获取小数部分
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t float_apart (decimal_t x, int64_t *int_ptr) noexcept
 分离整数和小数部分
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t sine (decimal_t x) noexcept
 计算正弦值
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t cosine (decimal_t x) noexcept
 计算余弦值
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t tangent (decimal_t x) noexcept
 计算正切值
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t cotangent (const decimal_t x)
 计算余切值
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t arctangent (decimal_t x) noexcept
 计算反正切值
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t arcsine (const decimal_t x) noexcept
 计算反正弦值
NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t arccosine (const decimal_t x) noexcept
 计算反余弦值

详细描述

基本数学运算函数

遵循的国际标准

本实现严格遵循以下数学计算相关标准规范:

浮点数算术标准:

数学函数规范:

三角函数实现

本实现采用泰勒级数展开与参数归约相结合的方法:

**参数归约**(根据 Cody & Waite 方法):

  1. 将输入 x 映射到 [-π/2, π/2] 区间
  2. 使用高精度 π/2 值(高位 + 低位)减少舍入误差
  3. 记录象限信息以确定最终符号

**泰勒级数展开**:

  • sin(x) = x - x³/3! + x⁵/5! - x⁷/7! + ...
  • cos(x) = 1 - x²/2! + x⁴/4! - x⁶/6! + ...
  • arctan(x) = x - x³/3 + x⁵/5 - x⁷/7 + ... (|x| ≤ 1)

迭代终止条件:当前项小于 MACHINE_EPSILON × 当前和

对数函数实现

**自然对数 ln(x)**:

  • 使用恒等式:ln(x) = 2 × arctanh((x-1)/(x+1))
  • arctanh(y) = y + y³/3 + y⁵/5 + ... (|y| < 1)

**任意底对数**:

  • log_base(x) = ln(x) / ln(base)

方根函数实现

**平方根 √x**(牛顿迭代法):

  • 初始猜测:guess = x × 0.5
  • 迭代公式:guess = 0.5 × (guess + x / guess)
  • 终止条件:|guess - prev| ≤ tolerance × |guess|

**立方根 ³√x**(牛顿迭代法):

  • 迭代公式:guess = (2×prev + x / prev²) / 3

特殊值处理

根据 IEEE 754-2019 §6,特殊值处理规则:

输入情况 返回值
输入为 NaN 返回 NaN
输入为 ±∞ 根据函数语义返回 ±∞ 或 NaN
负数的平方根 返回 NaN
除数为零 返回 NaN 或抛出异常

| |x| > 1 的反正弦/反余弦| 返回 NaN |

性能与精度说明

  • 三角函数使用参数归约减少大输入值的误差
  • 泰勒级数迭代次数由机器精度自适应确定
  • 预计算的斐波那契数列加速小索引值的查询
参见
https://standards.ieee.org/ieee/754/6210/
https://dlmf.nist.gov/
https://en.cppreference.com/w/cpp/numeric/math

函数说明

◆ absolute()

template<typename T>
NEFORCE_CONST_FUNCTION constexpr enable_if_t< is_signed_v< T >, T > absolute ( const T x)
constexprnoexcept

取绝对值(有符号数版本)

模板参数
T数值类型
参数
x原数值
返回
绝对值

在文件 math.hpp221 行定义.

被这些函数引用 arccosine(), arcsine(), arctangent(), around_multiple(), around_zero(), cube_root(), gcd(), logarithm_e(), round(), square_root() , 以及 truncate().

◆ angular2radian()

template<typename T>
NEFORCE_PURE_FUNCTION constexpr T angular2radian ( const T angular)
constexprnoexcept

角度转弧度

模板参数
T运算类型
参数
angular角度值
返回
对应的弧度值

在文件 math.hpp197 行定义.

引用了 is_arithmetic_v.

◆ arccosine()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t arccosine ( const decimal_t x)
noexcept

计算反余弦值

参数
x参数(|x| ≤ 1)
返回
arccos(x)(弧度值,范围[0, π])

在文件 math.hpp1032 行定义.

引用了 absolute(), arcsine(), is_nan() , 以及 numeric_traits< T, Dummy >::quiet_nan().

◆ arcsine()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t arcsine ( const decimal_t x)
noexcept

计算反正弦值

参数
x参数(|x| ≤ 1)
返回
arcsin(x)(弧度值,范围[-π/2, π/2])

在文件 math.hpp1011 行定义.

引用了 absolute(), arctangent(), is_nan(), numeric_traits< T, Dummy >::quiet_nan() , 以及 square_root().

被这些函数引用 arccosine().

◆ arctangent()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t arctangent ( decimal_t x)
noexcept

计算反正切值

参数
x参数
返回
arctan(x)(弧度值,范围(-π/2, π/2))

当|x|>1时,利用恒等式 arctan(x) = π/2 - arctan(1/x)。

在文件 math.hpp966 行定义.

引用了 absolute(), is_infinity(), is_nan() , 以及 square_root().

被这些函数引用 arcsine().

◆ around_multiple()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 bool around_multiple ( const decimal_t x,
const decimal_t axis,
const decimal_t toler = constants::DEFAULT_TOLERANCE )

判断是否接近某个倍数值

参数
x待判断值
axis基准值
toler容差
返回
如果x接近axis的整数倍则返回true
异常
math_exception当axis为0时抛出

在文件 math.hpp718 行定义.

引用了 absolute() , 以及 round().

被这些函数引用 around_pi().

◆ around_pi()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 bool around_pi ( const decimal_t x,
const decimal_t toler = constants::LOOSE_TOLERANCE )

判断是否接近π的整数倍

参数
x待判断值
toler容差
返回
如果x接近π的整数倍则返回true

在文件 math.hpp733 行定义.

引用了 around_multiple().

◆ around_zero()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 bool around_zero ( const decimal_t x,
const decimal_t toler = constants::LOOSE_TOLERANCE )
noexcept

判断是否接近零

参数
x待判断值
toler容差
返回
如果|x| < toler则返回true

在文件 math.hpp745 行定义.

引用了 absolute().

被这些函数引用 tangent().

◆ average()

template<typename... Args, enable_if_t<(sizeof...(Args) > 0), int > = 0>
NEFORCE_CONST_FUNCTION constexpr decltype(auto) average ( Args... args)
constexpr

计算平均值

模板参数
Args参数类型
参数
args要求平均值的参数
返回
平均值

在文件 math.hpp270 行定义.

引用了 sum().

◆ ceil() [1/2]

◆ ceil() [2/2]

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t ceil ( const decimal_t x,
const uint32_t bit )
noexcept

向上取整到指定位数

参数
x原数值
bit位数
返回
向上取整后的值

在文件 math.hpp601 行定义.

引用了 ceil() , 以及 power().

◆ ceil_bit()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t ceil_bit ( const decimal_t x,
const uint32_t bit )
noexcept

向上舍入到指定位数

参数
x原数值
bit位数
返回
向上舍入后的值

在文件 math.hpp650 行定义.

引用了 ceil() , 以及 power().

被这些函数引用 round_bit() , 以及 truncate_bit().

◆ cosine()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t cosine ( decimal_t x)
noexcept

计算余弦值

参数
x弧度值
返回
cos(x)

利用恒等式 cos(x) = sin(π/2 - x) 计算。

在文件 math.hpp886 行定义.

引用了 is_infinity(), is_nan() , 以及 numeric_traits< T, Dummy >::quiet_nan().

◆ cotangent()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t cotangent ( const decimal_t x)

计算余切值

参数
x弧度值
返回
cot(x)
异常
math_exception当x接近π的整数倍时抛出

在文件 math.hpp957 行定义.

引用了 tangent().

◆ cube_root()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t cube_root ( const decimal_t x,
const decimal_t precise = constants::DEFAULT_TOLERANCE )
noexcept

计算立方根

参数
x被开方数
precise精度要求
返回
³√x

使用牛顿迭代法计算。

在文件 math.hpp519 行定义.

引用了 absolute(), is_infinity(), is_nan() , 以及 prev().

◆ exponential()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t exponential ( const uint32_t n)
noexcept

计算e的n次幂

参数
n指数
返回
e^n

在文件 math.hpp394 行定义.

引用了 power().

◆ factorial()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 uint64_t factorial ( const uint32_t n)
noexcept

计算阶乘

参数
n非负整数
返回
n!

在文件 math.hpp548 行定义.

◆ fibonacci()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 uint64_t fibonacci ( const uint32_t n)
noexcept

计算斐波那契数

参数
n索引位置
返回
第n个斐波那契数

如果n小于预计算的数量,直接返回预计算结果; 否则递归计算。

在文件 math.hpp165 行定义.

被这些函数引用 leonardo().

◆ float_apart()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t float_apart ( decimal_t x,
int64_t * int_ptr )
noexcept

分离整数和小数部分

参数
x原数值
int_ptr指向整数部分的指针
返回
小数部分

将x的整数部分存入int_ptr,返回小数部分。

在文件 math.hpp782 行定义.

◆ float_part()

NEFORCE_CONST_FUNCTION constexpr decimal_t float_part ( const decimal_t x)
constexprnoexcept

获取小数部分

参数
x原数值
返回
x的小数部分

在文件 math.hpp770 行定义.

◆ floor() [1/2]

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t floor ( const decimal_t x)
noexcept

向下取整

参数
x原数值
返回
向下取整后的值

在文件 math.hpp561 行定义.

引用了 is_finite().

被这些函数引用 bit_ceil(), floor(), floor_bit(), round() , 以及 truncate().

◆ floor() [2/2]

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t floor ( const decimal_t x,
const uint32_t bit )
noexcept

向下取整到指定位数

参数
x原数值
bit位数
返回
向下取整后的值

在文件 math.hpp576 行定义.

引用了 floor() , 以及 power().

◆ floor_bit()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t floor_bit ( const decimal_t x,
const uint32_t bit )
noexcept

向下舍入到指定位数

参数
x原数值
bit位数,>0表示小数位,0表示整数位
返回
向下舍入后的值

在文件 math.hpp639 行定义.

引用了 floor() , 以及 power().

被这些函数引用 round_bit() , 以及 truncate_bit().

◆ gcd()

template<typename T>
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 T gcd ( const T & m,
const T & n )
noexcept

计算最大公约数

模板参数
T数值类型
参数
m第一个数
n第二个数
返回
最大公约数

在文件 math.hpp301 行定义.

引用了 absolute().

被这些函数引用 lcm().

◆ lcm()

template<typename T>
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 T lcm ( const T & m,
const T & n )
noexcept

计算最小公倍数

模板参数
T数值类型
参数
m第一个数
n第二个数
返回
最小公倍数

在文件 math.hpp320 行定义.

引用了 gcd().

◆ leonardo()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 uint64_t leonardo ( const uint32_t n)
noexcept

计算莱昂纳多数

参数
n索引位置
返回
第n个莱昂纳多数

莱昂纳多数:L(n) = 2 * F(n+1) - 1

在文件 math.hpp186 行定义.

引用了 fibonacci().

被这些函数引用 adjust_leonardo_heap(), pop_leonardo_heap() , 以及 sort_leonardo_heap().

◆ logarithm()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t logarithm ( const decimal_t x,
const uint32_t base )

计算任意底数的对数

参数
x真数
base底数
返回
以base为底x的对数

在文件 math.hpp456 行定义.

引用了 logarithm_e().

被这些函数引用 logarithm_10() , 以及 logarithm_2().

◆ logarithm_10()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t logarithm_10 ( const decimal_t x)

计算以10为底的对数

参数
x真数
返回
log₁₀(x)

在文件 math.hpp476 行定义.

引用了 logarithm().

◆ logarithm_2()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t logarithm_2 ( const decimal_t x)

计算以2为底的对数

参数
x真数
返回
log₂(x)

在文件 math.hpp469 行定义.

引用了 logarithm().

◆ logarithm_e()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t logarithm_e ( const decimal_t x)
noexcept

计算自然对数

参数
x真数
返回
ln(x)

使用反正切泰勒展开计算。

在文件 math.hpp405 行定义.

引用了 absolute(), numeric_traits< T, Dummy >::infinity(), is_infinity(), is_nan() , 以及 numeric_traits< T, Dummy >::quiet_nan().

被这些函数引用 bloom_filter< T, Hash >::approximate_count(), bloom_filter< T, Hash >::capacity() , 以及 logarithm().

◆ mod()

template<typename T>
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 enable_if_t< is_floating_point_v< T >, T > mod ( const T x,
const T y )

浮点数取模运算

模板参数
T浮点类型
参数
x被除数
y除数
返回
x除以y的余数
异常
math_exception除数为0时

在文件 math.hpp333 行定义.

引用了 is_infinity(), is_nan() , 以及 numeric_traits< T, Dummy >::quiet_nan().

被这些函数引用 ipackage< integer8, int8_t >::operator%=(), operator&() , 以及 operator|().

◆ power()

template<typename T>
NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 T power ( const T & x,
uint32_t n )
noexcept

幂运算

模板参数
T底数类型
参数
x底数
n指数
返回
x的n次幂

使用快速幂算法实现。

在文件 math.hpp372 行定义.

引用了 is_arithmetic_v.

被这些函数引用 ceil(), ceil_bit(), exponential(), bloom_filter< T, Hash >::false_positive_rate(), floor(), floor_bit(), round(), round_bit() , 以及 truncate().

◆ radian2angular()

template<typename T>
NEFORCE_PURE_FUNCTION constexpr T radian2angular ( const T radian)
constexprnoexcept

弧度转角度

模板参数
T运算类型
参数
radian弧度值
返回
对应的角度值

在文件 math.hpp209 行定义.

引用了 is_arithmetic_v.

◆ remainder()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t remainder ( const decimal_t x,
const decimal_t y )
noexcept

计算余数

参数
x被除数
y除数
返回
x除以y的余数

使用对称舍入规则

在文件 math.hpp758 行定义.

引用了 is_infinity(), is_nan(), numeric_traits< T, Dummy >::quiet_nan() , 以及 round().

◆ round() [1/2]

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t round ( const decimal_t x)
noexcept

四舍五入

参数
x原数值
返回
四舍五入后的值

在文件 math.hpp611 行定义.

引用了 absolute(), floor() , 以及 is_finite().

被这些函数引用 around_multiple(), color::blend(), color::from_premultiplied(), color::operator*(), color::operator*=(), remainder(), round(), color::set_opacity() , 以及 color::to_premultiplied().

◆ round() [2/2]

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t round ( const decimal_t x,
const uint32_t bit )
noexcept

四舍五入到指定位数

参数
x原数值
bit位数
返回
四舍五入后的值

在文件 math.hpp682 行定义.

引用了 power() , 以及 round().

◆ round_bit()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t round_bit ( const decimal_t x,
const uint32_t bit )
noexcept

四舍五入到指定位数

参数
x原数值
bit位数
返回
四舍五入后的值

在文件 math.hpp661 行定义.

引用了 ceil_bit(), floor_bit() , 以及 power().

◆ sign()

template<typename T>
NEFORCE_CONSTEXPR14 int sign ( const T & value)
noexcept

获取数值的符号

模板参数
T数值类型
参数
value原数值
返回
符号值:正数返回1,负数返回-1,零返回0

在文件 math.hpp281 行定义.

引用了 is_arithmetic_v.

被这些函数引用 datetime::parse_ISO_UTC() , 以及 datetime::to_offset_string().

◆ sine()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t sine ( decimal_t x)
noexcept

计算正弦值

参数
x弧度值
返回
sin(x)

使用泰勒展开计算,先进行周期性处理。

在文件 math.hpp856 行定义.

引用了 is_infinity(), is_nan() , 以及 numeric_traits< T, Dummy >::quiet_nan().

◆ square_root()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t square_root ( const decimal_t x,
const decimal_t precise = constants::DEFAULT_TOLERANCE )
noexcept

计算平方根

参数
x被开方数
precise精度要求
返回
√x

使用牛顿迭代法计算。

在文件 math.hpp487 行定义.

引用了 absolute(), is_infinity(), is_nan(), prev() , 以及 numeric_traits< T, Dummy >::quiet_nan().

被这些函数引用 arcsine() , 以及 arctangent().

◆ sum() [1/2]

template<typename T>
NEFORCE_CONST_FUNCTION constexpr const T & sum ( const T & x)
constexprnoexcept

单参数求和

模板参数
T数值类型
参数
x唯一参数
返回
参数本身

递归sum的终止位置

在文件 math.hpp246 行定义.

被这些函数引用 average() , 以及 sum().

◆ sum() [2/2]

template<typename First, typename... Rests, enable_if_t<(sizeof...(Rests) > 0), int > = 0>
NEFORCE_CONST_FUNCTION constexpr decltype(auto) sum ( First first,
Rests... args )
constexpr

多参数求和

模板参数
First第一个参数类型
Rests剩余参数类型
参数
first第一个参数
args剩余参数
返回
所有参数的和

在文件 math.hpp259 行定义.

引用了 sum().

◆ tangent()

NEFORCE_PURE_FUNCTION NEFORCE_CONSTEXPR14 decimal_t tangent ( decimal_t x)
noexcept

计算正切值

参数
x弧度值
返回
tan(x)
异常
math_exception当x接近π/2的奇数倍时抛出

在文件 math.hpp914 行定义.

引用了 around_zero(), numeric_traits< T, Dummy >::infinity(), is_infinity(), is_nan() , 以及 numeric_traits< T, Dummy >::quiet_nan().

被这些函数引用 cotangent().

◆ truncate() [1/2]

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t truncate ( const decimal_t x)
noexcept

截断到整数位

参数
x原数值
返回
截断后的整数值

在文件 math.hpp703 行定义.

引用了 is_finite().

◆ truncate() [2/2]

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t truncate ( const decimal_t x,
const int bit )
noexcept

截断

参数
x原数值
bit位数
返回
截断后的值

在文件 math.hpp693 行定义.

引用了 absolute(), ceil(), floor() , 以及 power().

◆ truncate_bit()

NEFORCE_CONST_FUNCTION NEFORCE_CONSTEXPR14 decimal_t truncate_bit ( const decimal_t x,
const uint32_t bit )
noexcept

截断到指定位数

参数
x原数值
bit位数
返回
截断后的值

在文件 math.hpp671 行定义.

引用了 ceil_bit() , 以及 floor_bit().