@Override public PyLong read(Kryo kryo, Input input, Class<PyLong> type) { int length = input.readShort(); return new PyLong(new BigInteger(input.readBytes(length))); } }
@Override public void write(Kryo kryo, Output output, PyLong object) { byte[] data = object.getValue().toByteArray(); output.writeShort(data.length); output.writeBytes(data); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rmul___doc) final PyObject long___rmul__(PyObject left) { if (left instanceof PySequence) { return ((PySequence)left).repeat(coerceInt(this)); } if (!canCoerce(left)) { return null; } return Py.newLong(coerce(left).multiply(getValue())); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rtruediv___doc) final PyObject long___rtruediv__(PyObject left) { if (!canCoerce(left)) { return null; } return true_divide(coerce(left), this.getValue()); }
@ExposedMethod(type = MethodType.BINARY, defaults = {"null"}, doc = BuiltinDocs.long___pow___doc) final PyObject long___pow__(PyObject right, PyObject modulo) { if (!canCoerce(right)) { return null; } modulo = (modulo == Py.None) ? null : modulo; if (modulo != null && !canCoerce(modulo)) { return null; } return _pow(getValue(), coerce(right), modulo, this, right); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rshift___doc) final PyObject long___rshift__(PyObject right) { if (!canCoerce(right)) { return null; } int rightv = coerceInt(right); if (rightv < 0) { throw Py.ValueError("negative shift count"); } return Py.newLong(getValue().shiftRight(rightv)); }
@ExposedMethod(doc = BuiltinDocs.long___abs___doc) final PyObject long___abs__() { if (getValue().signum() == -1) { return long___neg__(); } return long___long__(); }
public double scaledDoubleValue(int[] exp) { return scaledDoubleValue(getValue(), exp); }
@ExposedMethod(doc = BuiltinDocs.long___int___doc) final PyObject long___int__() { if (getValue().compareTo(PyInteger.MAX_INT) <= 0 && getValue().compareTo(PyInteger.MIN_INT) >= 0) { return Py.newInteger(getValue().intValue()); } return long___long__(); }
/** * Wimpy, slow approach to new calls for subtypes of long. * * First creates a regular long from whatever arguments we got, then allocates a subtype * instance and initializes it from the regular long. The regular long is then thrown away. */ private static PyObject longSubtypeNew(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { PyObject tmp = long___new__(new_, init, TYPE, args, keywords); if (tmp instanceof PyInteger) { int intValue = ((PyInteger)tmp).getValue(); return new PyLongDerived(subtype, BigInteger.valueOf(intValue)); } else { return new PyLongDerived(subtype, ((PyLong)tmp).getValue()); } }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___radd___doc) final PyObject long___radd__(PyObject left) { return __add__(left); }
public PyObject __and__(PyObject other) { PyType self_type=getType(); PyObject impl=self_type.lookup("__and__"); if (impl!=null) { PyObject res=impl.__get__(this,self_type).__call__(other); if (res==Py.NotImplemented) return null; return res; } return super.__and__(other); }
public PyObject __abs__() { PyType self_type=getType(); PyObject impl=self_type.lookup("__abs__"); if (impl!=null) return impl.__get__(this,self_type).__call__(); return super.__abs__(); }