Initializing Arbitrary Precision integers
(Ask a Question)The ap_[u]int
types can be constructed and assigned to from other
arbitrary precision integers, C++ integral types, ap_[u]fixpt
types, as
well as concatenations and bit selections. They can also be initialized from a hexadecimal
string describing the exact bits.
Some examples of initializing arbitrary precision integer types are show below.
#include "hls/ap_fixpt.hpp" #include "hls/ap_int.hpp" #include <iostream> #include <stdio.h> using namespace hls;
//... // Initialized to -7 ap_int<4> int1 = -7; std::cout << "int1 = " << int1 << std::endl; // Initialized to 15 // The bits below the decimal are truncated. ap_uint<4> int2 = ap_ufixpt<5, 4, AP_RND, AP_SAT>(15.5); std::cout << "int2 = " << int2 << std::endl; // Initialized to 132 // Could also write "0x84" // The 0x is optional ap_uint<8> int3("84"); std::cout << "int3 = " << int3 << std::endl; // Initialized to 4 // Bit selections are zero extended to match widths ap_int<4> int4 = int3(2, 0); std::cout << "int4 = " << int4 << std::endl; // Initialized to 128 // ap_uint types are zero extended to match widths // ap_int types are sign extended to match widths ap_int<16> int5 = ap_uint<8>("80"); std::cout << "int5 = " << int5 << std::endl; // Initialized to 2 // The value 4098 (= 4096 + 2) is wrapped to 2 ap_uint<12> int6 = 4098; std::cout << "int6 = " << int6 << std::endl;