From: Charles R H. <cha...@gm...> - 2006-10-15 00:44:28
|
On 10/14/06, Tim Hochberg <tim...@ie...> wrote: > > Charles R Harris wrote: > > > > > > On 10/14/06, *A. M. Archibald* <per...@gm... > > <mailto:per...@gm...>> wrote: > [SNIP] > > > > > > Hmmm, I wonder if we have a dictionary of precisions indexed by dtype > > somewhere? > > Here's some code I stole from somewhere for computing EPS. It would easy > enough to generate the dictionary you are looking for at startup using > this. I can't recall the pedigree of this code though, so caveat emptor: > > def bits_of_precision(dtype): > one = np.array([1], dtype) > i = 0 > while not np.alltrue(one + (one / 2.**i) == one): > i += 1 > return i - 1 Yep, that works. There is a version in my zeros module in scipy also, it's just that ISTR seeing similar code in numpy somewhere and I was hoping Travis would tell me where ;) Grep is my friend, I guess, ... ah, here it is In [140]: np.MachAr(np.single).eps Out[140]: 1.1920928955078125e-07 In [141]: np.MachAr(np.double).eps Out[141]: 2.2204460492503131e-16 Chuck |