Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Faster versions of some key functions in mpmath.libmp. """ from __future__ import print_function, absolute_import
from .ext_impl cimport * from sage.libs.gmp.all cimport * from sage.rings.integer cimport Integer
from .ext_impl import exp_fixed, cos_sin_fixed, log_int_fixed
# Note: not thread-safe cdef MPF tmp1 cdef MPF tmp2 MPF_init(&tmp1) MPF_init(&tmp2)
def mpf_add(tuple x, tuple y, int prec=0, str rnd='d'): cdef MPopts opts
def mpf_sub(tuple x, tuple y, int prec=0, str rnd='d'): cdef MPopts opts
def mpf_mul(tuple x, tuple y, int prec=0, str rnd='d'): cdef MPopts opts
def mpf_div(tuple x, tuple y, int prec, str rnd='d'): cdef MPopts opts
def mpf_sqrt(tuple x, int prec, str rnd='d'): """ Computes sqrt(x) with mpf value tuples.
EXAMPLES::
sage: from mpmath.libmp import mpf_sqrt, from_float, to_float sage: x = from_float(2) sage: y = mpf_sqrt(x, 53, 'n') sage: to_float(y) 1.4142135623730951
""" cdef MPopts opts
def mpf_log(tuple x, int prec, str rnd='d'): """ Computes log(x) with mpf value tuples.
EXAMPLES::
sage: from mpmath.libmp import mpf_log, from_float, to_float sage: x = from_float(2) sage: y = mpf_log(x, 53, 'n') sage: to_float(y) 0.6931471805599453
""" import mpmath.libmp as libmp raise libmp.ComplexResult("logarithm of a negative number") cdef MPopts opts
def mpf_exp(tuple x, int prec, str rnd='d'): """ Computes exp(x) with mpf value tuples.
EXAMPLES::
sage: from mpmath.libmp import mpf_exp, from_float, to_float sage: x = from_float(2) sage: z = mpf_exp(x, 53, 'n') sage: to_float(z) 7.38905609893065
""" cdef MPopts opts
def mpf_cos(tuple x, int prec, str rnd='d'): """ Computes cos(x) with mpf value tuples.
EXAMPLES::
sage: from mpmath.libmp import mpf_cos, from_float, to_float sage: x = from_float(1) sage: y = mpf_cos(x, 53, 'n') sage: to_float(y) 0.5403023058681398
""" cdef MPopts opts
def mpf_sin(tuple x, int prec, str rnd='d'): """ Computes sin(x) with mpf value tuples.
EXAMPLES::
sage: from mpmath.libmp import mpf_sin, from_float, to_float sage: x = from_float(1) sage: y = mpf_sin(x, 53, 'n') sage: to_float(y) 0.8414709848078965
""" cdef MPopts opts
def mpc_sqrt(tuple z, int prec, str rnd='d'): """ Computes sqrt(z) with mpc value tuples.
EXAMPLES::
sage: from mpmath.libmp import mpc_sqrt, from_float, to_float sage: z = from_float(-2), from_float(0) sage: re, im = mpc_sqrt(z, 53, 'n') sage: to_float(re), to_float(im) (0.0, 1.4142135623730951) """ cdef tuple a, b cdef MPopts opts
def mpc_exp(tuple z, int prec, str rnd='d'): """ Computes exp(z) with mpc value tuples.
EXAMPLES::
sage: from mpmath.libmp import mpc_exp, from_float, to_float sage: z = from_float(0), from_float(1) sage: re, im = mpc_exp(z, 53, 'n') sage: to_float(re), to_float(im) (0.5403023058681398, 0.8414709848078965) """ cdef tuple a, b cdef MPopts opts
def mpf_pow(tuple x, tuple y, int prec, str rnd='d'): """ Computes x ^ y with mpf value tuples.
EXAMPLES::
sage: from mpmath.libmp import mpf_pow, from_float, to_float sage: x = from_float(2) sage: y = from_float(3) sage: z = mpf_pow(x, y, 53, 'n') sage: to_float(z) 8.0
""" cdef MPopts opts import mpmath.libmp as libmp raise libmp.ComplexResult("negative number raised to a fractional power") |