@Override public void write(Kryo kryo, Output output, PyFloat object) { output.writeDouble(object.getValue()); }
@Override public PyFloat read(Kryo kryo, Input input, Class<PyFloat> type) { return new PyFloat(input.readDouble()); } }
} else if (other instanceof PyFloat) { PyFloat f = ((PyFloat)other); equal = (this.imag == 0.0 && this.real == f.getValue()); } else if (other instanceof PyInteger || other instanceof PyLong) { if (this.imag == 0.0) { } else { PyFloat f = new PyFloat(r); equal = (f.float___cmp__(other) == 0);
@ExposedMethod(doc = BuiltinDocs.float_hex_doc) public PyObject float_hex() { return new PyString(pyHexString(getValue())); }
@ExposedMethod(type = MethodType.CMP) final int float___cmp__(PyObject other) { double i = getValue(); double j; j = ((PyFloat)other).getValue(); } else if (!isFinite()) { j = ((PyInteger)other).getValue(); } else if (other instanceof PyLong) { BigDecimal v = new BigDecimal(getValue()); BigDecimal w = new BigDecimal(((PyLong)other).getValue()); return v.compareTo(w);
/** * test formatting of extreme values */ public void testInfinityAndNaN_repr() { PyFloat fNan = new PyFloat(Double.NaN); PyFloat fInf = new PyFloat(Double.POSITIVE_INFINITY); PyFloat fNinf = new PyFloat(Double.NEGATIVE_INFINITY); assertEquals("nan", String.valueOf(fNan.__repr__())); assertEquals("inf", String.valueOf(fInf.__repr__())); assertEquals("-inf", String.valueOf(fNinf.__repr__())); } }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.float___radd___doc) final PyObject float___radd__(PyObject left) { return __add__(left); }
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__(); }
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); }
@ExposedMethod(type = MethodType.BINARY, defaults = "null", // doc = BuiltinDocs.float___pow___doc) final PyObject float___pow__(PyObject right, PyObject modulo) { if (!canCoerce(right)) { return null; } modulo = (modulo == Py.None) ? null : modulo; if (modulo != null) { throw Py.TypeError("pow() 3rd argument not allowed unless all arguments are integers"); } else { return _pow(getValue(), coerce(right)); } }
@ExposedMethod(doc = BuiltinDocs.float___hash___doc) final int float___hash__() { double value = getValue(); if (Double.isInfinite(value)) { return value < 0 ? -271828 : 314159; } else if (Double.isNaN(value)) { return 0; } double intPart = Math.floor(value); double fractPart = value - intPart; if (fractPart == 0) { if (intPart <= Integer.MAX_VALUE && intPart >= Integer.MIN_VALUE) { return (int)value; } else { return __long__().hashCode(); } } else { long v = Double.doubleToLongBits(getValue()); return (int)v ^ (int)(v >> 32); } }
public PyObject __add__(PyObject other) { PyType self_type=getType(); PyObject impl=self_type.lookup("__add__"); if (impl!=null) { PyObject res=impl.__get__(this,self_type).__call__(other); if (res==Py.NotImplemented) return null; return res; } return super.__add__(other); }