예제 #1
0
 def test_floating(self):
     # Ticket #640, floats from string
     fsingle = np.single('1.234')
     fdouble = np.double('1.234')
     flongdouble = np.longdouble('1.234')
     assert_almost_equal(fsingle, 1.234)
     assert_almost_equal(fdouble, 1.234)
     assert_almost_equal(flongdouble, 1.234)
예제 #2
0
 def test_int_from_huge_longdouble(self):
     # Produce a longdouble that would overflow a double,
     # use exponent that avoids bug in Darwin pow function.
     exp = np.finfo(np.double).maxexp - 1
     huge_ld = 2 * 1234 * np.longdouble(2)**exp
     huge_i = 2 * 1234 * 2**exp
     assert_(huge_ld != np.inf)
     assert_equal(int(huge_ld), huge_i)
예제 #3
0
 def test_int_from_infinite_longdouble___int__(self):
     x = np.longdouble(np.inf)
     assert_raises(OverflowError, x.__int__)
     with suppress_warnings() as sup:
         sup.record(np.ComplexWarning)
         x = np.clongdouble(np.inf)
         assert_raises(OverflowError, x.__int__)
         assert_equal(len(sup.log), 1)
예제 #4
0
 def test_locale_longdouble(self):
     assert_equal(str(np.longdouble('1.2')), str(float(1.2)))
예제 #5
0
def test_repr_roundtrip_bytes():
    o = 1 + LD_INFO.eps
    assert_equal(np.longdouble(repr(o).encode("ascii")), o)
예제 #6
0
def test_bytes():
    np.longdouble(b"1.2")
예제 #7
0
def test_string():
    np.longdouble("1.2")
예제 #8
0
def test_unicode():
    np.longdouble(u"1.2")
예제 #9
0
def test_repr_roundtrip():
    # We will only see eps in repr if within printing precision.
    o = 1 + LD_INFO.eps
    assert_equal(np.longdouble(repr(o)), o, "repr was %s" % repr(o))
예제 #10
0
 def test_fromstring_foreign(self):
     s = "1.234"
     a = np.fromstring(s, dtype=np.longdouble, sep=" ")
     assert_equal(a[0], np.longdouble(s))
예제 #11
0
 def test_repr_roundtrip_foreign(self):
     o = 1.5
     assert_equal(o, np.longdouble(repr(o)))
예제 #12
0
import numpy1 as np
from numpy1.testing import (
    assert_,
    assert_equal,
    assert_raises,
    assert_array_equal,
    temppath,
)
from numpy1.core.tests._locales import CommaDecimalPointLocale

LD_INFO = np.finfo(np.longdouble)
longdouble_longer_than_double = (LD_INFO.eps < np.finfo(np.double).eps)

_o = 1 + LD_INFO.eps
string_to_longdouble_inaccurate = (_o != np.longdouble(repr(_o)))
del _o


def test_scalar_extraction():
    """Confirm that extracting a value doesn't convert to python float"""
    o = 1 + LD_INFO.eps
    a = np.array([o, o, o])
    assert_equal(a[1], o)


# Conversions string -> long double

# 0.1 not exactly representable in base 2 floating point.
repr_precision = len(repr(np.longdouble(0.1)))
예제 #13
0
 def test_int_from_longdouble(self):
     x = np.longdouble(1.5)
     assert_equal(int(x), 1)
     x = np.longdouble(-10.5)
     assert_equal(int(x), -10)