本文整理汇总了Python中pypy.rlib.rarithmetic.r_longlong函数的典型用法代码示例。如果您正苦于以下问题:Python r_longlong函数的具体用法?Python r_longlong怎么用?Python r_longlong使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了r_longlong函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: g
def g(n, m, o):
# This function should be completely marked as residual by
# codewriter.py on 32-bit platforms. On 64-bit platforms,
# this function should be JITted and the test should pass too.
n = r_longlong(n)
m = r_longlong(m)
return intmask((n*m) // o)
示例2: test_cast_float_to_ulonglong
def test_cast_float_to_ulonglong():
f = 12350000000000000000.0
py.test.raises(OverflowError, r_longlong, f)
r_longlong(f / 2) # does not raise OverflowError
#
x = llop.cast_float_to_ulonglong(lltype.UnsignedLongLong, f)
assert x == r_ulonglong(f)
示例3: f
def f(n1, n2):
# n == -30000000000000
n = (r_longlong(n1) << 32) | r_longlong(n2)
compare(n < n, 0, 0)
compare(n <= n, 0, 1)
compare(n == n, 0, 1)
compare(n != n, 0, 0)
compare(n > n, 0, 0)
compare(n >= n, 0, 1)
o = n + 2000000000
compare(o, -6985, -1948404736)
compare(n < o, 0, 1) # low word differs
compare(n <= o, 0, 1)
compare(o < n, 0, 0)
compare(o <= n, 0, 0)
compare(n > o, 0, 0)
compare(n >= o, 0, 0)
compare(o > n, 0, 1)
compare(o >= n, 0, 1)
compare(n == o, 0, 0)
compare(n != o, 0, 1)
p = -o
compare(n < p, 0, 1) # high word differs
compare(n <= p, 0, 1)
compare(p < n, 0, 0)
compare(p <= n, 0, 0)
compare(n > p, 0, 0)
compare(n >= p, 0, 0)
compare(p > n, 0, 1)
compare(p >= n, 0, 1)
compare(n == p, 0, 0)
compare(n != p, 0, 1)
return 1
示例4: min_max_acc_method
def min_max_acc_method(size, signed):
if signed:
min = -(2 ** (8*size-1))
max = (2 ** (8*size-1)) - 1
if size <= native_int_size:
accept_method = 'accept_int_arg'
min = int(min)
max = int(max)
else:
accept_method = 'accept_longlong_arg'
min = r_longlong(min)
max = r_longlong(max)
else:
min = 0
max = (2 ** (8*size)) - 1
if size < native_int_size:
accept_method = 'accept_int_arg'
elif size == native_int_size:
accept_method = 'accept_uint_arg'
min = r_uint(min)
max = r_uint(max)
else:
accept_method = 'accept_ulonglong_arg'
min = r_ulonglong(min)
max = r_ulonglong(max)
return min, max, accept_method
示例5: test_slonglong_args
def test_slonglong_args(self):
"""
long long sum_xy_longlong(long long x, long long y)
{
return x+y;
}
"""
maxint32 = 2147483647 # we cannot really go above maxint on 64 bits
# (and we would not test anything, as there long
# is the same as long long)
libfoo = self.get_libfoo()
func = (libfoo, 'sum_xy_longlong', [types.slonglong, types.slonglong],
types.slonglong)
if IS_32_BIT:
x = r_longlong(maxint32+1)
y = r_longlong(maxint32+2)
zero = longlong2float(r_longlong(0))
else:
x = maxint32+1
y = maxint32+2
zero = 0
res = self.call(func, [x, y], rffi.LONGLONG, init_result=zero)
if IS_32_BIT:
# obscure, on 32bit it's really a long long, so it returns a
# DOUBLE because of the JIT hack
res = float2longlong(res)
expected = maxint32*2 + 3
assert res == expected
示例6: _impl_pow
def _impl_pow(space, iv, w_int2, iz=r_longlong(0)):
iw = w_int2.intval
if iw < 0:
if iz != 0:
raise OperationError(space.w_TypeError,
space.wrap("pow() 2nd argument "
"cannot be negative when 3rd argument specified"))
## bounce it, since it always returns float
raise FailedToImplementArgs(space.w_ValueError,
space.wrap("integer exponentiation"))
temp = iv
ix = r_longlong(1)
try:
while iw > 0:
if iw & 1:
ix = llong_mul_ovf(ix, temp)
iw >>= 1 #/* Shift exponent down by 1 bit */
if iw==0:
break
temp = llong_mul_ovf(temp, temp) #/* Square the value of temp */
if iz:
#/* If we did a multiplication, perform a modulo */
ix = ix % iz
temp = temp % iz
if iz:
ix = ix % iz
except OverflowError:
raise FailedToImplementArgs(space.w_OverflowError,
space.wrap("integer exponentiation"))
return W_SmallLongObject(ix)
示例7: f
def f(x):
if x == r_longlong(3):
return 9
elif x == r_longlong(9):
return 27
elif x == r_longlong(27):
return 3
return 0
示例8: g
def g(n, m, o, p):
# On 64-bit platforms, long longs == longs. On 32-bit platforms,
# this function should be either completely marked as residual
# (with supports_longlong==False), or be compiled as a
# sequence of residual calls (with long long arguments).
n = r_longlong(n)
m = r_longlong(m)
return intmask((n*m + p) // o)
示例9: test_float_conversion_implicit
def test_float_conversion_implicit(self):
def f(ii):
return 1.0 + ii
res = self.interpret(f, [r_longlong(100000000)])
assert type(res) is float
assert res == 100000001.
res = self.interpret(f, [r_longlong(1234567890123456789)])
assert type(res) is float
assert self.float_eq(res, 1.2345678901234568e+18)
示例10: pack_float
def pack_float(result, number, size, bigendian):
"""Append to 'result' the 'size' characters of the 32-bit or 64-bit
IEEE representation of the number.
"""
if size == 4:
bias = 127
exp = 8
prec = 23
else:
bias = 1023
exp = 11
prec = 52
if isnan(number):
sign = 0x80
man, e = 1.5, bias + 1
else:
if number < 0:
sign = 0x80
number *= -1
elif number == 0.0:
for i in range(size):
result.append('\x00')
return
else:
sign = 0x00
if isinf(number):
man, e = 1.0, bias + 1
else:
man, e = math.frexp(number)
if 0.5 <= man and man < 1.0:
man *= 2
e -= 1
man -= 1
e += bias
power_of_two = r_longlong(1) << prec
mantissa = r_longlong(power_of_two * man + 0.5)
if mantissa >> prec :
mantissa = 0
e += 1
for i in range(size-2):
result.append(chr(mantissa & 0xff))
mantissa >>= 8
x = (mantissa & ((1<<(15-exp))-1)) | ((e & ((1<<(exp-7))-1))<<(15-exp))
result.append(chr(x))
x = sign | e >> (exp - 7)
result.append(chr(x))
if bigendian:
first = len(result) - size
last = len(result) - 1
for i in range(size // 2):
(result[first + i], result[last - i]) = (
result[last - i], result[first + i])
示例11: test_args_from_int
def test_args_from_int(self):
BASE = 1 << SHIFT
MAX = int(BASE-1)
assert rbigint.fromrarith_int(0).eq(bigint([0], 0))
assert rbigint.fromrarith_int(17).eq(bigint([17], 1))
assert rbigint.fromrarith_int(MAX).eq(bigint([MAX], 1))
assert rbigint.fromrarith_int(r_longlong(BASE)).eq(bigint([0, 1], 1))
assert rbigint.fromrarith_int(r_longlong(BASE**2)).eq(
bigint([0, 0, 1], 1))
assert rbigint.fromrarith_int(-17).eq(bigint([17], -1))
assert rbigint.fromrarith_int(-MAX).eq(bigint([MAX], -1))
assert rbigint.fromrarith_int(-MAX-1).eq(bigint([0, 1], -1))
assert rbigint.fromrarith_int(r_longlong(-(BASE**2))).eq(
bigint([0, 0, 1], -1))
示例12: dump_int
def dump_int(buf, x):
# only use TYPE_INT on 32-bit platforms
if LONG_BIT > 32:
dump_longlong(buf, r_longlong(x))
else:
buf.append(TYPE_INT)
w_long(buf, x)
示例13: test_wrap
def test_wrap():
def _is(box1, box2):
return box1.__class__ == box2.__class__ and box1.value == box2.value
p = lltype.malloc(lltype.GcStruct("S"))
po = lltype.cast_opaque_ptr(llmemory.GCREF, p)
assert _is(wrap(None, 42), BoxInt(42))
assert _is(wrap(None, 42.5), boxfloat(42.5))
assert _is(wrap(None, p), BoxPtr(po))
assert _is(wrap(None, 42, in_const_box=True), ConstInt(42))
assert _is(wrap(None, 42.5, in_const_box=True), constfloat(42.5))
assert _is(wrap(None, p, in_const_box=True), ConstPtr(po))
if longlong.supports_longlong:
import sys
from pypy.rlib.rarithmetic import r_longlong, r_ulonglong
value = r_longlong(-sys.maxint * 17)
assert _is(wrap(None, value), BoxFloat(value))
assert _is(wrap(None, value, in_const_box=True), ConstFloat(value))
value_unsigned = r_ulonglong(-sys.maxint * 17)
assert _is(wrap(None, value_unsigned), BoxFloat(value))
sfval = r_singlefloat(42.5)
ival = longlong.singlefloat2int(sfval)
assert _is(wrap(None, sfval), BoxInt(ival))
assert _is(wrap(None, sfval, in_const_box=True), ConstInt(ival))
示例14: test_contains_unsupported_variable_type
def test_contains_unsupported_variable_type():
def f(x):
return x
graph = support.getgraph(f, [5])
for sf in [False, True]:
for sll in [False, True]:
for ssf in [False, True]:
assert not contains_unsupported_variable_type(graph, sf,
sll, ssf)
#
graph = support.getgraph(f, [5.5])
for sf in [False, True]:
for sll in [False, True]:
for ssf in [False, True]:
res = contains_unsupported_variable_type(graph, sf, sll, ssf)
assert res is not sf
#
graph = support.getgraph(f, [r_singlefloat(5.5)])
for sf in [False, True]:
for sll in [False, True]:
for ssf in [False, True]:
res = contains_unsupported_variable_type(graph, sf, sll, ssf)
assert res == (not ssf)
#
graph = support.getgraph(f, [r_longlong(5)])
for sf in [False, True]:
for sll in [False, True]:
for ssf in [False, True]:
res = contains_unsupported_variable_type(graph, sf, sll, ssf)
assert res == (sys.maxint == 2147483647 and not sll)
示例15: test_wraplonglongs
def test_wraplonglongs():
space = CPyObjSpace()
w = space.wrap
w_res = space.add(w(r_longlong(1)), w(r_ulonglong(1)))
assert space.eq_w(w_res, w(2))
res = space.int_w(w_res)
assert res == 2