C++ Arbitrary Precision Fixed Point
Types的缩写就是ap_fixed,任意精度定点数类型。
定义如下
ap_[u]fixed < int W, int I,
ap_q_mode Q, ap_o_mode O, ap_sat_bits N > ;
1、W:宽度,数据占用的位宽;
2、I:整数部分的位数,那么(W-I)就是小数部分fraction占用的宽度了;
3、Q:量化模式,量化模式有下面几种:
(1)Rounding to plus infinity-->AP_RND,AP_RND
指示该值应舍入到最接近ap_ [u]定点类型的可表示值。
ap_fixed<3, 2,
AP_RND, AP_SAT> UAPFixed4 = 1.25; // Yields: 1.5
ap_fixed<3, 2,
AP_RND, AP_SAT> UAPFixed4 = -1.25; // Yields: -1.0
(2)Rounding to zero AP_RND_ZERO 向零取整。
ap_fixed<3, 2,
AP_RND_ZERO, AP_SAT> UAPFixed4 = 1.25; // Yields: 1.0
ap_fixed<3, 2,
AP_RND_ZERO, AP_SAT> UAPFixed4 = -1.25; // Yields:
-1.0
(3)Rounding to minus infinity AP_RND_MIN_INF
向负无穷取整
(4)Rounding to infinity AP_RND_INF 向正无穷取整
4、O:溢出模式
(1)Saturation AP_SAT 取到剩余位数能表示的最大的值
p_ufixed<4, 4,
AP_RND, AP_SAT> UAPFixed4 = 19.0; // Yields: 15.0 4位无符号最大能取到15
ap_fixed<4, 4,
AP_RND, AP_SAT> UAPFixed4 = 19.0; // Yields: 7.0 4位有符号数最大能取到7
ap_ufixed<4, 4,
AP_RND, AP_SAT> UAPFixed4 = -19.0; // Yields: 0.0
4位无符号最大能取到0
ap_fixed<4, 4,
AP_RND, AP_SAT> UAPFixed4 = -19.0; // Yields: -8.0 4位有符号极限能取到-8
(2)Saturation to zero AP_SAT_ZERO
ap_ufixed<4, 4,
AP_RND, AP_SAT_ZERO> UAPFixed4 = 19.0; // Yields: 0.0
ap_fixed<4, 4,
AP_RND, AP_SAT_ZERO> UAPFixed4 = 19.0; // Yields: 0.0
ap_ufixed<4, 4,
AP_RND, AP_SAT_ZERO> UAPFixed4 = -19.0; // Yields: 0.0
ap_fixed<4, 4,
AP_RND, AP_SAT_ZERO> UAPFixed4 = -19.0; // Yields:
0.0
(3)Wrap-around AP_WRAP
(4)Sign magnitude wrap-around AP_WRAP_SM
编译这个类型,要加上头文件:#include
加载中,请稍候......