3.5.1.17.6 Supported Operations in ap_[u]int, ap_[u]fixpt, and floating-point

The table below shows all the standard arithmetic operations that are supported in our Arbitrary Precision Integer and Fixed Point Libraries as well as for floating-point data types. It also shows some useful APIs that can be used to convert from one type to another or to convert to standard integral types or strings.

TypeOperatorDescriptionap_[u]intap_[u]fixptfloating
Arithmetic+AdditionYYY
-SubtractionYYY
*MultiplicationYYY
/DivisionYYY
%ModuloYYNote Below
++IncrementYYY
DecrementYYY
Assignment=AssignmentYYY
+=Add and assignYYY
-=Sub and assignYYY
*=Mult and assignYYY
/=Div and assignYYY
%=Mod and assignYYNote Below
&=bitwise AND and assignYYN/A
|=Bitwise OR and assignYYN/A
^=Bitwise XOR and assignYYN/A
>>=SHR and assignYYN/A
<<=SHL and assignYYN/A
Comparison==Equal toYYY
!=Not equal toYYY
>Greater thanYYY
<Less thanYYY
>=Greater than or equal toYYY
<=Less than or equal toYYY
Bitwise&Bitwise ANDYYN/A
^Bitwise XORYYN/A
|Bitwise ORYYN/A
~Bitwise NotYYN/A
.or_reduce()Bitwise OR reductionYYN/A
Shift<<Shift leftYYN/A
>>Shift right (Signed: ashr, unsigned: lshr)YYN/A
.lshr(ap_uint numbits)Logical shift rightYYN/A
.ashr(ap_uint numbits)Arithmetic shift rightYYN/A
Bit level accessnum(a, b)Range selectionYYN/A
num.range(a, b)Range selectionYYN/A
num[a]Bit selectionYYN/A
num.byte(n, s = 8)Select n-th byte with s bits per byteYYN/A
num.bytes(m, n, s = 8)Select m-th to n-th byte (inclusive) with s bits per byteYYN/A
(numa, numb, numc)ConcatYYN/A
Explicit Conversion.to_ufixpt()Convert to ap_ufixptYN/AN/A
.to_fixpt()Convert to ap_fixtYN/AN/A
.to_uint64()Convert to uint64YN/AN/A
.to_int64()Convert to int64YN/AN/A
.raw_bits()Convert to raw bitsN/AYN/A
.from_raw_bits()Convert from raw bitsN/AYN/A
.to_double()Convert to doubleN/AYN/A
String Conversion.to_fixpt_string()Convert to fixpt stringN/AYN/A
.to_string()Convert to int stringYYN/A
Note:

To use floating point remainder, call the fmod or fmodf function from the <math.h> header.

Note that the floating-point remainder core can be very large when used in a pipeline, so it should be used with care. For the same reason, floating point remainder is only directly supported for the float type. For double, the inputs to the core will be cast down to float, and the result will be cast back to double. This can result in a loss of precision, or incorrect results when the double input is not representable in the range of float.

: The C++ Arbitrary Precision Fixed Point Library provides the basic operations for the ap_[u]fixpt data type. SmartHLS includes an open source Fixed Point Math Library that includes tanscendental and trigonometric functions such as sin(), cos(), sqrt(), etc. See 3.5.1.17.10 SmartHLS Open Source Libraries for more information.