YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ystdex::fixed_point< _tBase, _vInt, _vFrac > 模板类 参考

通用定点数。 更多...

#include <rational.hpp>

类 ystdex::fixed_point< _tBase, _vInt, _vFrac > 继承关系图:
ystdex::fixed_point< _tBase, _vInt, _vFrac > 的协作图:

Public 类型

using base_type = _tBase
 

Public 成员函数

 fixed_point ()
 无参数构造。 更多...
 
bool operator< (const fixed_point &f) const
 
bool operator== (const fixed_point &f) const
 
bool operator! () const
 
fixed_point operator- () const
 
fixed_pointoperator++ ()
 
fixed_pointoperator-- ()
 
fixed_pointoperator+= (const fixed_point &f)
 
fixed_pointoperator-= (const fixed_point &f)
 
fixed_pointoperator*= (const fixed_point &f)
 
fixed_pointoperator/= (const fixed_point &f)
 
fixed_pointoperator>>= (size_t s)
 
fixed_pointoperator<<= (size_t s)
 
template<typename _type , typename = enable_if_t<is_arithmetic<_type>::value, _type>>
 operator _type () const
 
base_type get () const
 
 fixed_point (base_type v, raw_tag)
 
template<typename _tInt >
 fixed_point (_tInt val, enable_if_t< is_integral< _tInt >::value, _tInt * >={})
 
template<typename _tFloat >
 fixed_point (_tFloat val, enable_if_t< is_floating_point< _tFloat >::value, _tFloat * >={})
 
template<typename _tFirst , typename _tSecond >
 fixed_point (_tFirst x, _tSecond y, enable_if_t< is_integral< _tFirst >::value &&!is_same< _tSecond, raw_tag >::value, _tFirst * >={})
 
template<typename _tFirst , typename _tSecond >
 fixed_point (_tFirst x, _tSecond y, enable_if_t< is_floating_point< _tFirst >::value &&!is_same< _tSecond, raw_tag >::value, _tFirst * >={})
 
 fixed_point (const fixed_point &)=default
 
template<size_t _vOtherInt, size_t _vOtherFrac>
 fixed_point (const fixed_point< base_type, _vOtherInt, _vOtherFrac > &f, enable_if_t<(_vOtherInt< int_bit_n), base_type * >={})
 
template<size_t _vOtherInt, size_t _vOtherFrac>
 fixed_point (const fixed_point< base_type, _vOtherInt, _vOtherFrac > &f, enable_if_t<(int_bit_n< _vOtherInt), base_type * >={})
 
template<typename _tOtherBase , size_t _vOtherInt, size_t _vOtherFrac>
 fixed_point (const fixed_point< _tOtherBase, _vOtherInt, _vOtherFrac > &f, enable_if_t<(frac_bit_n==_vOtherFrac), base_type * >={})
 
template<typename _tOtherBase , size_t _vOtherInt, size_t _vOtherFrac>
 fixed_point (const fixed_point< _tOtherBase, _vOtherInt, _vOtherFrac > &f, enable_if_t<(frac_bit_n< _vOtherFrac), base_type * >={})
 
template<typename _tOtherBase , size_t _vOtherInt, size_t _vOtherFrac>
 fixed_point (const fixed_point< _tOtherBase, _vOtherInt, _vOtherFrac > &f, enable_if_t<(_vOtherFrac< frac_bit_n), base_type * >={})
 

静态 Public 成员函数

static base_type base_element ()
 base_type 表达的单位元。 更多...
 
static fixed_point identity ()
 取单位元。 更多...
 

静态 Public 属性

static const size_t int_bit_n = _vInt
 整数部分二进制位数。 更多...
 
static const size_t frac_bit_n = _vFrac
 小数部分二进制位数。 更多...
 
static const size_t digit_bit_n = int_bit_n + frac_bit_n
 非符号位的二进制位数。 更多...
 

Private 成员函数

template<typename _type >
enable_if_t< is_integral
< _type >::value, _type > 
cast () const
 
template<typename _type >
enable_if_t< is_floating_point
< _type >::value, _type > 
cast () const
 

静态 Private 成员函数

template<size_t _vShiftBits>
static base_type mul (base_type x, base_type y, true_type)
 
template<size_t _vShiftBits>
static base_type mul (base_type x, base_type y, false_type)
 
template<size_t _vShiftBits>
static base_type mul_signed (typename fixed_multiplicative< base_type >::type tmp)
 

Private 属性

base_type value
 

友元

template<typename _OtherBase , size_t _vOtherInt, size_t _vOtherFrac>
class fixed_point
 
class std::numeric_limits< fixed_point< _tBase, _vInt, _vFrac > >
 
fixed_point fabs (fixed_point x)
 
fixed_point ceil (fixed_point x)
 
fixed_point floor (fixed_point x)
 
fixed_point round (fixed_point x)
 

详细描述

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
class ystdex::fixed_point< _tBase, _vInt, _vFrac >

通用定点数。

基于整数算术实现的确定有限精度二进制定点小数类型。可用于替换内建的浮点数类型。 是否有符号同基本整数类型参数。若有符号,则最高有效位为符号位。 逻辑布局: [符号位]|整数部分|小数部分 。各个部分的内部为补码表示。

模板参数
_tBase基本整数类型。
_vInt整数部分(若有符号则不包括符号位,下同)二进制位数。
_vFrac分数部分二进制位数。
注解
默认保留 6 位二进制小数。
部分实现参考: http://www.codeproject.com/KB/cpp/fp_math.aspx
警告
基本整数类型需要具有补码表示。
非虚析构。
算术运算可能溢出。
自从
build 260
待办事项:

实现模除和位操作。

根据范围禁止算术类型隐式转换。

在文件 rational.hpp139 行定义.

成员类型定义说明

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
using ystdex::fixed_point< _tBase, _vInt, _vFrac >::base_type = _tBase

在文件 rational.hpp152 行定义.

构造及析构函数说明

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( )
inline

无参数构造。

警告
基本整数类型成员未被初始化,具有未决定值 ,使用可能造成未定义行为。

在文件 rational.hpp170 行定义.

参考自 ystdex::fixed_point< _tBase, _vInt, _vFrac >::identity().

这是这个函数的调用关系图:

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( base_type  v,
raw_tag   
)
inline
自从
build 439

在文件 rational.hpp176 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<typename _tInt >
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( _tInt  val,
enable_if_t< is_integral< _tInt >::value, _tInt * >  = {} 
)
inline

在文件 rational.hpp181 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<typename _tFloat >
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( _tFloat  val,
enable_if_t< is_floating_point< _tFloat >::value, _tFloat * >  = {} 
)
inline

在文件 rational.hpp187 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<typename _tFirst , typename _tSecond >
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( _tFirst  x,
_tSecond  y,
enable_if_t< is_integral< _tFirst >::value &&!is_same< _tSecond, raw_tag >::value, _tFirst * >  = {} 
)
inline

在文件 rational.hpp195 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<typename _tFirst , typename _tSecond >
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( _tFirst  x,
_tSecond  y,
enable_if_t< is_floating_point< _tFirst >::value &&!is_same< _tSecond, raw_tag >::value, _tFirst * >  = {} 
)
inline

在文件 rational.hpp201 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( const fixed_point< _tBase, _vInt, _vFrac > &  )
inlinedefault
自从
build 260
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<size_t _vOtherInt, size_t _vOtherFrac>
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( const fixed_point< base_type, _vOtherInt, _vOtherFrac > &  f)
inline

在文件 rational.hpp210 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<size_t _vOtherInt, size_t _vOtherFrac>
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( const fixed_point< base_type, _vOtherInt, _vOtherFrac > &  f)
inline

在文件 rational.hpp216 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<typename _tOtherBase , size_t _vOtherInt, size_t _vOtherFrac>
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( const fixed_point< _tOtherBase, _vOtherInt, _vOtherFrac > &  f,
enable_if_t<(frac_bit_n==_vOtherFrac), base_type * >  = {} 
)
inline

在文件 rational.hpp222 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<typename _tOtherBase , size_t _vOtherInt, size_t _vOtherFrac>
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( const fixed_point< _tOtherBase, _vOtherInt, _vOtherFrac > &  f)
inline

在文件 rational.hpp228 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<typename _tOtherBase , size_t _vOtherInt, size_t _vOtherFrac>
ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point ( const fixed_point< _tOtherBase, _vOtherInt, _vOtherFrac > &  f)
inline

在文件 rational.hpp234 行定义.

成员函数说明

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
static base_type ystdex::fixed_point< _tBase, _vInt, _vFrac >::base_element ( )
inlinestatic
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<typename _type >
enable_if_t<is_integral<_type>::value, _type> ystdex::fixed_point< _tBase, _vInt, _vFrac >::cast ( ) const
inlineprivate
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<typename _type >
enable_if_t<is_floating_point<_type>::value, _type> ystdex::fixed_point< _tBase, _vInt, _vFrac >::cast ( ) const
inlineprivate
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
base_type ystdex::fixed_point< _tBase, _vInt, _vFrac >::get ( ) const
inline
自从
build 439

在文件 rational.hpp337 行定义.

参考 ystdex::fixed_point< _tBase, _vInt, _vFrac >::value.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
static fixed_point ystdex::fixed_point< _tBase, _vInt, _vFrac >::identity ( )
inlinestatic

取单位元。

取值等于 1 的元素。

在文件 rational.hpp401 行定义.

参考 ystdex::fixed_point< _tBase, _vInt, _vFrac >::base_element() , 以及 ystdex::fixed_point< _tBase, _vInt, _vFrac >::fixed_point().

函数调用图:

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<size_t _vShiftBits>
static base_type ystdex::fixed_point< _tBase, _vInt, _vFrac >::mul ( base_type  x,
base_type  y,
true_type   
)
inlinestaticprivate

在文件 rational.hpp360 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<size_t _vShiftBits>
static base_type ystdex::fixed_point< _tBase, _vInt, _vFrac >::mul ( base_type  x,
base_type  y,
false_type   
)
inlinestaticprivate

在文件 rational.hpp367 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<size_t _vShiftBits>
static base_type ystdex::fixed_point< _tBase, _vInt, _vFrac >::mul_signed ( typename fixed_multiplicative< base_type >::type  tmp)
inlinestaticprivate

在文件 rational.hpp378 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<typename _type , typename = enable_if_t<is_arithmetic<_type>::value, _type>>
ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator _type ( ) const
inline
自从
build 439

在文件 rational.hpp330 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
bool ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator! ( ) const
inline
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point& ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator*= ( const fixed_point< _tBase, _vInt, _vFrac > &  f)
inline
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point& ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator++ ( )
inline
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point& ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator+= ( const fixed_point< _tBase, _vInt, _vFrac > &  f)
inline
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator- ( ) const
inline
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point& ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator-- ( )
inline
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point& ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator-= ( const fixed_point< _tBase, _vInt, _vFrac > &  f)
inline
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point& ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator/= ( const fixed_point< _tBase, _vInt, _vFrac > &  f)
inline
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
bool ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator< ( const fixed_point< _tBase, _vInt, _vFrac > &  f) const
inline
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point& ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator<<= ( size_t  s)
inline
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
bool ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator== ( const fixed_point< _tBase, _vInt, _vFrac > &  f) const
inline
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point& ystdex::fixed_point< _tBase, _vInt, _vFrac >::operator>>= ( size_t  s)
inline

友元及相关函数文档

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point ceil ( fixed_point< _tBase, _vInt, _vFrac >  x)
friend

在文件 rational.hpp413 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point fabs ( fixed_point< _tBase, _vInt, _vFrac >  x)
friend

在文件 rational.hpp407 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
template<typename _OtherBase , size_t _vOtherInt, size_t _vOtherFrac>
friend class fixed_point
friend

在文件 rational.hpp141 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point floor ( fixed_point< _tBase, _vInt, _vFrac >  x)
friend

在文件 rational.hpp420 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
fixed_point round ( fixed_point< _tBase, _vInt, _vFrac >  x)
friend

在文件 rational.hpp426 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
friend class std::numeric_limits< fixed_point< _tBase, _vInt, _vFrac > >
friend

在文件 rational.hpp149 行定义.

类成员变量说明

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
const size_t ystdex::fixed_point< _tBase, _vInt, _vFrac >::digit_bit_n = int_bit_n + frac_bit_n
static

非符号位的二进制位数。

在文件 rational.hpp159 行定义.

template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
const size_t ystdex::fixed_point< _tBase, _vInt, _vFrac >::frac_bit_n = _vFrac
static
template<typename _tBase = std::int32_t, size_t _vInt = std::numeric_limits<_tBase>::digits - 6U, size_t _vFrac = std::numeric_limits<_tBase>::digits - _vInt>
const size_t ystdex::fixed_point< _tBase, _vInt, _vFrac >::int_bit_n = _vInt
static

整数部分二进制位数。

在文件 rational.hpp155 行定义.


该类的文档由以下文件生成: