FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
RustPython/crates/stdlib/src/cmath.rs at 0.6.0 · RustPython/RustPython · GitHub
RustPython
RustPython
Repository navigation
Code
Issues
182
(182)
Pull requests
109
(109)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
RustPython
/
crates
/
stdlib
/
src
/
cmath.rs
Copy path
More file actions
More file actions
Latest commit
History
History
History
170 lines (142 loc) · 5.49 KB
Breadcrumbs
RustPython
/
crates
/
stdlib
/
src
/
cmath.rs
Copy path
File metadata and controls
170 lines (142 loc) · 5.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
pub
(
crate
)
use
cmath
::
module_def
;
#
[
pymodule
]
mod
cmath
{
use
crate
::
vm
::
{
PyResult
,
VirtualMachine
,
function
::
{
ArgIntoComplex
,
ArgIntoFloat
,
OptionalArg
}
,
}
;
use
num_complex
::
Complex64
;
use
crate
::
math
::
pymath_exception
;
// Constants
#
[
pyattr
(
name =
"e"
)
]
const
E
:
f64
= pymath
::
cmath
::
E
;
#
[
pyattr
(
name =
"pi"
)
]
const
PI
:
f64
= pymath
::
cmath
::
PI
;
#
[
pyattr
(
name =
"tau"
)
]
const
TAU
:
f64
= pymath
::
cmath
::
TAU
;
#
[
pyattr
(
name =
"inf"
)
]
const
INF
:
f64
= pymath
::
cmath
::
INF
;
#
[
pyattr
(
name =
"nan"
)
]
const
NAN
:
f64
= pymath
::
cmath
::
NAN
;
#
[
pyattr
(
name =
"infj"
)
]
const
INFJ
:
Complex64
= pymath
::
cmath
::
INFJ
;
#
[
pyattr
(
name =
"nanj"
)
]
const
NANJ
:
Complex64
= pymath
::
cmath
::
NANJ
;
#
[
pyfunction
]
fn
phase
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
f64
>
{
pymath
::
cmath
::
phase
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
polar
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
(
f64
,
f64
)
>
{
pymath
::
cmath
::
polar
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
rect
(
r
:
ArgIntoFloat
,
phi
:
ArgIntoFloat
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
rect
(
r
.
into_float
(
)
,
phi
.
into_float
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
isinf
(
z
:
ArgIntoComplex
)
->
bool
{
pymath
::
cmath
::
isinf
(
z
.
into_complex
(
)
)
}
#
[
pyfunction
]
fn
isfinite
(
z
:
ArgIntoComplex
)
->
bool
{
pymath
::
cmath
::
isfinite
(
z
.
into_complex
(
)
)
}
#
[
pyfunction
]
fn
isnan
(
z
:
ArgIntoComplex
)
->
bool
{
pymath
::
cmath
::
isnan
(
z
.
into_complex
(
)
)
}
#
[
pyfunction
]
fn
exp
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
exp
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
sqrt
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
sqrt
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
sin
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
sin
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
asin
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
asin
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
cos
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
cos
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
acos
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
acos
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
log
(
z
:
ArgIntoComplex
,
base
:
OptionalArg
<
ArgIntoComplex
>
,
vm
:
&
VirtualMachine
,
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
log
(
z
.
into_complex
(
)
,
base
.
into_option
(
)
.
map
(
|b| b
.
into_complex
(
)
)
,
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
log10
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
log10
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
acosh
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
acosh
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
atan
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
atan
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
atanh
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
atanh
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
tan
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
tan
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
tanh
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
tanh
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
sinh
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
sinh
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
cosh
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
cosh
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
pyfunction
]
fn
asinh
(
z
:
ArgIntoComplex
,
vm
:
&
VirtualMachine
)
->
PyResult
<
Complex64
>
{
pymath
::
cmath
::
asinh
(
z
.
into_complex
(
)
)
.
map_err
(
|err|
pymath_exception
(
err
,
vm
)
)
}
#
[
derive
(
FromArgs
)
]
struct
IsCloseArgs
{
#
[
pyarg
(
any
)
]
a
:
ArgIntoComplex
,
#
[
pyarg
(
any
)
]
b
:
ArgIntoComplex
,
#
[
pyarg
(
named
,
default
=
1e-09
)
]
rel_tol
:
ArgIntoFloat
,
#
[
pyarg
(
named
,
default
=
0.0
)
]
abs_tol
:
ArgIntoFloat
,
}
#
[
pyfunction
]
fn
isclose
(
args
:
IsCloseArgs
,
vm
:
&
VirtualMachine
)
->
PyResult
<
bool
>
{
let
a = args
.
a
.
into_complex
(
)
;
let
b = args
.
b
.
into_complex
(
)
;
let
rel_tol =
Some
(
args
.
rel_tol
.
into_float
(
)
)
;
let
abs_tol =
Some
(
args
.
abs_tol
.
into_float
(
)
)
;
pymath
::
cmath
::
isclose
(
a
,
b
,
rel_tol
,
abs_tol
)
.
map_err
(
|_| vm
.
new_value_error
(
"tolerances must be non-negative"
)
)
}
}
Back
|
FazBrowse Home
|
New Git URL