
    [hݯ              
          S r SrSSKrSSKJr  SSKrSqSSKJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJr  SSKJrJrJrJrJrJrJrJrJrJrJrJ r J!r!  \S:X  a  S	 r"OS
 r"S r# " S S\$5      r% \&  \&" S5      r(\&" S5      r)\&" S5      r*\&" S5      r+\&" S5      r,\,r-S r.S r/S r0S\	SS4r1S\	SS4r2S\
SS4r3S\
SS4r4S\
SS4r5S\SS4r6S\
SS4r7S\	SS4r8S\	SS4r9S\	SS4r:Sr;S r< " S  S!5      r=S/\>" SS"5       V s/ s H  n \
U S-
  -  S-
  PM     sn -   r?\=" 5       \?/r@\)S#\*S$\,S%\+S&0rAS' rBS( rC \D\E4rFS) rGS* rH\S+:X  a$  S,\I" \5      ;   a  \R                  rB\R                  rC\S:X  a  \R                  =rBrC\(       a  \GrK\HrLO\BrK\CrLS\-4S- jrM\N" S. \>" S/S05       5       5      rO\S+:X  a  S1\I" \5      ;   a  \R                  rM\S:X  a  \R                  rMS\-4S2 jrQS3 rRShS4 jrSS5 rTS\-4S6 jrUS\-4S7 jrVS\-4S8 jrWS\-4S9 jrXS:\-4S; jrYS<\-4S= jrZS\-4S> jr[S?\-4S@ jr\\-4SA jr]SB r^SC r_SD r`SE raSF rbSG rcSH rdSI reSJ rfSK rgSL rhS\-4SM jriS\-4SN jrjS\-4SO jrkSP rlS\-S4SQ jrmS\-4SR jrnS\-S?4SS jroS\-4ST jrp\-4SU jrqS\-4SV jrr\-4SW jrs\S+:X  a  \prt\qruO\rrt\sruSX rvSY rw\-4SZ jrx\-4S[ jry\-4S\ jrz\,\+\+\,\)\*\*\)\(\(0r{\,\,\+\+\)\*\*\)\(\(0r|\-4S] jr}S^ r~S_ r  SiS` jrSjSa jr\9\9\:\8Sb.r\-4Sc jrSd rSe r\-4Sf jr\-4Sg jr\S:X  aK   SSKJs  Js  Jr  \R                  rm\R                  rn\R                  rt\R                  rx\GR                  rgg! \' a    S r& GNf = fs  sn f ! \' a    \D4rF GNDf = f! \ a     gf = f)kzH
Low-level functions for arbitrary-precision floating-point arithmetic.
	plaintext    N)bisect   )MPZMPZ_TYPEMPZ_ZEROMPZ_ONEMPZ_TWOMPZ_FIVEBACKENDSTRICTHASH_MODULUS	HASH_BITSgmpysage
sage_utils)giant_steps
trailtablebctablelshiftrshiftbitcounttrailing
sqrt_fixednumeralisqrt
isqrt_fastsqrtrembin_to_radixr   c                 (    U u  pp4U[        U5      X44$ Nhexxsignmanexpbcs        K/var/www/auris/envauris/lib/python3.13/site-packages/mpmath/libmp/libmpf.pyto_pickabler+      s    3SXs&&    c                 .    U u  pp4U[        U5      SS  X44$ )N   r"   r$   s        r*   r+   r+   #   s#    3SXab\3**r,   c                 *    U u  pp4U[        US5      X44$ )N   )r   r$   s        r*   from_pickabler1   '   s    Ds#c2,((r,   c                       \ rS rSrSrg)ComplexResult+    N)__name__
__module____qualname____firstlineno____static_attributes__r5   r,   r*   r3   r3   +   s    r,   r3   c                     U $ r!   r5   )r%   s    r*   <lambda>r<   1   s    qr,   nfcudc           
      \    [        S[        [        [        U 5      S-  5      S-
  5      5      $ )zVReturn number of accurate decimals that can be represented
with a precision of n bits.r   ry	O
@maxintroundr=   s    r*   prec_to_dpsrI   ;   s*     q#eCF#556q89::r,   c           
      \    [        S[        [        [        U 5      S-   S-  5      5      5      $ )zFReturn the number of bits required to represent n decimals
accurately.r   rC   rD   rH   s    r*   dps_to_precrK   @   s)     q#eSVAX'99:;<<r,   c                 0    [        U 5      nUS:X  a  gUS-   $ )zReturn the number of decimal digits required to represent
a number with n-bit precision so that it can be uniquely
reconstructed from the representation.         )rI   )r=   dpss     r*   repr_dpsrQ   E   s      a.C
by7Nr,   rO   ii8ig      c                 h   U[         :X  aS  U S:  a?  XS-
  -	  nUS-  (       a)  US-  (       d  U [        US:     U   -  (       a  US-	  S-   $ US-	  $ [        U * X5      * $ U[        :X  a  X-	  $ U[        :X  a  U * U-	  * $ U[
        :X  a  U S:  a  X-	  $ U * U-	  * $ U[        :X  a  U S:  a  U * U-	  * $ X-	  $ g )Nr   r   r.   ,  )round_nearesth_mask	round_intround_floorround_ceiling
round_downround_up)r%   r=   rndts       r*   rY   rY   k   s    
m6c
A1u1q5a&3-*:&:1ax!tqb!)))
kv
m"|
j66M"|
h6bQY<v r,   c                       \ rS rSrS rSrg)
h_mask_big   c                      [         US-
  -  S-
  $ )Nr   )r	   )selfr=   s     r*   __getitem__h_mask_big.__getitem__   s    !A#!!r,   r5   N)r6   r7   r8   r9   re   r:   r5   r,   r*   ra   ra      s    "r,   ra   rV   )r   r   )r   r   )r   r   )r   r   c                    U(       d  [         $ X4-
  nUS:  an  U[        :X  aA  XS-
  -	  nUS-  (       a*  US-  (       d  U[        US:     U   -  (       a	  US-	  S-   nO#US-	  nO[        U   U    (       a  X-  nOU* U-	  * nX&-  nUnUS-  (       db  [        [        US-  5         nU(       d:  US-  (       d  US-  nUS-  nUS-  nUS-  (       d  M  [        [        US-  5         nX-  nX'-  nX7-  nUS:X  a  SnXX#4$ )ad  
Create a raw mpf tuple with value (-1)**sign * man * 2**exp and
normalized mantissa. The mantissa is rounded in the specified
direction if its size exceeds the precision. Trailing zero bits
are also stripped from the mantissa to ensure that the
representation is canonical.

Conditions on the input:
* The input must represent a regular (finite) number
* The sign bit must be 0 or 1
* The mantissa must be positive
* The exponent must be an integer
* The bitcount must be exact

If these conditions are not met, use from_man_exp, mpf_pos, or any
of the conversion functions to create normalized raw mpf tuples.
r   r   r.   rV         fzerorW   rX   shifts_downr   rF   r&   r'   r(   r)   precr^   r=   r_   s           r*   
_normalizero      s   $ 
	A1u-!A1u1q5cF1S5M!,<&<!tQhdd#ICTAI,C7s39~&Ci	qa Cii 3sSy>*A	

 axcr,   c                    U(       d  [         $ X4::  a  XX#4$ X4-
  nU[        :X  aA  XS-
  -	  nUS-  (       a*  US-  (       d  U[        US:     U   -  (       a	  US-	  S-   nO#US-	  nO[        U   U    (       a  X-  nOU* U-	  * nX&-  nUnUS-  (       db  [        [        US-  5         nU(       d:  US-  (       d  US-  nUS-  nUS-  nUS-  (       d  M  [        [        US-  5         nX-  nX'-  nX7-  nUS:X  a  SnXX#4$ )zHsame as normalize, but with the added condition that
man is odd or zero
r   r.   rV   rh   ri   rj   rm   s           r*   _normalize1rq      s%    	z#!!
	A
maCLq5q1u#qua(8"8a4(CQ$C	S	$			lHC	B7s39~&Ci	qa Cii 3sSy>*A	

 axcr,   c                     [        U5      [        :X  d   e[        U5      [        ;   d   e[        U5      [        ;   d   eU[        U5      :X  d   e[	        XX#XE5      $ )sAdditional checks on the components of an mpf. Enable tests by setting
the environment variable MPMATH_STRICT to Y.)typer   
_exp_typesr   ro   r&   r'   r(   r)   rn   r^   s         r*   strict_normalizerw      s[     9   8z!!!9
"""#d$44r,   c                     [        U5      [        :X  d   e[        U5      [        ;   d   e[        U5      [        ;   d   eU[        U5      :X  d   eU(       a  US-  (       d   e[	        XX#XE5      $ )rs   r   )rt   r   ru   r   rq   rv   s         r*   strict_normalize1ry     sj     9   8z!!!9
"""#q!!t#455r,   r   _mpmath_normalizec                    [        U 5      n SnU S:  a  SnU * n U S:  a  [        [        U 5         nO[        U 5      nU(       d  U (       d  [        $ U S-  (       dz  U S-  (       a  X@S-	  US-   US-
  4$ [
        [        U S-  5         nU(       d:  U S-  (       d  U S-  n US-  nUS-  nU S-  (       d  M  [
        [        U S-  5         nX-  n X-  nXV-  nX@X4$ [        X@XX#5      $ )z~Create raw mpf from (man, exp) pair. The mantissa may be signed.
If no precision is specified, the mantissa is stored exactly.r   r      r.   rh   ri   )r   r   rF   r   rk   r   	normalize)r'   r(   rn   r^   r&   r)   r_   s          r*   from_man_expr~   #  s     c(CD
Qwd
TzSXc]LQwQwQhaa883sSy>*A)AIC1HC!GB )) s39~.ICHCGB3##T33r,   c              #   <   #    U  H  o[        US 5      4v   M     g7f)r   N)r~   ).0r=   s     r*   	<genexpr>r   B  s     B/Q\!Q'(/s   ii  _mpmath_createc                 P    U(       d  U [         ;   a	  [         U    $ [        U SX5      $ )z_Create a raw mpf from an integer. If no precision is specified,
the mantissa is stored exactly.r   )	int_cacher~   )r=   rn   r^   s      r*   from_intr   J  s'     	>Q<1d((r,   c                 J    U u  pp4U(       d  U(       a  [        SU-  5      eX#4$ )z:Return (man, exp) of a raw mpf. Raise an error if inf/nan.z*mantissa and exponent are undefined for %s
ValueErrorsr&   r'   r(   r)   s        r*   
to_man_expr   R  s)    DsSEKLL8Or,   c                     U u  p#pEU(       d  U(       a  [        S5      eUS:  a  U(       a  U* U-  $ X4-  $ U(       d  U(       a  X4* -	  * $ X4* -	  $ U(       a  [        U* U* U5      $ [        X4* U5      $ )zConvert a raw mpf to the nearest int. Rounding is done down by
default (same as int(float) in Python), but can be changed. If the
input is inf/nan, an exception is raised.z cannot convert inf or nan to intr   )r   rY   )r   r^   r&   r'   r(   r)   s         r*   to_intr   Y  s     DsS;<<
axDS= zT]##4= #tS))dC((r,   c                 b   U u  p#pEU(       d	  U(       a  U $ US:  a  U $ XE-   nUS:  as  U[         :X  a  U(       a  [        $ [        $ U[        :X  a  U(       a  [        $ [        $ U[
        :X  a)  US:  d
  U[        :X  a  [        $ U(       a  [        $ [        $ [        e[        U [        XV5      U5      $ Nr   r   )
r[   rk   fonerZ   fnonerW   r	   NotImplementedErrormpf_posmin)r   r^   r&   r'   r(   r)   mags          r*   mpf_round_intr   o  s    DsS
ax
&C
Qw-E\ [KE\!\M!Qw#.,e|"{%%1c"lC((r,   c                 L    [        U [        5      nU(       a  [        X1U5      nU$ r!   )r   rZ   r   r   rn   r^   vs       r*   	mpf_floorr     s"    a%AAS!Hr,   c                 L    [        U [        5      nU(       a  [        X1U5      nU$ r!   )r   r[   r   r   s       r*   mpf_ceilr     "    a'AAS!Hr,   c                 L    [        U [        5      nU(       a  [        X1U5      nU$ r!   )r   rW   r   r   s       r*   mpf_nintr     r   r,   c                 .    [        U [        U 5      X5      $ r!   )mpf_subr   )r   rn   r^   s      r*   mpf_fracr     s    1ilD..r,   5   c                 (   X :w  a  [         $  [        R                  " U 5      u  p4U [        :X  a  [        $ U [        * :X  a  [
        $ [        [        US-  5      US-
  X5      $ !   U [        :X  a  [        s $ U [        * :X  a  [
        s $ [         s $ = f)zCreate 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.l          r   )fnanmathfrexpmath_float_inffinffninfr~   rF   )r%   rn   r^   mes        r*   
from_floatr     s    
 	vzz!}
 	N4K^OE\AuI"d88ts   A" "B6B	Bq   c                 t   [        U 5      nX:X  a  [        X1U5      $ SSKnUR                  U 5      (       aE  UR	                  U 5      u  pV[        [        UR                  US5      5      [        US-
  5      X5      $ UR                  U 5      (       a  [        $ UR                  U 5      (       a  [        $ [        $ )zCreate a raw mpf from a numpy float, rounding if necessary.
If prec >= 113, the result is guaranteed to represent exactly the
same number as the input. If prec is not specified, use prec=113.r   Nr   )floatr   numpyisfiniter   r~   rF   ldexpisposinfr   isneginfr   r   )r%   rn   r^   ynpr   r   s          r*   from_npfloatr     s     	aAv!3''	{{1~~xx{CC 013qu:tII	{{1~~d{	{{1~~e|Kr,   c                 $   U R                  5       (       a  [        $ U R                  5       (       a!  U R                  5       (       a  [        $ [
        $ Uc(  [        [        U R                  5       S   5      S-  5      n[        [        U 5      X5      $ )zCreate a raw mpf from a Decimal, rounding if necessary.
If prec is not specified, use the equivalent bit precision
of the number of significant digits in x.r   rC   )is_nanr   is_infinite	is_signedr   r   rF   lenas_tuplefrom_strstr)r%   rn   r^   s      r*   from_Decimalr     sg     	xxzz$;}}u?4?|3qzz|A'(::;CFD&&r,   Fc                 l   U u  p4pVU(       d9  U [         :X  a  gU [        :X  a  [        $ U [        :X  a  [        * $ [        [        -  $ US:  a  [	        X4XVSU5      u  p4pVU(       a  U* n [
        R                  " XE5      $ ! [         a+    U(       a  e XV-   S:  a  U(       a	  [        * s $ [        s $  gf = f)a  
Convert a raw mpf to a Python float. The result is exact if the
bitcount of s is <= 53 and no underflow/overflow occurs.

If the number is too large or too small to represent as a regular
float, it will be converted to inf or 0.0. Setting strict=True
forces an OverflowError to be raised instead.

Warning: with a directed rounding mode, the correct nearest representable
floating-point number in the specified direction might not be computed
in case of overflow or (gradual) underflow.
g        r   r   )rk   r   r   r   
normalize1r   r   OverflowError)r   strictr^   r&   r'   r(   r)   s          r*   to_floatr     s     Ds:c9^+:~o-n,,	Bw'3BD3dzz### 
8a<&&%%
s   (A> >(B3(B32B3c                 @    [        [        U 5      [        U5      X#5      $ )z@Create a raw mpf from a rational number p/q, round if
necessary.)mpf_divr   )pqrn   r^   s       r*   from_rationalr     s     8A;T77r,   c                 x    U u  pp4U(       a  U* nUS:X  a  [        SU-  5      eUS:  a
  USU-  -  S4$ USU* -  4$ )zYConvert a raw mpf to a rational number. Return integers (p, q)
such that s = p/q exactly.rR   z&cannot convert %s to a rational numberr   r   r   r   s        r*   to_rationalr     sZ     Dsd	RxACGHH
axaf~q  AI~r,   c                 f    U u  p#pEXA-   nU(       a  US:  a  U* U-  $ U* U* -	  $ US:  a  X6-  $ X6* -	  $ )z.Convert a raw mpf to a fixed-point big integerr   r5   )r   rn   r&   r'   r(   r)   offsets          r*   to_fixedr     sQ    DsZFQ;//!$6'22Q;s},"w//r,   c                 p    [         (       d  SSKnUR                   q [        [        U 5      U * U [        5      $ )zMReturn a raw mpf chosen randomly from [0, 1), with prec bits
in the mantissa.r   N)getrandbitsrandomr~   rZ   )rn   r   s     r*   mpf_randr     s/     ;((D)D5$DDr,   c                 \    U S   (       a
  US   (       d  U [         :X  d
  U[         :X  a  gX:H  $ )z~Test equality of two raw mpfs. This is simply tuple comparison
unless either number is nan, in which case the result is False.r   F)r   r   r_   s     r*   mpf_eqr     s(     Q4qt9T	6Mr,   c                 (   [         R                  S:  a  U u  pp4U(       dm  U [        :X  a  [         R                  R                  $ U [
        :X  a  [         R                  R                  $ U [        :X  a  [         R                  R                  * $ U[        -  nUS:  a
  U[        -  nO[        S-
  SU-
  [        -  -
  nXS-  [        -  nU(       a  U* nUS:X  a  Sn[        U5      $  [        [        U SS95      $ ! [         a    [        U 5      s $ f = f)N)rO   r.   r   r   rR   rS   )r   )sysversion_infor   	hash_infonanr   infr   r   r   rF   hashr   r   )r   ssignsmansexpsbchs         r*   mpf_hashr   !  s    
6!!"T Dy!2!22Dy!2!22Ez3==#4#4"44<19)#Dq=R$Y)$;<DY,&qb!7A1v	1-.. 	 7N		s   &C9 9DDc                    U u  p#pEUu  pgpU(       a  U(       dS  U [         :X  a  [        U5      * $ U[         :X  a  [        U 5      $ X:X  a  gU[        :X  a  gU [        :X  a  gU[        :X  a  ggX&:w  a	  U(       d  ggXH:X  a  X7:X  a  gX7:  a	  U(       a  ggU(       a  ggXT-   n
X-   nU(       a  X:  a  gX:  a  gOX:  a  gX:  a  g[        XS[        5      nUS   (       a  gg)z|Compare the raw mpfs s and t. Return -1 if s < t, 0 if s == t,
and 1 if s > t. (Same convention as Python's cmp() function.)r   r   rR      )rk   mpf_signr   r   r   r   rZ   )r   r_   r   r   r   r   tsigntmantexptbcabdeltas                r*   mpf_cmpr   >  s     EE t:x{l*:hqk)6!9Q9Q:a~Q|<;RQ 	
A
A55555 A![)EQxr,   c                 H    U [         :X  d
  U[         :X  a  g[        X5      S:  $ NFr   r   r   r   s     r*   mpf_ltr   r  !    DyAI1=1r,   c                 H    U [         :X  d
  U[         :X  a  g[        X5      S:*  $ r   r   r   s     r*   mpf_ler   w  !    DyAI1=Ar,   c                 H    U [         :X  d
  U[         :X  a  g[        X5      S:  $ r   r   r   s     r*   mpf_gtr   |  r   r,   c                 H    U [         :X  d
  U[         :X  a  g[        X5      S:  $ r   r   r   s     r*   mpf_ger     r   r,   c                 x    U S   =pU SS   H)  n[        X15      (       a  Un[        X25      (       d  M'  UnM+     X4$ r   )r   r   )seqr   rE   r%   s       r*   mpf_min_maxr     sA    ACW!>>3!>>3  8Or,   c                 X    U(       a"  U u  p4pVU(       d	  U(       a  U $ [        X4XVX5      $ U $ )zLCalculate 0+s for a raw mpf (i.e., just round s to the specified
precision).)r   r   rn   r^   r&   r'   r(   r)   s          r*   r   r     s/     3H$Sd88Hr,   c                     U u  p4pVU(       d)  U(       a   U [         :X  a  [        $ U [        :X  a  [         $ U $ U(       d  SU-
  XEU4$ [        SU-
  XEXaU5      $ )zNegate a raw mpf (return -s), rounding the result to the
specified precision. The prec argument can be omitted to do the
operation exactly.r   )r   r   r   r   s          r*   mpf_negr    sX     DsDy,Ez$;$"%%afc#66r,   c                     U u  p4pVU(       d  U(       a  U [         :X  a  [        $ U $ U(       d  U(       a  SXEU4$ U $ [        SXEXaU5      $ )zReturn abs(s) of the raw mpf s, rounded to the specified
precision. The prec argument can be omitted to generate an
exact result.r   )r   r   r   r   s          r*   mpf_absr    sM     DsS:Ks$$a2S11r,   c                 R    U u  pp4U(       d  U [         :X  a  gU [        :X  a  ggSU-  $ )zReturn -1, 0, or 1 (as a Python int, not a raw mpf) depending on
whether s is negative, zero, or positive. (Nan is taken to give 0.)r   rR   r   )r   r   r   s        r*   r   r     s0     Ds9Q:b4<r,   c                    U u  pVpxUu  ppX-  n	U(       Ga  U
(       Ga  X{-
  nU(       GaY  US:  a  US:  aK  U(       aD  X-   U-
  U-
  nXS-   :  a2  US-   nXm-  nX:X  a  US-  nOUS-  n[        XVX}-
  [        U5      X#5      $ XY:X  a  XU-  -   nO$U(       a  XU-  -
  nOXm-  U
-
  nUS:  a  SnOU* nSn[        U5      n[        X_UUU=(       d    UU5      $ US:  a  US:  aK  U(       aD  X-   U-
  U-
  nXS-   :  a2  US-   nX-  n
XY:X  a  U
S-  n
OU
S-  n
[        XX-
  [        U
5      X#5      $ XY:X  a	  XjU* -  -   nO&U	(       a	  XjU* -  -
  nOX* -  U-
  nUS:  a  SnOU* nSn[        U5      n[        X_UUU=(       d    UU5      $ XY:X  a  X-   nOU(       a  X-
  nOXj-
  nUS:  a  SnOU* nSn[        U5      n[        X_UUU=(       d    UU5      $ U(       a  [        U5      nU(       dB  U(       a  X:X  d  U
(       d  U(       d  U $ [        $ U
(       a  [        XXU=(       d    UU5      $ U$ U(       a  U$ U(       a  [        XVXxU=(       d    UU5      $ U $ )z
Add the two raw mpf values s and t.

With prec=0, no rounding is performed. Note that this can
produce a very large mantissa (potentially too large to fit
in memory) if exponents are far apart.
r   d      r   i)r   r   r}   r  r   )r   r_   rn   r^   _subr   r   r   r   r   r   r   r   r   r   r'   r)   s                    r*   mpf_addr
    s    EE	MEzC<DJ,t3Eax'!% >4194+/194)%t{$TND 7 7 >&.1C DFN$;c%)^t$;cax !"d !c]!%dB
CHH!D=TJ,t3Eax'!% >4194+/194)%t{$TND 7 7 >6'/2C DVGO$<c%)W_$<cax !"d !c]!%dB
CHH>+CDKc Kcaxdc]T2tzr3??AJvTKe4dkc3GG%t$+#sCCHr,   c                     [        XX#S5      $ )ztReturn the difference of two raw mpfs, s-t. This function is
simply a wrapper of mpf_add that changes the sign of t.r   )r
  )r   r_   rn   r^   s       r*   r   r     s     1A&&r,   c                    SnSnUS-  =(       d    SnSnU  H  nUu  ppU
(       as  U	(       a
  U(       d  U
* n
X-
  nX:  a6  X:  a(  U(       a  U[        [        U5      5      -
  U:  a  U
nUnMV  XJU-  -  nM_  U* nX-
  U:  a  U(       d  XpTMu  Mw  XM-  U
-   nUnM  U(       d  M  U(       a  [        U5      n[        U=(       d    [        US5      nM     U(       a  U$ [        XEX5      $ )a"  
Sum a list of mpf values efficiently and accurately
(typically no temporary roundoff occurs). If prec=0,
the final result will not be rounded either.

There may be roundoff error or cancellation if extremely
large exponent differences occur.

With absolute=True, sums the absolute values.
r   r.   i@B Nr   )r   absr  r
  rk   r~   )xsrn   r^   absoluter'   r(   max_extra_precspecialr%   xsignxmanxexpxbcr   s                 r*   mpf_sumr  "  s     C
C!V&wNG!"TXuJE{ *%S(:":^"KCCEM*C9~-#'S  <4/CCTAJg.15G7 : $,,r,   c                    U u  pEpgUu  ppXH-  nXY-  nU(       a)  [        U5      nU(       a  [        XXj-   XU5      $ XXj-   U4$ U(       + =(       a    UnU	(       + =(       a    U
nU(       d  U(       d  [        $ [        X4;   a  [        $ U	(       d	  U
(       a  XpU[        :X  a  [        $ [        [
        S.[        U 5      [        U5      -     $ )Multiply two raw mpfsr   rR   )r   r   rk   r   r   r   r   r   r_   rn   r^   r   r   r   r   r   r   r   r   r&   r'   r)   	s_special	t_specials                    r*   gmpy_mpf_mulr  R  s    EE=D
)C
c]dBcBBty"--#tI#tIYv~d{d1qEz$;uhqkHQK788r,   c                     U u  pEpgU(       d  [        U [        U5      X#5      $ U(       d  [        $ US:  a  US-  nU* nXQ-  n[        XEU[	        U5      X#5      $ )Multiply by a Python integer.r   r   )mpf_mulr   rk   r}   r   r   r=   rn   r^   r&   r'   r(   r)   s           r*   gmpy_mpf_mul_intr"  g  s]    Dsq(1+t111u	BHCTXc]D>>r,   c                    U u  pEpgUu  ppXH-  nXY-  nU(       a5  X{-   S-
  nU[        X-	  5      -  nU(       a  [        XXj-   XU5      $ XXj-   U4$ U(       + =(       a    UnU	(       + =(       a    U
nU(       d  U(       d  [        $ [        X4;   a  [        $ U	(       d	  U
(       a  XpU[        :X  a  [        $ [        [
        S.[        U 5      [        U5      -     $ )r  r   r  )rF   r   rk   r   r   r   r   r  s                    r*   python_mpf_mulr$  t  s    EE=D
)C
Y]
c#'ldBcBBty"--#tI#tIYv~d{d1qEz$;uhqkHQK788r,   c                    U u  pEpgU(       d  [        U [        U5      X#5      $ U(       d  [        $ US:  a  US-  nU* nXQ-  nUS:  a  U[        [	        U5         S-
  -  nOU[        U5      S-
  -  nU[	        XW-	  5      -  n[        XEXgX#5      $ )r  r   r   r|   )r   r   rk   r   rF   r   r}   r!  s           r*   python_mpf_mul_intr&    s    Dsq(1+t111u	BHC4x
gc!fo!!
hqkAo#cg,BT33r,   c                 ,    U u  p#pEU(       d  U $ X#XA-   U4$ )z8Quickly multiply the raw mpf s by 2**n without rounding.r5   )r   r=   r&   r'   r(   r)   s         r*   	mpf_shiftr(    s#    DsceRr,   c                 p    U u  pp4U(       d  U [         :X  a  [         S4$ [        e[        X* U-
  5      XC-   4$ )z?Convert x = y*2**n to (y, n) with abs(y) in [0.5, 1) if nonzeror   )rk   r   r(  r$   s        r*   	mpf_frexpr*    s>    Ds:1:QC "&((r,   c                    U u  pEpgUu  ppU(       a  U	(       d  U [         :X  a&  U[         :X  a  [        eU[        :X  a  [        $ [         $ U[         :X  a  [        eU(       + =(       a    UnU	(       + =(       a    U
nU(       a  U(       a  [        $ U [        :X  d
  U[        :X  a  [        $ U(       d5  U[         :X  a  [        $ [        [        S.[        U 5      [        U5      -     $ [         $ XH-  nU	S:X  a  [        XXj-
  XrU5      $ X'-
  U-   S-   nUS:  a  Sn[        X_-  U	5      u  nnU(       a*  US-  S-   nUS-  n[        UUXj-
  U-
  [        U5      X#5      $ [        UUXj-
  U-
  [        U5      X#5      $ )zFloating-point divisionr  r   r   )
rk   ZeroDivisionErrorr   r   r   r   r   divmodr   r}   )r   r_   rn   r^   r   r   r   r   r   r   r   r   r  r  r&   extraquotrems                     r*   r   r     sV   EEt:Ez!22Dy+L:##X'4	X'4	K9T	KEzu%hqkHQK&?@@=Dqy$diC@@ Jq Eqyt{D)ID#
a1}
$diox~tQQT45(4.$LLr,   c                 2   Uu  pEpgU (       a  U(       d  [        [        U 5      XU5      $ U S:  a  US-  nU * n X'-   S-   n[        X-  U5      u  pU
(       a(  U	S-  S-   n	US-  n[        XIU* U-
  [	        U	5      X#5      $ [        XIU* U-
  [	        U	5      X#5      $ )z>Floating-point division n/t with a Python integer as numeratorr   r   r   )r   r   r-  r   r   r}   )r=   r_   rn   r^   r&   r'   r(   r)   r.  r/  r0  s              r*   mpf_rdiv_intr2    s    DsCx{AS111u	BIMEqx%ID
a1}
$sd5j(4.$LLT#eXd^TGGr,   c                 >   U u  pEpgUu  ppU(       d  U(       d  U	(       d  U
(       a  [         $ XH:X  a
  XU-   :  a  U $ U	S:X  a  XjU-   :  a  [        $ [        Xj5      nSU-  U-  nSU-  U	-  n	XVU-
  -  XU-
  -  -  nUS:  a  SnOU* nSn[        XU[	        U5      X#5      $ )Nr   rR   r   )r   rk   r   r}   r   )r   r_   rn   r^   r   r   r   r   r   r   r   r   baser'   r&   s                  r*   mpf_modr5    s    EEtd~$c/ qyTH_t?D;D;DI4I#6
7C
axdThsmT??r,   c                    U u  pEpgU(       de  U(       a^  U [         :X  a  US:  a  U $ US:X  a  [        $ [        $ U [        :X  a*  US:  a  [         [        /US-     $ US:X  a  [        $ [        $ [        $ [	        U5      nUS:X  a  [
        $ US:X  a  [        XU5      $ US:X  aW  U u  ppgU(       d  [        $ XU-  nUS:X  a  S[        Xf-   S4$ Xw-   S-
  nU[        [	        XW-	  5         -  n[        SXVU-   XrU5      $ US:X  a  [        [
        XU5      $ US:  a)  [        X* US-   [        U   5      n	[        [
        XU5      $ XA-  n
US:X  a  U
[        Xa-  S4$ Xq-  S:  a  XQ-  n[        XXa-  [        U5      X#5      $ U[        :H  =(       d    [        U   U
   nUS[        U5      -  -   S-   n[
        u  pp US-  (       aY  X-  nX-   nXS-
  -  nU[        [	        X-	  5         -   nX:  a!  U(       a  XU-
  -	  nO	U* X-
  -	  * nXU-
  -  nUnUS-  nU(       d  OSXU-  nXf-   nXw-   S-
  nU[        [	        XW-	  5         -   nX|:  a!  U(       a  XWU-
  -	  nO	U* X|-
  -	  * nXgU-
  -  nUnUS-  nM  [!        XXX#5      $ )z=Compute s**n, where s is a raw mpf and n is a Python integer.r   r   r.   rR   r   i  r  )r   r   rk   r   rF   r   r   r	   r   r   r   mpf_pow_intreciprocal_rndr   rW   rl   r}   )r   r=   rn   r^   r&   r'   r(   r)   _inverseresult_signrounds_downworkprecpmpepbcs                   r*   r7  r7    s   DsS91uQhAvd{L:1udE]1q511Avd{LAAAvd{Avgas++AvLg!8w++Wq[
gc#'l##!Sc'2S99BwwtQc221uaT!V^C-@AtWC00(K axWceQ//	td{	+CE8C=$LL -' &C%  am#a'HNA2
q5BB6MCBI//C~H-BCS\23BHn$FAggWq['#ci.))=k*2;/0= CBF7 : [bt99r,   c                     U[         :X  a  [        XU5      $ U u  pEpgU[        Xg-   U-
  S-
  S4nU(       a  U[        [        4;   U-  n	OU[
        [        4;   U-  n	U	(       a  [        XX#5      $ [        XU5      $ )z
For nonzero x, calculate x + eps with directed rounding, where
eps < prec relatively and eps has the given sign (0 for
positive, 1 for negative).

With rounding to nearest, this is taken to simply normalize
x to the given precision.
r   )rW   r   r	   r\   r[   r]   r
  )
r%   eps_signrn   r^   r&   r'   r(   r)   epsaways
             r*   mpf_perturbrE  f  s     mq$$DsWcfTk!mQ
/C
M22h>-00H<qt))q$$r,   c                    U S   (       a  Sn[        U 5      n OSnU u  p4pVU(       d  g[        U[        R                  " SS5      -  5      S-   nXV-   n[	        U5      S:  a{  SS	KJn	Jn
  [        [	        U5      5      S
-   n[        U5      n[        X" U5      5      n[        X" U5      U5      n[        U5      n[        U [        [        X5      U5      n U u  p4pVUnOSn[        Xu-
  U-
  S5      n[        U[        R                  " SS5      -  S-   5      n[!        X5      n[#        UUSU5      n[%        USUS9nU['        U5      U-
  S-
  -  nUUU4$ )a   Helper function for representing the floating-point number s as
a decimal with dps digits. Returns (sign, string, exponent) where
sign is '' or '-', string is the digit string, and exponent is
the decimal exponent as an int.

If inexact, the decimal representation is rounded toward zero.r   - )rH  0r   
   r.   i  r   )mpf_ln2mpf_ln10r   g      ?)r4  size)r  rF   r   logr  	libelefunrK  rL  r   r   r   r   r   r7  ftenrE   r   r   r   r   )r   rP   r&   _signr'   r(   r)   bitprec
exp_from_1rK  rL  expprectmpr   exponentfixprecfixdpssfsddigitss                       r*   to_digits_expr\    sX    	tAJE#A&'",G J
:0 3s8$q(smc77+,c8G,g63KA{44g>C
 '-"$a(G488Bq>)C/0F	!	B	b'2v	.BRbs+FFf$q((H!!r,   c                    U S   (       dK  U [         :X  a  U(       a  SnOSnU(       a  US-  nU$ U [        :X  a  gU [        :X  a  gU [        :X  a  g[        eUc  [        US	-  * S
5      nUc  Un[        XS	-   5      u  pxn	U(       d  US   S;   a  U	S-  n	SnGO[        U5      U:  aw  X   S;   ao  USU nUS-
  n
U
S:  a  X   S:X  a  U
S-  n
U
S:  a
  X   S:X  a  M  U
S:  a+  USU
 [        [        X   5      S-   5      -   SX-
  S-
  -  -   nOSSUS-
  -  -   nU	S-  n	OUSU nX9s=:  a  U:  a5  O  O2U	S:  a  S[        U	* 5      -  U-   nSnOU	S-   nX:  a
  USX-
  -  -  nSn	OSnUSU S-   XS -   nU(       a  UR                  S5      nUS   S:X  a  US-  nU	S:X  a  U(       a  U(       d  Xx-   $ U	S:  a  Xx-   S-   [        U	5      -   $ U	S:  a  Xx-   S-   [        U	5      -   $ g)aK  
Convert a raw mpf to a decimal floating-point literal with at
most `dps` decimal digits in the mantissa (not counting extra zeros
that may be inserted for visual purposes).

The number will be printed in fixed-point format if the position
of the leading digit is strictly between min_fixed
(default = min(-dps/3,-5)) and max_fixed (default = dps).

To force fixed-point format always, set min_fixed = -inf,
max_fixed = +inf. To force floating-point format, set
min_fixed >= max_fixed.

The literal is formatted so that it can be parsed back to a number
by to_str, float() or Decimal().
r   z0.0z.0ze+0+inf-infr   NrO   r   567899rI  1.rR   ze+r   )rk   r   r   r   r   r   r\  r   r   rF   rstrip)r   rP   strip_zeros	min_fixed	max_fixedshow_zero_exponentr_   r&   r[  rV  isplits               r*   to_strrl    s;   ( Q4:AA!U
H9V:f9UcCF)R&8)c) +1!e4D( !9MH v;!7DS\FaAq&VY#-Q q&VY#-Avc#fi.1*<&==swQR{@SSscAg.ADS\F +)+!|c8)n,6 1;c59o-FHE%.3&7]]3'FbzS #1}%79M1}T]T1CMAA!|DMC/#h-??|r,   c                    U R                  5       R                  S5      n [        U 5        U R                  S5      n[	        U5      S:X  a  SnOUS   n [        US   5      nU R                  S5      n[	        U5      S:X  a*  US   US   R                  S5      pTU[	        U5      -  nXE-   n [        [        X5      5      n X4$ )zHelper function for from_str.lr   r   r   rd  r.   rI  )lowerre  r   rk  r   rF   r   )r%   r4  partsr(   r   r   s         r*   str_to_man_exprq  
  s    		A	!HGGCLE
5zQ!H%(mGGCLE
5zQQxq-1s1vECLA6Mr,   )r   r^  r_  r   c           	         U R                  5       R                  5       n U [        ;   a	  [        U    $ SU ;   aS  U R                  S5      u  p4UR	                  S5      UR	                  S5      pC[        [        U5      [        U5      X5      $ [        U SS9u  pV[        U5      S:  a.  [        XQS-   5      n[        U[        [        XaS-   5      X5      nU$ US:  a  [        USU-  -  X5      nU$ [        USU* -  X5      nU$ )a>  Create a raw mpf from a decimal literal, rounding in the
specified direction if the input number cannot be represented
exactly as a binary floating-point number with the given number of
bits. The literal syntax accepted is the same as for Python
floats.

TODO: the rounding does not work properly for large exponents.
/rn  rJ  r4  i  r   )ro  stripspecial_strrk  re  r   rF   rq  r  r   r   r7  rP  )r%   rn   r^   r   r   r'   r(   r   s           r*   r   r   !  s     	
	AK1~
axwws|xx}ahhsm1SVSVT77ab)HC 3x#~Sr'"A{42g6B H	 !8r3w2A H c2t8T7AHr,   c                     [        U SS9u  p[        U5      nSnUS:  a  U* nSn[        U5      n[        X1X$U[        5      $ )Nr.   rt  r   r   )rq  r   r   r}   rZ   )r%   r'   r(   r&   r)   s        r*   	from_bstrrx  D  sK    aa(HC
c(CD
Qwd	#BT[99r,   c                 P    U u  pp4SS/U   [        U[        U5      SS9-   SU-  -   $ )NrH  rG  r.   )rM  r4  ze%i)r   r   r$   s        r*   to_bstrrz  N  s6    Dss8D>GChsm!DDPSTTr,   c                 n   U u  p4pVU(       a  [        S5      eU(       d  U $ US-  (       a  US-  nUS-  nUS-  nOUS:X  a  [        X4US-  XaU5      $ [        SSU-  U-
  S-   5      nXwS-  -  nUS;   a  [        XG-  5      nO#[	        XG-  5      u  pHU(       a  US-  S-   nUS-  n[        XEU-
  S-  X5      $ )zV
Compute the square root of a nonnegative mpf value. The
result is correctly rounded.
z square root of a negative numberr   r.   r  fd)r3   r   rE   r   r   r~   )	r   rn   r^   r&   r'   r(   r)   shiftr0  s	            r*   mpf_sqrtr~  X  s    
 Ds>??
Qwq	
a	$S!VRs;;1T6"9Q;E	QYE
d{CJ3:&61*CQJE%i!^T77r,   c                     U[         :X  a  [        XU5      $ U [         :X  a  [        XU5      $ [        [        X 5      [        X5      US-   5      n[	        XBU5      $ )zECompute the Euclidean norm sqrt(x**2 + y**2) of two raw mpfs
x and y.r  )rk   r  r
  r   r~  )r%   r   rn   r^   hypot2s        r*   	mpf_hypotr  t  sQ     	Ez'!3//Ez'!3//WQ\71<a8FF#&&r,   r!   )TNNF)rJ  )__doc____docformat__r   r   r   r   backendr   r   r   r	   r
   r   r   r   r   r   r   r   r   
libintmathr   r   r   r   r   r   r   r   r   r   r   r   r   r+   r1   r   r3   intern	NameErrorrW   rZ   r[   r]   r\   
round_fastrI   rK   rQ   rk   fnzeror   r   ftworP  fhalfr   r   r   r   rY   ra   rangeh_mask_smallrX   rl   ro   rq   rF   longru   rw   ry   dirrz   r}   r   r~   dictr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r
  r   r  r  r"  r$  r&  r   mpf_mul_intr(  r*  r   r2  r5  r8  negative_rndr7  rE  r\  rl  rq  rv  r   rx  rz  r~  r  sage.libs.mpmath.ext_libmplibsmpmath	ext_libmpext_libImportError)r9  s   0r*   <module>r     sS      
 F F F F    f'+)	J 	

 sSks#;C[

;
=
 
Ha
Xq!		7Aq	
GQ	7Aq	8Q	
GR 	
8T2	8T2	
HdB 2" " s%3-@-Qg!na'-@@
,	%
 5-uhu&5n'RtJ56 f,D	9''J((K
f)333J	 I"JIJ !%* 4> B%S/BB	
f)SY6&&L
f**LJ )),), Z  J  J  J / z 9& *  : ' * #J #- 8
	0&E:2h



 :  j 7 j 2 jq ]~ j '
 J .-` : 9* &0 ?  Z 9, (2 4( fG"KG$K ) ' #MJ ", H  ' @0 x
Z+- z
X+- !+ Q:h%62"h @DS@j* $uDA$ F:U % 88 ) ' f44////////## [*  Fp Af  JT$  s=   -M :M%.M* 
A	M: 	M"!M"*	M76M7:NN