Author: Benjamin Peterson <benja...@python.org> Branch: Changeset: r93681:3d1f618efa2e Date: 2018-01-19 00:13 -0800 http://bitbucket.org/pypy/pypy/changeset/3d1f618efa2e/
Log: replace rfloat.isnan and rfloat.isinf with the functions in the math module diff --git a/pypy/module/__builtin__/operation.py b/pypy/module/__builtin__/operation.py --- a/pypy/module/__builtin__/operation.py +++ b/pypy/module/__builtin__/operation.py @@ -2,11 +2,13 @@ Interp-level implementation of the basic space operations. """ +import math + from pypy.interpreter import gateway from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.gateway import unwrap_spec, WrappedDefault from rpython.rlib.runicode import UNICHR -from rpython.rlib.rfloat import isfinite, isinf, round_double, round_away +from rpython.rlib.rfloat import isfinite, round_double, round_away from rpython.rlib import rfloat import __builtin__ @@ -151,7 +153,7 @@ else: # finite x, and ndigits is not unreasonably large z = round_double(number, ndigits) - if isinf(z): + if math.isinf(z): raise oefmt(space.w_OverflowError, "rounded value too large to represent") return space.newfloat(z) diff --git a/pypy/module/cmath/test/test_cmath.py b/pypy/module/cmath/test/test_cmath.py --- a/pypy/module/cmath/test/test_cmath.py +++ b/pypy/module/cmath/test/test_cmath.py @@ -1,5 +1,4 @@ from __future__ import with_statement -from rpython.rlib.rfloat import isnan, isinf from pypy.module.cmath import interp_cmath import os, sys, math @@ -142,12 +141,12 @@ """ # special values testing - if isnan(a): - if isnan(b): + if math.isnan(a): + if math.isnan(b): return raise AssertionError(msg + '%r should be nan' % (b,)) - if isinf(a): + if math.isinf(a): if a == b: return raise AssertionError(msg + 'finite result where infinity expected: ' diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py --- a/pypy/module/math/interp_math.py +++ b/pypy/module/math/interp_math.py @@ -65,11 +65,11 @@ def isinf(space, w_x): """Return True if x is infinity.""" - return space.newbool(rfloat.isinf(_get_double(space, w_x))) + return space.newbool(math.isinf(_get_double(space, w_x))) def isnan(space, w_x): """Return True if x is not a number.""" - return space.newbool(rfloat.isnan(_get_double(space, w_x))) + return space.newbool(math.isnan(_get_double(space, w_x))) def pow(space, w_x, w_y): """pow(x,y) @@ -327,14 +327,14 @@ if not rfloat.isfinite(v): if rfloat.isfinite(original): raise oefmt(space.w_OverflowError, "intermediate overflow") - if rfloat.isinf(original): + if math.isinf(original): inf_sum += original special_sum += original del partials[:] else: partials.append(v) if special_sum != 0.0: - if rfloat.isnan(inf_sum): + if math.isnan(inf_sum): raise oefmt(space.w_ValueError, "-inf + inf") return space.newfloat(special_sum) hi = 0.0 diff --git a/pypy/module/micronumpy/test/test_complex.py b/pypy/module/micronumpy/test/test_complex.py --- a/pypy/module/micronumpy/test/test_complex.py +++ b/pypy/module/micronumpy/test/test_complex.py @@ -7,7 +7,6 @@ from pypy.interpreter.error import OperationError from pypy.interpreter.gateway import interp2app from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest -from rpython.rlib.rfloat import isnan, isinf from rpython.rlib.rcomplex import c_pow @@ -22,12 +21,12 @@ """ # special values testing - if isnan(a): - if isnan(b): + if math.isnan(a): + if math.isnan(b): return True,'' raise AssertionError(msg + '%r should be nan' % (b,)) - if isinf(a): + if math.isinf(a): if a == b: return True,'' raise AssertionError(msg + 'finite result where infinity expected: '+ \ diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py --- a/pypy/module/micronumpy/types.py +++ b/pypy/module/micronumpy/types.py @@ -816,7 +816,7 @@ def sign(self, v): if v == 0.0: return 0.0 - if rfloat.isnan(v): + if math.isnan(v): return rfloat.NAN return math.copysign(1.0, v) @@ -830,27 +830,27 @@ @simple_binary_op def max(self, v1, v2): - return v1 if v1 >= v2 or rfloat.isnan(v1) else v2 + return v1 if v1 >= v2 or math.isnan(v1) else v2 @simple_binary_op def min(self, v1, v2): - return v1 if v1 <= v2 or rfloat.isnan(v1) else v2 + return v1 if v1 <= v2 or math.isnan(v1) else v2 @raw_binary_op def argmax(self, v1, v2): - return v1 >= v2 or rfloat.isnan(v1) + return v1 >= v2 or math.isnan(v1) @raw_binary_op def argmin(self, v1, v2): - return v1 <= v2 or rfloat.isnan(v1) + return v1 <= v2 or math.isnan(v1) @simple_binary_op def fmax(self, v1, v2): - return v1 if v1 >= v2 or rfloat.isnan(v2) else v2 + return v1 if v1 >= v2 or math.isnan(v2) else v2 @simple_binary_op def fmin(self, v1, v2): - return v1 if v1 <= v2 or rfloat.isnan(v2) else v2 + return v1 if v1 <= v2 or math.isnan(v2) else v2 @simple_binary_op def fmod(self, v1, v2): @@ -876,9 +876,9 @@ @specialize.argtype(1) def round(self, v, decimals=0): raw = self.for_computation(self.unbox(v)) - if rfloat.isinf(raw): + if math.isinf(raw): return v - elif rfloat.isnan(raw): + elif math.isnan(raw): return v ans = rfloat.round_double(raw, decimals, half_even=True) return self.box(ans) @@ -986,11 +986,11 @@ @raw_unary_op def isnan(self, v): - return rfloat.isnan(v) + return math.isnan(v) @raw_unary_op def isinf(self, v): - return rfloat.isinf(v) + return math.isinf(v) @raw_unary_op def isfinite(self, v): @@ -1189,7 +1189,7 @@ return imag_str real_str = str_format(real) - op = '+' if imag >= 0 or rfloat.isnan(imag) else '' + op = '+' if imag >= 0 or math.isnan(imag) else '' return ''.join(['(', real_str, op, imag_str, ')']) def runpack_str(self, space, s, native): @@ -1318,7 +1318,7 @@ return rcomplex.c_div(v1, v2) except ZeroDivisionError: if rcomplex.c_abs(*v1) == 0 or \ - (rfloat.isnan(v1[0]) and rfloat.isnan(v1[1])): + (math.isnan(v1[0]) and math.isnan(v1[1])): return rfloat.NAN, rfloat.NAN return rfloat.INFINITY, rfloat.INFINITY @@ -1353,12 +1353,12 @@ @raw_unary_op def isnan(self, v): '''a complex number is nan if one of the parts is nan''' - return rfloat.isnan(v[0]) or rfloat.isnan(v[1]) + return math.isnan(v[0]) or math.isnan(v[1]) @raw_unary_op def isinf(self, v): '''a complex number is inf if one of the parts is inf''' - return rfloat.isinf(v[0]) or rfloat.isinf(v[1]) + return math.isinf(v[0]) or math.isinf(v[1]) def _eq(self, v1, v2): return v1[0] == v2[0] and v1[1] == v2[1] @@ -1374,7 +1374,7 @@ def _lt(self, v1, v2): (r1, i1), (r2, i2) = v1, v2 - if r1 < r2 and not rfloat.isnan(i1) and not rfloat.isnan(i2): + if r1 < r2 and not math.isnan(i1) and not math.isnan(i2): return True if r1 == r2 and i1 < i2: return True @@ -1459,7 +1459,7 @@ ratio = i2 / r2 denom = r2 + i2 * ratio rr = (r1 + i1 * ratio) / denom - elif rfloat.isnan(r2): + elif math.isnan(r2): rr = rfloat.NAN else: ratio = r2 / i2 @@ -1503,7 +1503,7 @@ sign of complex number could be either the point closest to the unit circle or {-1,0,1}, for compatability with numpy we choose the latter ''' - if rfloat.isnan(v[0]) or rfloat.isnan(v[1]): + if math.isnan(v[0]) or math.isnan(v[1]): return rfloat.NAN, 0 if v[0] == 0.0: if v[1] == 0: @@ -1534,9 +1534,9 @@ @complex_unary_op def reciprocal(self, v): - if rfloat.isinf(v[1]) and rfloat.isinf(v[0]): + if math.isinf(v[1]) and math.isinf(v[0]): return rfloat.NAN, rfloat.NAN - if rfloat.isinf(v[0]): + if math.isinf(v[0]): return (math.copysign(0., v[0]), math.copysign(0., -v[1])) a2 = v[0]*v[0] + v[1]*v[1] @@ -1575,13 +1575,13 @@ @complex_unary_op def exp(self, v): - if rfloat.isinf(v[1]): - if rfloat.isinf(v[0]): + if math.isinf(v[1]): + if math.isinf(v[0]): if v[0] < 0: return 0., 0. return rfloat.INFINITY, rfloat.NAN elif (rfloat.isfinite(v[0]) or \ - (rfloat.isinf(v[0]) and v[0] > 0)): + (math.isinf(v[0]) and v[0] > 0)): return rfloat.NAN, rfloat.NAN try: return rcomplex.c_exp(*v) @@ -1603,13 +1603,13 @@ def expm1(self, v): # duplicate exp() so in the future it will be easier # to implement seterr - if rfloat.isinf(v[1]): - if rfloat.isinf(v[0]): + if math.isinf(v[1]): + if math.isinf(v[0]): if v[0] < 0: return -1., 0. return rfloat.NAN, rfloat.NAN elif (rfloat.isfinite(v[0]) or \ - (rfloat.isinf(v[0]) and v[0] > 0)): + (math.isinf(v[0]) and v[0] > 0)): return rfloat.NAN, rfloat.NAN try: res = rcomplex.c_exp(*v) @@ -1622,29 +1622,29 @@ @complex_unary_op def sin(self, v): - if rfloat.isinf(v[0]): + if math.isinf(v[0]): if v[1] == 0.: return rfloat.NAN, 0. if rfloat.isfinite(v[1]): return rfloat.NAN, rfloat.NAN - elif not rfloat.isnan(v[1]): + elif not math.isnan(v[1]): return rfloat.NAN, rfloat.INFINITY return rcomplex.c_sin(*v) @complex_unary_op def cos(self, v): - if rfloat.isinf(v[0]): + if math.isinf(v[0]): if v[1] == 0.: return rfloat.NAN, 0.0 if rfloat.isfinite(v[1]): return rfloat.NAN, rfloat.NAN - elif not rfloat.isnan(v[1]): + elif not math.isnan(v[1]): return rfloat.INFINITY, rfloat.NAN return rcomplex.c_cos(*v) @complex_unary_op def tan(self, v): - if rfloat.isinf(v[0]) and rfloat.isfinite(v[1]): + if math.isinf(v[0]) and rfloat.isfinite(v[1]): return rfloat.NAN, rfloat.NAN return rcomplex.c_tan(*v) @@ -1669,29 +1669,29 @@ @complex_unary_op def sinh(self, v): - if rfloat.isinf(v[1]): + if math.isinf(v[1]): if rfloat.isfinite(v[0]): if v[0] == 0.0: return 0.0, rfloat.NAN return rfloat.NAN, rfloat.NAN - elif not rfloat.isnan(v[0]): + elif not math.isnan(v[0]): return rfloat.INFINITY, rfloat.NAN return rcomplex.c_sinh(*v) @complex_unary_op def cosh(self, v): - if rfloat.isinf(v[1]): + if math.isinf(v[1]): if rfloat.isfinite(v[0]): if v[0] == 0.0: return rfloat.NAN, 0.0 return rfloat.NAN, rfloat.NAN - elif not rfloat.isnan(v[0]): + elif not math.isnan(v[0]): return rfloat.INFINITY, rfloat.NAN return rcomplex.c_cosh(*v) @complex_unary_op def tanh(self, v): - if rfloat.isinf(v[1]) and rfloat.isfinite(v[0]): + if math.isinf(v[1]) and rfloat.isfinite(v[0]): return rfloat.NAN, rfloat.NAN return rcomplex.c_tanh(*v) diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py --- a/pypy/module/time/interp_time.py +++ b/pypy/module/time/interp_time.py @@ -6,6 +6,7 @@ from rpython.rlib.rarithmetic import intmask from rpython.rlib import rposix, rtime from rpython.translator.tool.cbuild import ExternalCompilationInfo +import math import os import sys import time as pytime @@ -311,11 +312,10 @@ return os.strerror(errno) def _check_sleep_arg(space, secs): - from rpython.rlib.rfloat import isinf, isnan if secs < 0: raise oefmt(space.w_IOError, "Invalid argument: negative time in sleep") - if isinf(secs) or isnan(secs): + if math.isinf(secs) or math.isnan(secs): raise oefmt(space.w_IOError, "Invalid argument: inf or nan") diff --git a/pypy/objspace/std/complexobject.py b/pypy/objspace/std/complexobject.py --- a/pypy/objspace/std/complexobject.py +++ b/pypy/objspace/std/complexobject.py @@ -4,7 +4,7 @@ from rpython.rlib.rarithmetic import intmask, r_ulonglong from rpython.rlib.rbigint import rbigint from rpython.rlib.rfloat import ( - DTSF_STR_PRECISION, formatd, isinf, isnan, string_to_float) + DTSF_STR_PRECISION, formatd, string_to_float) from rpython.rlib.rstring import ParseStringError from pypy.interpreter.baseobjspace import W_Root @@ -111,12 +111,12 @@ def format_float(x, code, precision): # like float2string, except that the ".0" is not necessary - if isinf(x): + if math.isinf(x): if x > 0.0: return "inf" else: return "-inf" - elif isnan(x): + elif math.isnan(x): return "nan" else: return formatd(x, code, precision) @@ -349,7 +349,7 @@ if self.realval == 0 and math.copysign(1., self.realval) == 1.: return space.newtext(repr_format(self.imagval) + 'j') sign = (math.copysign(1., self.imagval) == 1. or - isnan(self.imagval)) and '+' or '' + math.isnan(self.imagval)) and '+' or '' return space.newtext('(' + repr_format(self.realval) + sign + repr_format(self.imagval) + 'j)') @@ -357,7 +357,7 @@ if self.realval == 0 and math.copysign(1., self.realval) == 1.: return space.newtext(str_format(self.imagval) + 'j') sign = (math.copysign(1., self.imagval) == 1. or - isnan(self.imagval)) and '+' or '' + math.isnan(self.imagval)) and '+' or '' return space.newtext('(' + str_format(self.realval) + sign + str_format(self.imagval) + 'j)') diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py --- a/pypy/objspace/std/floatobject.py +++ b/pypy/objspace/std/floatobject.py @@ -8,7 +8,7 @@ from rpython.rlib.rbigint import rbigint from rpython.rlib.rfloat import ( DTSF_ADD_DOT_0, DTSF_STR_PRECISION, INFINITY, NAN, - float_as_rbigint_ratio, formatd, isfinite, isinf, isnan) + float_as_rbigint_ratio, formatd, isfinite) from rpython.rlib.rstring import ParseStringError from rpython.rlib.unroll import unrolling_iterable from rpython.rtyper.lltypesystem.module.ll_math import math_fmod @@ -27,7 +27,7 @@ # we special-case explicitly inf and nan here if isfinite(x): s = formatd(x, code, precision, DTSF_ADD_DOT_0) - elif isinf(x): + elif math.isinf(x): if x > 0.0: s = "inf" else: @@ -704,7 +704,7 @@ def _hash_float(space, v): - if isnan(v): + if math.isnan(v): return 0 # This is designed so that Python numbers of different types @@ -798,16 +798,16 @@ if y == 0.0: # x**0 is 1, even 0**0 return 1.0 - if isnan(x): + if math.isnan(x): # nan**y = nan, unless y == 0 return x - if isnan(y): + if math.isnan(y): # x**nan = nan, unless x == 1; x**nan = x if x == 1.0: return 1.0 else: return y - if isinf(y): + if math.isinf(y): # x**inf is: 0.0 if abs(x) < 1; 1.0 if abs(x) == 1; inf if # abs(x) > 1 (including case where x infinite) # @@ -820,7 +820,7 @@ return INFINITY else: return 0.0 - if isinf(x): + if math.isinf(x): # (+-inf)**w is: inf for w positive, 0 for w negative; in oth # cases, we need to add the appropriate sign if w is an odd # integer. @@ -846,7 +846,7 @@ # unlike "math.pow(-1.0, bignum)". See http://mail.python.org/ # - pipermail/python-bugs-list/2003-March/016795.html if x < 0.0: - if isnan(y): + if math.isnan(y): return NAN if math.floor(y) != y: raise PowDomainError diff --git a/pypy/objspace/std/formatting.py b/pypy/objspace/std/formatting.py --- a/pypy/objspace/std/formatting.py +++ b/pypy/objspace/std/formatting.py @@ -1,10 +1,11 @@ """String formatting routines""" +import math import sys from rpython.rlib import jit from rpython.rlib.objectmodel import specialize from rpython.rlib.rarithmetic import INT_MAX -from rpython.rlib.rfloat import DTSF_ALT, formatd, isnan, isinf +from rpython.rlib.rfloat import DTSF_ALT, formatd from rpython.rlib.rstring import StringBuilder, UnicodeBuilder from rpython.rlib.unroll import unrolling_iterable from rpython.tool.sourcetools import func_with_new_name @@ -118,12 +119,12 @@ def format_float(self, w_value, char): space = self.space x = space.float_w(maybe_float(space, w_value)) - if isnan(x): + if math.isnan(x): if char in 'EFG': r = 'NAN' else: r = 'nan' - elif isinf(x): + elif math.isinf(x): if x < 0: if char in 'EFG': r = '-INF' diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py --- a/pypy/objspace/std/listobject.py +++ b/pypy/objspace/std/listobject.py @@ -7,6 +7,7 @@ """ +import math import operator import sys @@ -1797,11 +1798,9 @@ def _safe_find(self, w_list, obj, start, stop): - from rpython.rlib.rfloat import isnan - # l = self.unerase(w_list.lstorage) stop = min(stop, len(l)) - if not isnan(obj): + if not math.isnan(obj): for i in range(start, stop): val = l[i] if val == obj: diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py --- a/rpython/annotator/model.py +++ b/rpython/annotator/model.py @@ -170,9 +170,8 @@ def __eq__(self, other): if (type(self) is SomeFloat and type(other) is SomeFloat and self.is_constant() and other.is_constant()): - from rpython.rlib.rfloat import isnan # NaN unpleasantness. - if isnan(self.const) and isnan(other.const): + if math.isnan(self.const) and math.isnan(other.const): return True # 0.0 vs -0.0 unpleasantness. if not self.const and not other.const: diff --git a/rpython/jit/backend/test/runner_test.py b/rpython/jit/backend/test/runner_test.py --- a/rpython/jit/backend/test/runner_test.py +++ b/rpython/jit/backend/test/runner_test.py @@ -1,4 +1,4 @@ -import py, sys, random, os, struct, operator +import py, sys, random, os, struct, operator, math from rpython.jit.metainterp.history import (AbstractFailDescr, AbstractDescr, BasicFailDescr, @@ -1696,7 +1696,7 @@ if not self.cpu.supports_floats: py.test.skip("requires floats") - from rpython.rlib.rfloat import INFINITY, NAN, isinf, isnan + from rpython.rlib.rfloat import INFINITY, NAN from rpython.jit.metainterp.resoperation import opname fzer = 0.0 @@ -1724,10 +1724,10 @@ expectedtype) if not isinstance(expected, bool): got = longlong.getrealfloat(got) - if isnan(expected): - ok = isnan(got) - elif isinf(expected): - ok = isinf(got) + if math.isnan(expected): + ok = math.isnan(got) + elif math.isinf(expected): + ok = math.isinf(got) else: ok = got == expected if not ok: diff --git a/rpython/jit/metainterp/test/support.py b/rpython/jit/metainterp/test/support.py --- a/rpython/jit/metainterp/test/support.py +++ b/rpython/jit/metainterp/test/support.py @@ -1,5 +1,4 @@ - -import py, sys +import py, sys, math from rpython.rtyper.lltypesystem import lltype, llmemory from rpython.jit.backend.llgraph import runner from rpython.jit.metainterp.warmspot import ll_meta_interp, get_stats @@ -10,7 +9,6 @@ from rpython.jit.codewriter.policy import JitPolicy from rpython.jit.codewriter import codewriter, longlong from rpython.jit.backend.llsupport.vector_ext import VectorExt -from rpython.rlib.rfloat import isnan from rpython.rlib.jit import ENABLE_ALL_OPTS from rpython.translator.backendopt.all import backend_optimizations @@ -274,11 +272,11 @@ result1 = _run_with_blackhole(self, args) # try to run it with pyjitpl.py result2 = _run_with_pyjitpl(self, args, stats) - assert result1 == result2 or isnan(result1) and isnan(result2) + assert result1 == result2 or math.isnan(result1) and math.isnan(result2) # try to run it by running the code compiled just before df, result3 = _run_with_machine_code(self, args) self._lastframe = df - assert result1 == result3 or result3 == NotImplemented or isnan(result1) and isnan(result3) + assert result1 == result3 or result3 == NotImplemented or math.isnan(result1) and math.isnan(result3) # if (longlong.supports_longlong and isinstance(result1, longlong.r_float_storage)): diff --git a/rpython/jit/metainterp/test/test_ajit.py b/rpython/jit/metainterp/test/test_ajit.py --- a/rpython/jit/metainterp/test/test_ajit.py +++ b/rpython/jit/metainterp/test/test_ajit.py @@ -1,3 +1,4 @@ +import math import sys import py @@ -3973,7 +3974,6 @@ assert res == 3 def test_float_bytes(self): - from rpython.rlib.rfloat import isnan def f(n): ll = float2longlong(n) return longlong2float(ll) @@ -3981,7 +3981,7 @@ for x in [2.5, float("nan"), -2.5, float("inf")]: # There are tests elsewhere to verify the correctness of this. res = self.interp_operations(f, [x]) - assert res == x or isnan(x) and isnan(res) + assert res == x or math.isnan(x) and math.isnan(res) class TestLLtype(BaseLLtypeTests, LLJitMixin): diff --git a/rpython/jit/metainterp/test/test_math.py b/rpython/jit/metainterp/test/test_math.py --- a/rpython/jit/metainterp/test/test_math.py +++ b/rpython/jit/metainterp/test/test_math.py @@ -1,6 +1,6 @@ import math from rpython.jit.metainterp.test.support import LLJitMixin -from rpython.rlib.rfloat import isinf, isnan, INFINITY, NAN +from rpython.rlib.rfloat import INFINITY, NAN class MathTests: @@ -32,11 +32,11 @@ self.check_operations_history(call_pure_f=0) # res = self.interp_operations(f, [INFINITY]) - assert isinf(res) and not isnan(res) and res > 0.0 + assert math.isinf(res) and not math.isnan(res) and res > 0.0 self.check_operations_history(call_pure_f=0) # res = self.interp_operations(f, [NAN]) - assert isnan(res) and not isinf(res) + assert math.isnan(res) and not math.isinf(res) self.check_operations_history(call_pure_f=0) diff --git a/rpython/jit/metainterp/test/test_zvector.py b/rpython/jit/metainterp/test/test_zvector.py --- a/rpython/jit/metainterp/test/test_zvector.py +++ b/rpython/jit/metainterp/test/test_zvector.py @@ -11,7 +11,6 @@ from rpython.jit.metainterp import history from rpython.rlib.jit import JitDriver, hint, set_param from rpython.rlib.objectmodel import compute_hash -from rpython.rlib import rfloat from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rlib.rarithmetic import r_uint, intmask, r_int from rpython.rlib.rawstorage import (alloc_raw_storage, raw_storage_setitem, @@ -309,7 +308,7 @@ reds = 'auto', vectorize=True) def fmax(v1, v2): - return v1 if v1 >= v2 or rfloat.isnan(v2) else v2 + return v1 if v1 >= v2 or math.isnan(v2) else v2 T = lltype.Array(rffi.DOUBLE, hints={'nolength': True}) def f(d): i = 0 diff --git a/rpython/rlib/constant.py b/rpython/rlib/constant.py --- a/rpython/rlib/constant.py +++ b/rpython/rlib/constant.py @@ -1,5 +1,4 @@ import math -from rpython.rlib.rfloat import isinf from rpython.rtyper.tool import rffi_platform from rpython.translator.tool.cbuild import ExternalCompilationInfo @@ -18,7 +17,7 @@ assert 0.0 < DBL_MAX < (1e200*1e200) -assert isinf(DBL_MAX * 1.0001) +assert math.isinf(DBL_MAX * 1.0001) assert DBL_MIN > 0.0 assert DBL_MIN * (2**-53) == 0.0 diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py --- a/rpython/rlib/objectmodel.py +++ b/rpython/rlib/objectmodel.py @@ -549,9 +549,9 @@ In RPython, floats cannot be used with ints in dicts, anyway. """ from rpython.rlib.rarithmetic import intmask - from rpython.rlib.rfloat import isfinite, isinf + from rpython.rlib.rfloat import isfinite if not isfinite(f): - if isinf(f): + if math.isinf(f): if f < 0.0: return -271828 else: diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py --- a/rpython/rlib/rarithmetic.py +++ b/rpython/rlib/rarithmetic.py @@ -36,7 +36,7 @@ """ -import sys, struct +import sys, struct, math from rpython.rtyper import extregistry from rpython.rlib import objectmodel from rpython.flowspace.model import Constant, const @@ -191,8 +191,7 @@ # Note the "<= x <" here, as opposed to "< x <" above. # This is justified by test_typed in translator/c/test. def ovfcheck_float_to_longlong(x): - from rpython.rlib.rfloat import isnan - if isnan(x): + if math.isnan(x): raise OverflowError if -9223372036854776832.0 <= x < 9223372036854775296.0: return r_longlong(x) @@ -200,8 +199,7 @@ if sys.maxint == 2147483647: def ovfcheck_float_to_int(x): - from rpython.rlib.rfloat import isnan - if isnan(x): + if math.isnan(x): raise OverflowError if -2147483649.0 < x < 2147483648.0: return int(x) diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py --- a/rpython/rlib/rbigint.py +++ b/rpython/rlib/rbigint.py @@ -1,7 +1,6 @@ from rpython.rlib.rarithmetic import LONG_BIT, intmask, longlongmask, r_uint, r_ulonglong from rpython.rlib.rarithmetic import ovfcheck, r_longlong, widen from rpython.rlib.rarithmetic import most_neg_value_of_same_type -from rpython.rlib.rfloat import isinf, isnan from rpython.rlib.rstring import StringBuilder from rpython.rlib.debug import make_sure_not_resized, check_regular_int from rpython.rlib.objectmodel import we_are_translated, specialize, not_rpython @@ -227,9 +226,9 @@ def fromfloat(dval): """ Create a new bigint object from a float """ # This function is not marked as pure because it can raise - if isinf(dval): + if math.isinf(dval): raise OverflowError("cannot convert float infinity to integer") - if isnan(dval): + if math.isnan(dval): raise ValueError("cannot convert float NaN to integer") return rbigint._fromfloat_finite(dval) diff --git a/rpython/rlib/rcomplex.py b/rpython/rlib/rcomplex.py --- a/rpython/rlib/rcomplex.py +++ b/rpython/rlib/rcomplex.py @@ -1,6 +1,6 @@ import math from math import fabs -from rpython.rlib.rfloat import asinh, log1p, isfinite, isinf, isnan +from rpython.rlib.rfloat import asinh, log1p, isfinite from rpython.rlib.constant import DBL_MIN, CM_SCALE_UP, CM_SCALE_DOWN from rpython.rlib.constant import CM_LARGE_DOUBLE, DBL_MANT_DIG from rpython.rlib.constant import M_LN2, M_LN10 @@ -57,7 +57,7 @@ denom = r2 + i2 * ratio rr = (r1 + i1 * ratio) / denom ir = (i1 - r1 * ratio) / denom - elif isnan(r2): + elif math.isnan(r2): rr = NAN ir = NAN else: @@ -330,7 +330,7 @@ def c_exp(x, y): if not isfinite(x) or not isfinite(y): - if isinf(x) and isfinite(y) and y != 0.: + if math.isinf(x) and isfinite(y) and y != 0.: if x > 0: real = math.copysign(INF, math.cos(y)) imag = math.copysign(INF, math.sin(y)) @@ -343,7 +343,7 @@ # need to raise ValueError if y is +/- infinity and x is not # a NaN and not -infinity - if isinf(y) and (isfinite(x) or (isinf(x) and x > 0)): + if math.isinf(y) and (isfinite(x) or (math.isinf(x) and x > 0)): raise ValueError("math domain error") return r @@ -355,14 +355,14 @@ l = math.exp(x) real = l * math.cos(y) imag = l * math.sin(y) - if isinf(real) or isinf(imag): + if math.isinf(real) or math.isinf(imag): raise OverflowError("math range error") return real, imag def c_cosh(x, y): if not isfinite(x) or not isfinite(y): - if isinf(x) and isfinite(y) and y != 0.: + if math.isinf(x) and isfinite(y) and y != 0.: if x > 0: real = math.copysign(INF, math.cos(y)) imag = math.copysign(INF, math.sin(y)) @@ -375,7 +375,7 @@ # need to raise ValueError if y is +/- infinity and x is not # a NaN - if isinf(y) and not isnan(x): + if math.isinf(y) and not math.isnan(x): raise ValueError("math domain error") return r @@ -388,7 +388,7 @@ else: real = math.cos(y) * math.cosh(x) imag = math.sin(y) * math.sinh(x) - if isinf(real) or isinf(imag): + if math.isinf(real) or math.isinf(imag): raise OverflowError("math range error") return real, imag @@ -396,7 +396,7 @@ def c_sinh(x, y): # special treatment for sinh(+/-inf + iy) if y is finite and nonzero if not isfinite(x) or not isfinite(y): - if isinf(x) and isfinite(y) and y != 0.: + if math.isinf(x) and isfinite(y) and y != 0.: if x > 0: real = math.copysign(INF, math.cos(y)) imag = math.copysign(INF, math.sin(y)) @@ -409,7 +409,7 @@ # need to raise ValueError if y is +/- infinity and x is not # a NaN - if isinf(y) and not isnan(x): + if math.isinf(y) and not math.isnan(x): raise ValueError("math domain error") return r @@ -420,7 +420,7 @@ else: real = math.cos(y) * math.sinh(x) imag = math.sin(y) * math.cosh(x) - if isinf(real) or isinf(imag): + if math.isinf(real) or math.isinf(imag): raise OverflowError("math range error") return real, imag @@ -437,7 +437,7 @@ # computation of cosh(x). if not isfinite(x) or not isfinite(y): - if isinf(x) and isfinite(y) and y != 0.: + if math.isinf(x) and isfinite(y) and y != 0.: if x > 0: real = 1.0 # vv XXX why is the 2. there? imag = math.copysign(0., 2. * math.sin(y) * math.cos(y)) @@ -449,7 +449,7 @@ r = tanh_special_values[special_type(x)][special_type(y)] # need to raise ValueError if y is +/-infinity and x is finite - if isinf(y) and isfinite(x): + if math.isinf(y) and isfinite(x): raise ValueError("math domain error") return r @@ -487,7 +487,7 @@ # if r is +/-infinity and phi is finite but nonzero then # result is (+-INF +-INF i), but we need to compute cos(phi) # and sin(phi) to figure out the signs. - if isinf(r) and isfinite(phi) and phi != 0.: + if math.isinf(r) and isfinite(phi) and phi != 0.: if r > 0: real = math.copysign(INF, math.cos(phi)) imag = math.copysign(INF, math.sin(phi)) @@ -500,7 +500,7 @@ # need to raise ValueError if r is a nonzero number and phi # is infinite - if r != 0. and not isnan(r) and isinf(phi): + if r != 0. and not math.isnan(r) and math.isinf(phi): raise ValueError("math domain error") return z @@ -512,10 +512,10 @@ def c_phase(x, y): # Windows screws up atan2 for inf and nan, and alpha Tru64 5.1 doesn't # follow C99 for atan2(0., 0.). - if isnan(x) or isnan(y): + if math.isnan(x) or math.isnan(y): return NAN - if isinf(y): - if isinf(x): + if math.isinf(y): + if math.isinf(x): if math.copysign(1., x) == 1.: # atan2(+-inf, +inf) == +-pi/4 return math.copysign(0.25 * math.pi, y) @@ -524,7 +524,7 @@ return math.copysign(0.75 * math.pi, y) # atan2(+-inf, x) == +-pi/2 for finite x return math.copysign(0.5 * math.pi, y) - if isinf(x) or y == 0.: + if math.isinf(x) or y == 0.: if math.copysign(1., x) == 1.: # atan2(+-y, +inf) = atan2(+-0, +x) = +-0. return math.copysign(0., y) @@ -538,9 +538,9 @@ if not isfinite(r) or not isfinite(i): # C99 rules: if either the real or the imaginary part is an # infinity, return infinity, even if the other part is a NaN. - if isinf(r): + if math.isinf(r): return INF - if isinf(i): + if math.isinf(i): return INF # either the real or imaginary part is a NaN, @@ -560,11 +560,11 @@ def c_isinf(r, i): - return isinf(r) or isinf(i) + return math.isinf(r) or math.isinf(i) def c_isnan(r, i): - return isnan(r) or isnan(i) + return math.isnan(r) or math.isnan(i) def c_isfinite(r, i): diff --git a/rpython/rlib/rfloat.py b/rpython/rlib/rfloat.py --- a/rpython/rlib/rfloat.py +++ b/rpython/rlib/rfloat.py @@ -1,7 +1,7 @@ """Float constants""" import math, struct -from math import isinf, isnan, acosh, asinh, atanh, log1p, expm1 +from math import acosh, asinh, atanh, log1p, expm1 from rpython.annotator.model import SomeString, SomeChar from rpython.rlib import objectmodel, unroll @@ -85,7 +85,7 @@ def double_to_string(value, tp, precision, flags): if isfinite(value): special = DIST_FINITE - elif isinf(value): + elif math.isinf(value): special = DIST_INFINITY else: #isnan(value): special = DIST_NAN @@ -204,7 +204,7 @@ # (a) produce exact results for powers of 2, and # (b) be monotonic, assuming that the system log is monotonic. if not isfinite(x): - if isnan(x): + if math.isnan(x): return x # log2(nan) = nan elif x > 0.0: return x # log2(+inf) = +inf @@ -262,14 +262,14 @@ @not_rpython def isfinite(x): - return not isinf(x) and not isnan(x) + return not math.isinf(x) and not math.isnan(x) def float_as_rbigint_ratio(value): from rpython.rlib.rbigint import rbigint - if isinf(value): + if math.isinf(value): raise OverflowError("cannot pass infinity to as_integer_ratio()") - elif isnan(value): + elif math.isnan(value): raise ValueError("cannot pass nan to as_integer_ratio()") float_part, exp_int = math.frexp(value) for i in range(300): @@ -327,7 +327,7 @@ def erf(x): """The error function at x.""" - if isnan(x): + if math.isnan(x): return x absx = abs(x) if absx < ERF_SERIES_CUTOFF: @@ -338,7 +338,7 @@ def erfc(x): """The complementary error function at x.""" - if isnan(x): + if math.isnan(x): return x absx = abs(x) if absx < ERF_SERIES_CUTOFF: @@ -410,9 +410,9 @@ def gamma(x): """Compute the gamma function for x.""" - if isnan(x) or (isinf(x) and x > 0.): + if math.isnan(x) or (math.isinf(x) and x > 0.): return x - if isinf(x): + if math.isinf(x): raise ValueError("math domain error") if x == 0.: raise ValueError("math domain error") @@ -424,7 +424,7 @@ absx = abs(x) if absx < 1e-20: r = 1. / x - if isinf(r): + if math.isinf(r): raise OverflowError("math range error") return r if absx > 200.: @@ -458,15 +458,15 @@ sqrtpow = math.pow(y, absx / 2. - .25) r *= sqrtpow r *= sqrtpow - if isinf(r): + if math.isinf(r): raise OverflowError("math range error") return r def lgamma(x): """Compute the natural logarithm of the gamma function for x.""" - if isnan(x): + if math.isnan(x): return x - if isinf(x): + if math.isinf(x): return INFINITY if x == math.floor(x) and x <= 2.: if x <= 0.: @@ -482,7 +482,7 @@ r = (math.log(math.pi) - math.log(abs(_sinpi(absx))) - math.log(absx) - (math.log(_lanczos_sum(absx)) - _lanczos_g + (absx - .5) * (math.log(absx + _lanczos_g - .5) - 1))) - if isinf(r): + if math.isinf(r): raise OverflowError("math domain error") return r 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 @@ -152,10 +152,10 @@ raise ValueError("invalid size value") sign = math.copysign(1.0, x) < 0.0 - if rfloat.isinf(x): + if math.isinf(x): mant = r_ulonglong(0) exp = MAX_EXP - MIN_EXP + 2 - elif rfloat.isnan(x): + elif math.isnan(x): asint = cast(ULONGLONG, float2longlong(x)) sign = asint >> 63 # shift off lower bits, perhaps losing data @@ -217,10 +217,10 @@ raise ValueError("invalid size value") sign = math.copysign(1.0, x) < 0.0 - if rfloat.isinf(x): + if math.isinf(x): mant = r_ulonglong(0) exp = MAX_EXP - MIN_EXP + 2 - elif rfloat.isnan(x): # rfloat.isnan(x): + elif math.isnan(x): asint = cast(ULONGLONG, float2longlong(x)) mant = asint & ((r_ulonglong(1) << 51) - 1) if mant == 0: diff --git a/rpython/rlib/rstruct/test/test_ieee.py b/rpython/rlib/rstruct/test/test_ieee.py --- a/rpython/rlib/rstruct/test/test_ieee.py +++ b/rpython/rlib/rstruct/test/test_ieee.py @@ -1,3 +1,4 @@ +import math import py import sys import random @@ -5,7 +6,7 @@ from rpython.rlib.mutbuffer import MutableStringBuffer from rpython.rlib.rstruct import ieee -from rpython.rlib.rfloat import isnan, NAN, INFINITY +from rpython.rlib.rfloat import NAN, INFINITY from rpython.translator.c.test.test_genc import compile @@ -30,7 +31,6 @@ assert f == ieee.float_unpack(h, 2) def test_halffloat_overunderflow(self): - import math cases = [[670000, float('inf')], [-67000, -float('inf')], [1e-08, 0], [-1e-8, -0.]] for f1, f2 in cases: @@ -176,7 +176,7 @@ # nans are tricky: we can't hope to reproduce the bit # pattern exactly, so check_float will fail for a nan # whose mantissa does not fit into float16's mantissa. - if isnan(x) and (Q & mantissa_mask) >= 1 << 11: + if math.isnan(x) and (Q & mantissa_mask) >= 1 << 11: continue self.check_float(x) @@ -189,7 +189,7 @@ for i in range(20): val_to_preserve = exp | ((maxmant16 - i) << 42) a = ieee.float_unpack(val_to_preserve, 8) - assert isnan(a), 'i %d, maxmant %s' % (i, hex(val_to_preserve)) + assert math.isnan(a), 'i %d, maxmant %s' % (i, hex(val_to_preserve)) b = ieee.float_pack(a, 8) assert b == val_to_preserve, 'i %d, val %s b %s' % (i, hex(val_to_preserve), hex(b)) b = ieee.float_pack(a, 2) @@ -214,14 +214,14 @@ def check_roundtrip(x, size): s = c_pack(x, size) - if not isnan(x): + if not math.isnan(x): # pack uses copysign which is ambiguous for NAN assert s == pack(x, size) assert unpack(s) == x assert c_unpack(s) == x else: - assert isnan(unpack(s)) - assert isnan(c_unpack(s)) + assert math.isnan(unpack(s)) + assert math.isnan(c_unpack(s)) for size in [2, 4, 8]: check_roundtrip(123.4375, size) diff --git a/rpython/rlib/special_value.py b/rpython/rlib/special_value.py --- a/rpython/rlib/special_value.py +++ b/rpython/rlib/special_value.py @@ -1,5 +1,4 @@ import math -from rpython.rlib.rfloat import isnan, isinf # code to deal with special values (infinities, NaNs, ...) # @@ -13,9 +12,9 @@ ST_NAN = 6 # Not a Number def special_type(d): - if isnan(d): + if math.isnan(d): return ST_NAN - elif isinf(d): + elif math.isinf(d): if d > 0.0: return ST_PINF else: diff --git a/rpython/rlib/test/test_longlong2float.py b/rpython/rlib/test/test_longlong2float.py --- a/rpython/rlib/test/test_longlong2float.py +++ b/rpython/rlib/test/test_longlong2float.py @@ -1,3 +1,4 @@ +import math from rpython.translator.c.test.test_genc import compile from rpython.rlib.longlong2float import longlong2float, float2longlong from rpython.rlib.longlong2float import uint2singlefloat, singlefloat2uint @@ -74,7 +75,6 @@ from rpython.rlib.longlong2float import encode_int32_into_longlong_nan from rpython.rlib.longlong2float import decode_int32_from_longlong_nan from rpython.rlib.longlong2float import is_int32_from_longlong_nan - from rpython.rlib.rfloat import isnan assert can_encode_float(f1) assert can_encode_int32(i2) l1 = float2longlong(f1) @@ -82,7 +82,7 @@ assert not is_int32_from_longlong_nan(l1) assert is_int32_from_longlong_nan(l2) f1b = longlong2float(l1) - assert f1b == f1 or (isnan(f1b) and isnan(f1)) + assert f1b == f1 or (math.isnan(f1b) and math.isnan(f1)) assert decode_int32_from_longlong_nan(l2) == i2 return 42 diff --git a/rpython/rlib/test/test_rcomplex.py b/rpython/rlib/test/test_rcomplex.py --- a/rpython/rlib/test/test_rcomplex.py +++ b/rpython/rlib/test/test_rcomplex.py @@ -1,7 +1,6 @@ from __future__ import with_statement import rpython.rlib.rcomplex as c -from rpython.rlib.rfloat import copysign, isnan, isinf import os, sys, math, struct @@ -120,12 +119,12 @@ """ # special values testing - if isnan(a): - if isnan(b): + if math.isnan(a): + if math.isnan(b): return raise AssertionError(msg + '%r should be nan' % (b,)) - if isinf(a): + if math.isinf(a): if a == b: return raise AssertionError(msg + 'finite result where infinity expected: ' @@ -136,8 +135,7 @@ # and b to have opposite signs; in practice these hardly ever # occur). if not a and not b: - # only check it if we are running on top of CPython >= 2.6 - if sys.version_info >= (2, 6) and copysign(1., a) != copysign(1., b): + if math.copysign(1., a) != math.copysign(1., b): raise AssertionError(msg + 'zero has wrong sign: expected %r, ' 'got %r' % (a, b)) diff --git a/rpython/rlib/test/test_rfloat.py b/rpython/rlib/test/test_rfloat.py --- a/rpython/rlib/test/test_rfloat.py +++ b/rpython/rlib/test/test_rfloat.py @@ -1,9 +1,9 @@ -import sys, py +import sys, py, math from rpython.rlib.rfloat import float_as_rbigint_ratio from rpython.rlib.rfloat import round_away from rpython.rlib.rfloat import round_double -from rpython.rlib.rfloat import erf, erfc, gamma, lgamma, isnan +from rpython.rlib.rfloat import erf, erfc, gamma, lgamma from rpython.rlib.rfloat import ulps_check, acc_check from rpython.rlib.rfloat import string_to_float from rpython.rlib.rbigint import rbigint @@ -171,9 +171,9 @@ accuracy_failure = None if isinstance(got, float) and isinstance(expected, float): - if isnan(expected) and isnan(got): + if math.isnan(expected) and math.isnan(got): continue - if not isnan(expected) and not isnan(got): + if not math.isnan(expected) and not math.isnan(got): if fn == 'lgamma': # we use a weaker accuracy test for lgamma; # lgamma only achieves an absolute error of diff --git a/rpython/rtyper/extfuncregistry.py b/rpython/rtyper/extfuncregistry.py --- a/rpython/rtyper/extfuncregistry.py +++ b/rpython/rtyper/extfuncregistry.py @@ -27,12 +27,12 @@ _register = [ # (module, [(method name, arg types, return type), ...], ...) (rfloat, [ - ('isinf', [float], bool), - ('isnan', [float], bool), ('isfinite', [float], bool), ]), (math, [ ('copysign', [float, float], float), + ('isinf', [float], bool), + ('isnan', [float], bool), ('floor', [float], float), ('sqrt', [float], float), ('log', [float], float), diff --git a/rpython/rtyper/lltypesystem/module/ll_math.py b/rpython/rtyper/lltypesystem/module/ll_math.py --- a/rpython/rtyper/lltypesystem/module/ll_math.py +++ b/rpython/rtyper/lltypesystem/module/ll_math.py @@ -5,7 +5,7 @@ from rpython.translator import cdir from rpython.rlib import jit, rposix -from rpython.rlib.rfloat import INFINITY, NAN, isfinite, isinf, isnan +from rpython.rlib.rfloat import INFINITY, NAN, isfinite from rpython.rlib.rposix import UNDERSCORE_ON_WIN32 from rpython.rtyper.lltypesystem import lltype, rffi from rpython.tool.sourcetools import func_with_new_name @@ -147,13 +147,13 @@ Windows, FreeBSD and alpha Tru64 are amongst platforms that don't always follow C99. """ - if isnan(x): + if math.isnan(x): return NAN if not isfinite(y): - if isnan(y): + if math.isnan(y): return NAN - if isinf(x): + if math.isinf(x): if math_copysign(1.0, x) == 1.0: # atan2(+-inf, +inf) == +-pi/4 return math_copysign(0.25 * math.pi, y) @@ -163,7 +163,7 @@ # atan2(+-inf, x) == +-pi/2 for finite x return math_copysign(0.5 * math.pi, y) - if isinf(x) or y == 0.0: + if math.isinf(x) or y == 0.0: if math_copysign(1.0, x) == 1.0: # atan2(+-y, +inf) = atan2(+-0, +x) = +-0. return math_copysign(0.0, y) @@ -211,7 +211,7 @@ else: r = math_ldexp(x, exp) errno = rposix.get_saved_errno() - if isinf(r): + if math.isinf(r): errno = ERANGE if errno: _likely_raise(errno, r) @@ -222,7 +222,7 @@ # some platforms don't do the right thing for NaNs and # infinities, so we take care of special cases directly. if not isfinite(x): - if isnan(x): + if math.isnan(x): return (x, x) else: # isinf(x) return (math_copysign(0.0, x), x) @@ -237,13 +237,13 @@ def ll_math_fmod(x, y): # fmod(x, +/-Inf) returns x for finite x. - if isinf(y) and isfinite(x): + if math.isinf(y) and isfinite(x): return x r = math_fmod(x, y) errno = rposix.get_saved_errno() - if isnan(r): - if isnan(x) or isnan(y): + if math.isnan(r): + if math.isnan(x) or math.isnan(y): errno = 0 else: errno = EDOM @@ -254,16 +254,16 @@ def ll_math_hypot(x, y): # hypot(x, +/-Inf) returns Inf, even if x is a NaN. - if isinf(x): + if math.isinf(x): return math_fabs(x) - if isinf(y): + if math.isinf(y): return math_fabs(y) r = math_hypot(x, y) errno = rposix.get_saved_errno() if not isfinite(r): - if isnan(r): - if isnan(x) or isnan(y): + if math.isnan(r): + if math.isnan(x) or math.isnan(y): errno = 0 else: errno = EDOM @@ -281,18 +281,18 @@ # deal directly with IEEE specials, to cope with problems on various # platforms whose semantics don't exactly match C99 - if isnan(y): + if math.isnan(y): if x == 1.0: return 1.0 # 1**Nan = 1 return y if not isfinite(x): - if isnan(x): + if math.isnan(x): if y == 0.0: return 1.0 # NaN**0 = 1 return x else: # isinf(x) - odd_y = not isinf(y) and math_fmod(math_fabs(y), 2.0) == 1.0 + odd_y = not math.isinf(y) and math_fmod(math_fabs(y), 2.0) == 1.0 if y > 0.0: if odd_y: return x @@ -304,7 +304,7 @@ return math_copysign(0.0, x) return 0.0 - if isinf(y): + if math.isinf(y): if math_fabs(x) == 1.0: return 1.0 elif y > 0.0 and math_fabs(x) > 1.0: @@ -319,7 +319,7 @@ r = math_pow(x, y) errno = rposix.get_saved_errno() if not isfinite(r): - if isnan(r): + if math.isnan(r): # a NaN result should arise only from (-ve)**(finite non-integer) errno = EDOM else: # isinf(r) @@ -363,12 +363,12 @@ return math_log1p(x) def ll_math_sin(x): - if isinf(x): + if math.isinf(x): raise ValueError("math domain error") return math_sin(x) def ll_math_cos(x): - if isinf(x): + if math.isinf(x): raise ValueError("math domain error") return math_cos(x) @@ -389,8 +389,8 @@ # Error checking fun. Copied from CPython 2.6 errno = rposix.get_saved_errno() if not isfinite(r): - if isnan(r): - if isnan(x): + if math.isnan(r): + if math.isnan(x): errno = 0 else: errno = EDOM diff --git a/rpython/rtyper/test/test_rfloat.py b/rpython/rtyper/test/test_rfloat.py --- a/rpython/rtyper/test/test_rfloat.py +++ b/rpython/rtyper/test/test_rfloat.py @@ -162,11 +162,10 @@ assert self.interpret(fn, [0]) == 42.3 def test_isnan(self): - from rpython.rlib import rfloat def fn(x, y): n1 = x * x n2 = y * y * y - return rfloat.isnan(n1 / n2) + return math.isnan(n1 / n2) assert self.interpret(fn, [1e200, 1e200]) # nan assert not self.interpret(fn, [1e200, 1.0]) # +inf assert not self.interpret(fn, [1e200, -1.0]) # -inf @@ -174,11 +173,10 @@ assert not self.interpret(fn, [42.5, -2.3]) # -finite def test_isinf(self): - from rpython.rlib import rfloat def fn(x, y): n1 = x * x n2 = y * y * y - return rfloat.isinf(n1 / n2) + return math.isinf(n1 / n2) assert self.interpret(fn, [1e200, 1.0]) # +inf assert self.interpret(fn, [1e200, -1.0]) # -inf assert not self.interpret(fn, [1e200, 1e200]) # nan diff --git a/rpython/rtyper/tool/test/test_rffi_platform.py b/rpython/rtyper/tool/test/test_rffi_platform.py --- a/rpython/rtyper/tool/test/test_rffi_platform.py +++ b/rpython/rtyper/tool/test/test_rffi_platform.py @@ -1,4 +1,4 @@ -import py, sys, struct +import py, sys, struct, math from rpython.rtyper.tool import rffi_platform from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem import rffi @@ -7,7 +7,6 @@ from rpython.translator.platform import platform from rpython.translator import cdir from rpython.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong -from rpython.rlib.rfloat import isnan def import_ctypes(): try: @@ -126,7 +125,7 @@ value = rffi_platform.getdefineddouble('BLAH', '#define BLAH 1.0e50000') assert value == float("inf") value = rffi_platform.getdefineddouble('BLAH', '#define BLAH (double)0/0') - assert isnan(value) + assert math.isnan(value) def test_defined_constant_string(): value = rffi_platform.getdefinedstring('MCDONC', '') diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py --- a/rpython/translator/c/node.py +++ b/rpython/translator/c/node.py @@ -1,3 +1,4 @@ +import math from rpython.rtyper.lltypesystem.lltype import (Struct, Array, FixedSizeArray, FuncType, typeOf, GcStruct, GcArray, RttiStruct, ContainerType, parentlink, Void, OpaqueType, Float, RuntimeTypeInfo, getRuntimeTypeInfo, Char, @@ -9,7 +10,7 @@ from rpython.translator.c.support import c_char_array_constant, barebonearray from rpython.translator.c.primitive import PrimitiveType, name_signed from rpython.rlib import exports, objectmodel -from rpython.rlib.rfloat import isfinite, isinf +from rpython.rlib.rfloat import isfinite def needs_gcheader(gctransformer, T): @@ -756,7 +757,7 @@ comma = ',' if typeOf(value) == Float and not isfinite(value): db.late_initializations.append(('%s' % access_expr, db.get(value))) - if isinf(value): + if math.isinf(value): name = '-+'[value > 0] + 'inf' else: name = 'NaN' diff --git a/rpython/translator/c/primitive.py b/rpython/translator/c/primitive.py --- a/rpython/translator/c/primitive.py +++ b/rpython/translator/c/primitive.py @@ -3,7 +3,6 @@ from rpython.rlib.objectmodel import Symbolic, ComputedIntSymbolic, CDefinedIntSymbolic from rpython.rlib.rarithmetic import r_longlong, is_emulated_long -from rpython.rlib.rfloat import isinf, isnan from rpython.rtyper.lltypesystem import rffi, llgroup from rpython.rtyper.lltypesystem.llmemory import (Address, AddressOffset, ItemOffset, ArrayItemsOffset, FieldOffset, CompositeOffset, @@ -117,12 +116,12 @@ return math.copysign(1, value) > 0 def name_float(value, db): - if isinf(value): + if math.isinf(value): if value > 0: return '(Py_HUGE_VAL)' else: return '(-Py_HUGE_VAL)' - elif isnan(value): + elif math.isnan(value): if is_positive_nan(value): return '(Py_HUGE_VAL/Py_HUGE_VAL)' else: @@ -135,12 +134,12 @@ def name_singlefloat(value, db): value = float(value) - if isinf(value): + if math.isinf(value): if value > 0: return '((float)Py_HUGE_VAL)' else: return '((float)-Py_HUGE_VAL)' - elif isnan(value): + elif math.isnan(value): # XXX are these expressions ok? if is_positive_nan(value): return '((float)(Py_HUGE_VAL/Py_HUGE_VAL))' diff --git a/rpython/translator/c/test/test_genc.py b/rpython/translator/c/test/test_genc.py --- a/rpython/translator/c/test/test_genc.py +++ b/rpython/translator/c/test/test_genc.py @@ -390,7 +390,7 @@ assert res == 1.5 def test_infinite_float_in_array(): - from rpython.rlib.rfloat import INFINITY, NAN, isnan + from rpython.rlib.rfloat import INFINITY, NAN lst = [INFINITY, -INFINITY, NAN] def fn(i): return lst[i] @@ -400,19 +400,19 @@ res = f1(1) assert res == -INFINITY res = f1(2) - assert isnan(res) + assert math.isnan(res) def test_nan_and_special_values(): - from rpython.rlib.rfloat import isnan, isinf, isfinite + from rpython.rlib.rfloat import isfinite inf = 1e300 * 1e300 - assert isinf(inf) + assert math.isinf(inf) nan = inf/inf - assert isnan(nan) + assert math.isnan(nan) for value, checker in [ - (inf, lambda x: isinf(x) and x > 0.0), - (-inf, lambda x: isinf(x) and x < 0.0), - (nan, isnan), + (inf, lambda x: math.isinf(x) and x > 0.0), + (-inf, lambda x: math.isinf(x) and x < 0.0), + (nan, math.isnan), (42.0, isfinite), (0.0, lambda x: not x and math.copysign(1., x) == 1.), (-0.0, lambda x: not x and math.copysign(1., x) == -1.), _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit