Author: mattip <matti.pi...@gmail.com> Branch: propogate-nans Changeset: r80508:ebaf0b23194a Date: 2015-11-03 04:42 +0200 http://bitbucket.org/pypy/pypy/changeset/ebaf0b23194a/
Log: porpogate various nan values across float conversions diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py --- a/pypy/module/micronumpy/test/test_ndarray.py +++ b/pypy/module/micronumpy/test/test_ndarray.py @@ -1852,6 +1852,19 @@ a = array([(1, 2)], dtype=[('a', 'int64'), ('b', 'int64')]) assert a.view('S16')[0] == '\x01' + '\x00' * 7 + '\x02' + def test_half_conversions(self): + from numpy import array, arange + all_f16 = arange(0xff10, 0xff20, dtype='uint16') + all_f16.dtype = 'float16' + print all_f16.view(dtype='uint16') + all_f32 = array(all_f16, dtype='float32') + print all_f32.view(dtype='uint32') + b = array(all_f32, dtype='float16') + print b.view(dtype='uint16') + c = b.view(dtype='uint16') + d = all_f16.view(dtype='uint16') + assert (c == d).all() + def test_ndarray_view_empty(self): from numpy import array, dtype x = array([], dtype=[('a', 'int8'), ('b', 'int8')]) diff --git a/rpython/rlib/rstruct/ieee.py b/rpython/rlib/rstruct/ieee.py --- a/rpython/rlib/rstruct/ieee.py +++ b/rpython/rlib/rstruct/ieee.py @@ -6,6 +6,7 @@ from rpython.rlib import rarithmetic, rfloat, objectmodel, jit from rpython.rlib.rarithmetic import r_ulonglong +from rpython.rtyper.lltypesystem.rffi import DOUBLE, cast def round_to_nearest(x): """Python 3 style round: round a float x to the nearest int, but @@ -60,7 +61,10 @@ if exp == MAX_EXP - MIN_EXP + 2: # nan or infinity - result = rfloat.NAN if mant else rfloat.INFINITY + if mant == 0: + result = rfloat.INFINITY + else: + result = rfloat.NAN #cast(DOUBLE, mant | elif exp == 0: # subnormal or zero result = math.ldexp(mant, MIN_EXP - MANT_DIG) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit