3.5.1.19.6 Supported Operations in ap_[u]int, ap_[u]fixpt, and floating-point
(Ask a Question)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.
Type | Operator | Description | ap_[u]int | ap_[u]fixpt | floating |
---|---|---|---|---|---|
Arithmetic | + | Addition | Y | Y | Y |
- | Subtraction | Y | Y | Y | |
* | Multiplication | Y | Y | Y | |
/ | Division | Y | Y | Y | |
% | Modulo | Y | Y | Note Below | |
++ | Increment | Y | Y | Y | |
– | Decrement | Y | Y | Y | |
Assignment | = | Assignment | Y | Y | Y |
+= | Add and assign | Y | Y | Y | |
-= | Sub and assign | Y | Y | Y | |
*= | Mult and assign | Y | Y | Y | |
/= | Div and assign | Y | Y | Y | |
%= | Mod and assign | Y | Y | Note Below | |
&= | bitwise AND and assign | Y | Y | N/A | |
|= | Bitwise OR and assign | Y | Y | N/A | |
^= | Bitwise XOR and assign | Y | Y | N/A | |
>>= | SHR and assign | Y | Y | N/A | |
<<= | SHL and assign | Y | Y | N/A | |
Comparison | == | Equal to | Y | Y | Y |
!= | Not equal to | Y | Y | Y | |
> | Greater than | Y | Y | Y | |
< | Less than | Y | Y | Y | |
>= | Greater than or equal to | Y | Y | Y | |
<= | Less than or equal to | Y | Y | Y | |
Bitwise | & | Bitwise AND | Y | Y | N/A |
^ | Bitwise XOR | Y | Y | N/A | |
| | Bitwise OR | Y | Y | N/A | |
~ | Bitwise Not | Y | Y | N/A | |
.or_reduce() | Bitwise OR reduction | Y | Y | N/A | |
Shift | << | Shift left | Y | Y | N/A |
>> | Shift right (Signed: ashr , unsigned: lshr ) | Y | Y | N/A | |
.lshr(ap_uint numbits) | Logical shift right | Y | Y | N/A | |
.ashr(ap_uint numbits) | Arithmetic shift right | Y | Y | N/A | |
Bit level access | num(a, b) | Range selection | Y | Y | N/A |
num.range(a, b) | Range selection | Y | Y | N/A | |
num[a] | Bit selection | Y | Y | N/A | |
num.byte(n, s = 8) | Select n-th byte with s bits per byte | Y | Y | N/A | |
num.bytes(m, n, s = 8) | Select m-th to n-th byte (inclusive) with s bits per byte | Y | Y | N/A | |
(numa, numb, numc) | Concat | Y | Y | N/A | |
Explicit Conversion | .to_ufixpt() | Convert to ap_ufixpt | Y | N/A | N/A |
.to_fixpt() | Convert to ap_fixt | Y | N/A | N/A | |
.to_uint64() | Convert to uint64 | Y | N/A | N/A | |
.to_int64() | Convert to int64 | Y | N/A | N/A | |
.raw_bits() | Convert to raw bits | N/A | Y | N/A | |
.from_raw_bits() | Convert from raw bits | N/A | Y | N/A | |
.to_double() | Convert to double | N/A | Y | N/A | |
String Conversion | .to_fixpt_string() | Convert to fixpt string | N/A | Y | N/A |
.to_string() | Convert to int string | Y | Y | N/A |
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.