(ctx, x)
Quick logarithmic magnitude estimate of a number. Returns an
        integer or infinity `m` such that `|x| <= 2^m`. It is not
        guaranteed that `m` is an optimal bound, but it will never
        be too large by more than 2 (and probably not more than 1).

        **Examples**

            >>> from sympy.mpmath import *
            >>> mp.pretty = True
            >>> mag(10), mag(10.0), mag(mpf(10)), int(ceil(log(10,2)))
            (4, 4, 4, 4)
            >>> mag(10j), mag(10+10j)
            (4, 5)
            >>> mag(0.01), int(ceil(log(0.01,2)))
            (-6, -6)
            >>> mag(0), mag(inf), mag(-inf), mag(nan)
            (-inf, +inf, +inf, nan)
Quick logarithmic magnitude estimate of a number. Returns an
        integer or infinity `m` such that `|x| <= 2^m`. It is not
        guaranteed that `m` is an optimal bound, but it will never
        be too large by more than 2 (and probably not more than 1).
Quick logarithmic magnitude estimate of a number . Returns an integer or infinity m such that |x| < = 2^m . It is not guaranteed that m is an optimal bound but it will never be too large by more than 2 ( and probably not more than 1 ) .
def mag(ctx, x):
        """
        Quick logarithmic magnitude estimate of a number. Returns an
        integer or infinity `m` such that `|x| <= 2^m`. It is not
        guaranteed that `m` is an optimal bound, but it will never
        be too large by more than 2 (and probably not more than 1).

        **Examples**

            >>> from sympy.mpmath import *
            >>> mp.pretty = True
            >>> mag(10), mag(10.0), mag(mpf(10)), int(ceil(log(10,2)))
            (4, 4, 4, 4)
            >>> mag(10j), mag(10+10j)
            (4, 5)
            >>> mag(0.01), int(ceil(log(0.01,2)))
            (-6, -6)
            >>> mag(0), mag(inf), mag(-inf), mag(nan)
            (-inf, +inf, +inf, nan)

        """
        if hasattr(x, "_mpf_"):
            return ctx._mpf_mag(x._mpf_)
        elif hasattr(x, "_mpc_"):
            r, i = x._mpc_
            if r == fzero:
                return ctx._mpf_mag(i)
            if i == fzero:
                return ctx._mpf_mag(r)
            return 1+max(ctx._mpf_mag(r), ctx._mpf_mag(i))
        elif isinstance(x, int_types):
            if x:
                return bitcount(abs(x))
            return ctx.ninf
        elif isinstance(x, rational.mpq):
            p, q = x._mpq_
            if p:
                return 1 + bitcount(abs(p)) - bitcount(q)
            return ctx.ninf
        else:
            x = ctx.convert(x)
            if hasattr(x, "_mpf_") or hasattr(x, "_mpc_"):
                return ctx.mag(x)
            else:
                raise TypeError("requires an mpf/mpc")
def mag ( ctx , x ) : if hasattr ( x , "_mpf_" ) : return ctx . _mpf_mag ( x . _mpf_ ) elif hasattr ( x , "_mpc_" ) : r , i = x . _mpc_ if r == fzero : return ctx . _mpf_mag ( i ) if i == fzero : return ctx . _mpf_mag ( r ) return 1 + max ( ctx . _mpf_mag ( r ) , ctx . _mpf_mag ( i ) ) elif isinstance ( x , int_types ) : if x : return bitcount ( abs ( x ) ) return ctx . ninf elif isinstance ( x , rational . mpq ) : p , q = x . _mpq_ if p : return 1 + bitcount ( abs ( p ) ) - bitcount ( q ) return ctx . ninf else : x = ctx . convert ( x ) if hasattr ( x , "_mpf_" ) or hasattr ( x , "_mpc_" ) : return ctx . mag ( x ) else : raise TypeError ( "requires an mpf/mpc" )