fxp
pyfxp.fxp
Convert a numeric value to fixed-point representation using a pre-defined fixed-point specification.
This function behaves like fxpt, but instead of requiring multiple
arguments (qi, qf, signed, rnd, ovf), it accepts a single
FxpSpec named tuple (or tuple) that encapsulates all format parameters.
This makes it easier to reuse and pass fixed-point type definitions in
a compact, Numba-friendly form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(int, float or array - like)
|
The input value(s) to convert. |
required |
spec
|
FxpSpec or tuple
|
A fixed-point specification tuple or named tuple with the following fields:
|
required |
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Fixed-point representation of the input value(s). |
Notes
- Equivalent to: >>> fxp(x, Q(qi, qf, signed, rnd, ovf)) == fxpt(x, qi, qf, signed, rnd, ovf)
- Uses ARM-style Q-format notation (Qm.n), where:
- m =
qi→ number of integer bits (including signed bit ifsigned=True) - n =
qf→ number of fractional bits
- m =
- Designed to be fully compatible with Numba
@njitmode
Examples: