[Numpy-discussion] fixed-point arithmetic

Neal Becker ndbecker2@gmail....
Mon Sep 21 07:00:34 CDT 2009

One thing I'm really missing is something like matlab's fixed-pt toolbox.  
I'd love to see this added to numpy.

A fixed point integer (fpi) type is based on an integer, but keeps track of 
where the 'binary point' is.  When created, the fpi has a specified number 
of fractional bits and integer bits.  When assigned to, the fpi will check 
for overflow.  On overflow various actions can be taken, including raise 
exception and ignore (just wraparound).

numpy arrays of fpi should support all numeric operations.  Also mixed 
fpi/integer operations.

I'm not sure how to go about implementing this.  At first, I was thinking to 
just subclass numpy array.  But, I don't think this provides fpi scalars, 
and their associated operations.

I have code in c++ for a scalar fpi data type (not numpy scalar, just a c++ 
type) that I think has all the required behavior.  It depends on 
boost::python and other boost code (and unreleased boost constrained_value), 
so probably would not be interesting to a larger numpy audience.

I'm thinking this might all be implemented in cython.  I haven't used cython 
yet, so this could be an opportunity.  OTOH, I don't know if cython has all 
the capabilities to implement a new numpy scalar/array type.

Thoughts?  Interest?   

More information about the NumPy-Discussion mailing list