Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(20)  |  Call(18)  |  Derive(0)  |  Import(2)
Create a raw mpf from a Python float, rounding if necessary.
If prec >= 53, the result is guaranteed to represent exactly the
same number as the input. If prec is not specified, use prec=53.

        def from_float(x, prec=53, rnd=round_fast):
    """Create a raw mpf from a Python float, rounding if necessary.
    If prec >= 53, the result is guaranteed to represent exactly the
    same number as the input. If prec is not specified, use prec=53."""
    # frexp only raises an exception for nan on some platforms
    if x != x:
        return fnan
    # in Python2.5 math.frexp gives an exception for float infinity
    # in Python2.6 it returns (float infinity, 0)
    try:
        m, e = math.frexp(x)
    except:
        if x == math_float_inf: return finf
        if x == -math_float_inf: return fninf
        return fnan
    if x == math_float_inf: return finf
    if x == -math_float_inf: return fninf
    return from_man_exp(int(m*(1<<53)), e-53, prec, rnd)
        


src/s/y/sympy-HEAD/sympy/core/tests/test_evalf.py   sympy(Download)
from sympy.mpmath import inf, ninf, nan
from sympy.abc import n, x, y
from sympy.mpmath.libmp.libmpf import from_float
from sympy.utilities.pytest import raises, XFAIL
 
def test_evalf_helpers():
    assert complex_accuracy((from_float(2.0), None, 35, None)) == 35
    assert complex_accuracy((from_float(2.0), from_float(10.0), 35, 100)) == 37
    assert complex_accuracy(
        (from_float(2.0), from_float(1000.0), 35, 100)) == 43

src/s/y/sympy-polys-HEAD/sympy/core/tests/test_evalf.py   sympy-polys(Download)
    factorial, binomial, Sum, zeta, Catalan, Pow, GoldenRatio, sympify, sstr
 
from sympy.mpmath.libmp.libmpf import from_float
 
from sympy.utilities.pytest import raises
def test_evalf_helpers():
    assert complex_accuracy((from_float(2.0),None,35,None)) == 35
    assert complex_accuracy((from_float(2.0),from_float(10.0),35,100)) == 37
    assert complex_accuracy((from_float(2.0),from_float(1000.0),35,100)) == 43
    assert complex_accuracy((from_float(2.0),from_float(10.0),100,35)) == 35