Example #1
0
    def ldexp(ctx, x, n):
        r"""
        Computes `x 2^n` efficiently. No rounding is performed.
        The argument `x` must be a real floating-point number (or
        possible to convert into one) and `n` must be a Python ``int``.

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> ldexp(1, 10)
            mpf('1024.0')
            >>> ldexp(1, -3)
            mpf('0.125')

        """
        x = ctx.convert(x)
        return ctx.make_mpf(libmp.mpf_shift(x._mpf_, n))
Example #2
0
    def ldexp(ctx, x, n):
        r"""
        Computes `x 2^n` efficiently. No rounding is performed.
        The argument `x` must be a real floating-point number (or
        possible to convert into one) and `n` must be a Python ``int``.

            >>> from mpmath import *
            >>> mp.dps = 15; mp.pretty = False
            >>> ldexp(1, 10)
            mpf('1024.0')
            >>> ldexp(1, -3)
            mpf('0.125')

        """
        x = ctx.convert(x)
        return ctx.make_mpf(libmp.mpf_shift(x._mpf_, n))
Example #3
0
 def ldexp(ctx, x, n):
     a, b = ctx.convert(x)._mpi_
     a = libmp.mpf_shift(a, n)
     b = libmp.mpf_shift(b, n)
     return ctx.make_mpf((a,b))
Example #4
0
 def ldexp(ctx, x, n):
     a, b = ctx.convert(x)._mpi_
     a = libmp.mpf_shift(a, n)
     b = libmp.mpf_shift(b, n)
     return ctx.make_mpf((a, b))