zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
U
O±dÇ.ã@sZdZdgZddlmZddlmZddlmZedƒGdd„dƒƒZe    dkrVe
eƒƒd    S)
Machine arithmetic - determine the parameters of the
floating-point arithmetic system
 
Author: Pearu Peterson, September 2003
 
ÚMachAré)Úany)Úerrstate)Ú
set_moduleÚnumpyc@s8eZdZdZeeedd„dfdd„Zdd„Zd    d
„Zd S) raw
    Diagnosing machine parameters.
 
    Attributes
    ----------
    ibeta : int
        Radix in which numbers are represented.
    it : int
        Number of base-`ibeta` digits in the floating point mantissa M.
    machep : int
        Exponent of the smallest (most negative) power of `ibeta` that,
        added to 1.0, gives something different from 1.0
    eps : float
        Floating-point number ``beta**machep`` (floating point precision)
    negep : int
        Exponent of the smallest power of `ibeta` that, subtracted
        from 1.0, gives something different from 1.0.
    epsneg : float
        Floating-point number ``beta**negep``.
    iexp : int
        Number of bits in the exponent (including its sign and bias).
    minexp : int
        Smallest (most negative) power of `ibeta` consistent with there
        being no leading zeros in the mantissa.
    xmin : float
        Floating-point number ``beta**minexp`` (the smallest [in
        magnitude] positive floating point number with full precision).
    maxexp : int
        Smallest (positive) power of `ibeta` that causes overflow.
    xmax : float
        ``(1-epsneg) * beta**maxexp`` (the largest [in magnitude]
        usable floating value).
    irnd : int
        In ``range(6)``, information on what kind of rounding is done
        in addition, and on how underflow is handled.
    ngrd : int
        Number of 'guard digits' used when truncating the product
        of two mantissas to fit the representation.
    epsilon : float
        Same as `eps`.
    tiny : float
        An alias for `smallest_normal`, kept for backwards compatibility.
    huge : float
        Same as `xmax`.
    precision : float
        ``- int(-log10(eps))``
    resolution : float
        ``- 10**(-precision)``
    smallest_normal : float
        The smallest positive floating point number with 1 as leading bit in
        the mantissa following IEEE-754. Same as `xmin`.
    smallest_subnormal : float
        The smallest positive floating point number with 0 as leading bit in
        the mantissa following IEEE-754.
 
    Parameters
    ----------
    float_conv : function, optional
        Function that converts an integer or integer array to a float
        or float array. Default is `float`.
    int_conv : function, optional
        Function that converts a float or float array to an integer or
        integer array. Default is `int`.
    float_to_float : function, optional
        Function that converts a float array to float. Default is `float`.
        Note that this does not seem to do anything useful in the current
        implementation.
    float_to_str : function, optional
        Function that converts a single float to a string. Default is
        ``lambda v:'%24.16e' %v``.
    title : str, optional
        Title that is printed in the string representation of `MachAr`.
 
    See Also
    --------
    finfo : Machine limits for floating point types.
    iinfo : Machine limits for integer types.
 
    References
    ----------
    .. [1] Press, Teukolsky, Vetterling and Flannery,
           "Numerical Recipes in C++," 2nd ed,
           Cambridge University Press, 2002, p. 31.
 
    cCsd|S)Nz%24.16e©)ÚvrrúId:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/core/_machar.pyÚ<lambda>kózMachAr.<lambda>zPython floating point numberc    Cs,tdd| |||||¡W5QRXdS)a!
 
        float_conv - convert integer to float (array)
        int_conv   - convert float (array) to integer
        float_to_float - convert float array to float
        float_to_str - convert array float to str
        title        - description of used floating point numbers
 
        Úignore)ZunderN)rÚ_do_init)ÚselfÚ
float_convÚint_convÚfloat_to_floatÚ float_to_strÚtitlerrr    Ú__init__is zMachAr.__init__c/Csúd}d}|dƒ}||}    ||}
|} t|ƒD]0} | | } | |} | | }t|||
kƒr,qpq,t|| |jfƒ‚|}t|ƒD]0} ||}| |} || | ƒ}t|dkƒr|qÀq|t|| |jfƒ‚|}||ƒ}d}|}t|ƒD]:} |d}||}||} | |}t|||
kƒrܐq*qÜt|| |jfƒ‚||    }|} t|ƒD]6} | | } | |} | | }t|||
kƒr>qˆq>t|| |jfƒ‚| |} d}t| | |
kƒrªd}| |}||} |dkrÚt| ||
kƒrÚd}|d}||}|} t|ƒD]}| |} qö| }t|ƒD]N} || } t| ||
kƒr6qt| |} |d}|dkrtdtƒƒ‚qt|| |jfƒ‚| }| }| d}|} t|ƒD]6} || } t| ||
kƒr¸qÞ| |} |d}q”t|| |jfƒ‚| }d}||} |dkrt| |||
kƒrd}d}d}|}||} d}!t|ƒD]|} |}"|"|"}||} || } t| | |
kƒsvtt|ƒ|"kƒr|qÂ| |}t|||kƒrœqÂ|d}||}q2t|| |jfƒ‚|d    krÞ|d}#||}$n2d}#|}%||%kr|%|}%|#d}#qæ|%|%d}$t|ƒD]Œ} |"}&|"|}"|"|} |"| } t| | |
kƒrœtt|"ƒ|&kƒrœ|d}| |}t|||"kƒr¢t| |"kƒr¢d}!|"}&q¸nq¸qt|| |jfƒ‚| }'|$||dkrê|d    krê|$|$}$|#d}#|$|'}(||!}|dkr |(d}(|(|'}|dkr,|s,|(d}(|d
kr>|(d}(t| |"kƒrT|(d}(||})t|)||)kƒrz|||})|)|&|||})|(|'d}t|ƒD]"}*|dkrº|)|)})n|)|})q¢t|&||ƒ}+||_||_||_||ƒ|_    ||ƒ|_
||_ ||ƒ|_ ||ƒ|_ ||_|#|_|'|_||&ƒ|_||&ƒ|_|(|_||)ƒ|_||)ƒ|_||_||_|j |_|j|_|j|_|j|_||jƒ|_||+ƒ|_||+ƒ|_ddl},t |, !||j ƒ¡ ƒ|_"|    |    |    |    |    }-|-|j" }.||.ƒ|_#||.ƒ|_$dS) Ni'z'Did not converge after %d tries with %séréÿÿÿÿéézAcould not determine machine tolerance for 'negep', locals() -> %sé
é)%ÚrangerÚ RuntimeErrorZdtypeÚlocalsÚabsÚibetaÚitÚnegepÚepsnegZ _str_epsnegÚmachepÚepsZ_str_epsÚngrdÚiexpÚminexpÚxminZ    _str_xminÚmaxexpÚxmaxZ    _str_xmaxÚirndrÚepsilonZtinyZhugeZsmallest_normalZ_str_smallest_normalÚsmallest_subnormalZ_str_smallest_subnormalÚmathÚintÚlog10Z    precisionÚ
resolutionZ_str_resolution)/rrrrrrZ    max_iterNÚmsgZoneZtwoZzeroÚaÚ_ÚtempZtemp1ÚbZitemprÚbetar Zbetahr+Ztempar!ZbetainÚir"r#r$r%ÚkÚzÚtZnxresÚyr&ZmxZizr(r'r)r*Újr-r.Ztenr1rrr    r {sh      
 
ÿ
 
    $ 
 
 
   $ 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
zMachAr._do_initcCsd}||jS)NaCMachine parameters for %(title)s
---------------------------------------------------------------------
ibeta=%(ibeta)s it=%(it)s iexp=%(iexp)s ngrd=%(ngrd)s irnd=%(irnd)s
machep=%(machep)s     eps=%(_str_eps)s (beta**machep == epsilon)
negep =%(negep)s  epsneg=%(_str_epsneg)s (beta**epsneg)
minexp=%(minexp)s   xmin=%(_str_xmin)s (beta**minexp == tiny)
maxexp=%(maxexp)s    xmax=%(_str_xmax)s ((1-epsneg)*beta**maxexp == huge)
smallest_normal=%(smallest_normal)s    smallest_subnormal=%(smallest_subnormal)s
---------------------------------------------------------------------
)Ú__dict__)rÚfmtrrr    Ú__str__Tsÿ zMachAr.__str__N)    Ú__name__Ú
__module__Ú __qualname__Ú__doc__Úfloatr/rr r@rrrr    rsVý
ZÚ__main__N) rDÚ__all__Znumpy.core.fromnumericrZnumpy.core._ufunc_configrZnumpy.core.overridesrrrAÚprintrrrr    Ú<module>s   T