[Numpy-discussion] Fixed-point arithemetic...any solution yet?
Norbert Nemec
Norbert.Nemec.list@gmx...
Thu Dec 10 12:36:26 CST 2009
Dag Sverre Seljebotn wrote:
> I haven't heard of anything, but here's what I'd do:
> - Use np.int64
> - Multiply all inputs to my code with 10^6
> - Divide all output from my code with 10^6
> - If you need to debug-print and array, simply define something like
>
> FIXED_POINT_FACTOR = 10**6
>
> def printarr(x):
> print x.astype(np.float) / FIXED_POINT_FACTOR
>
> Or am I missing something?
>
Indeed, you are missing that internal multiplications have to take into
account this factor as well. To prevent loss of precision, you would
need int128 results and shift those correctly after the multiplication.
More information about the NumPy-Discussion
mailing list