Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0a84691d
Commit
0a84691d
authored
Jan 12, 1996
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes for complex numbers
parent
a16c7a6f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
1 deletion
+111
-1
Python/bltinmodule.c
Python/bltinmodule.c
+53
-1
Python/getargs.c
Python/getargs.c
+11
-0
Python/marshal.c
Python/marshal.c
+47
-0
No files found.
Python/bltinmodule.c
View file @
0a84691d
...
@@ -281,6 +281,51 @@ builtin_compile(self, args)
...
@@ -281,6 +281,51 @@ builtin_compile(self, args)
return
compile_string
(
str
,
filename
,
start
);
return
compile_string
(
str
,
filename
,
start
);
}
}
#ifndef WITHOUT_COMPLEX
static
object
*
builtin_complex
(
self
,
args
)
object
*
self
;
object
*
args
;
{
object
*
r
,
*
i
;
number_methods
*
nbr
,
*
nbi
;
complex
cr
,
ci
;
i
=
NULL
;
if
(
!
newgetargs
(
args
,
"O|O:complex"
,
&
r
,
&
i
))
return
NULL
;
if
((
nbr
=
r
->
ob_type
->
tp_as_number
)
==
NULL
||
nbr
->
nb_float
==
NULL
||
(
i
!=
NULL
&&
((
nbi
=
i
->
ob_type
->
tp_as_number
)
==
NULL
||
nbi
->
nb_float
==
NULL
)))
{
err_setstr
(
TypeError
,
"complex() argument can't be converted to complex"
);
return
NULL
;
}
if
(
is_complexobject
(
r
))
cr
=
((
complexobject
*
)
r
)
->
cval
;
else
{
cr
.
real
=
getfloatvalue
((
*
nbr
->
nb_float
)(
r
));
cr
.
imag
=
0
.;
}
if
(
i
==
NULL
)
{
ci
.
real
=
0
.;
ci
.
imag
=
0
.;
}
else
if
(
is_complexobject
(
i
))
ci
=
((
complexobject
*
)
i
)
->
cval
;
else
{
ci
.
real
=
getfloatvalue
((
*
nbi
->
nb_float
)(
i
));
ci
.
imag
=
0
.;
}
cr
.
real
-=
ci
.
imag
;
cr
.
imag
+=
ci
.
real
;
return
newcomplexobject
(
cr
);
}
#endif
static
object
*
static
object
*
builtin_dir
(
self
,
args
)
builtin_dir
(
self
,
args
)
object
*
self
;
object
*
self
;
...
@@ -954,7 +999,11 @@ do_pow(v, w)
...
@@ -954,7 +999,11 @@ do_pow(v, w)
err_setstr
(
TypeError
,
"pow() requires numeric arguments"
);
err_setstr
(
TypeError
,
"pow() requires numeric arguments"
);
return
NULL
;
return
NULL
;
}
}
if
(
is_floatobject
(
w
)
&&
getfloatvalue
(
v
)
<
0
.
0
)
{
if
(
#ifndef WITHOUT_COMPLEX
!
is_complexobject
(
v
)
&&
#endif
is_floatobject
(
w
)
&&
getfloatvalue
(
v
)
<
0
.
0
)
{
if
(
!
err_occurred
())
if
(
!
err_occurred
())
err_setstr
(
ValueError
,
"negative number to float power"
);
err_setstr
(
ValueError
,
"negative number to float power"
);
return
NULL
;
return
NULL
;
...
@@ -1394,6 +1443,9 @@ static struct methodlist builtin_methods[] = {
...
@@ -1394,6 +1443,9 @@ static struct methodlist builtin_methods[] = {
{
"cmp"
,
builtin_cmp
,
1
},
{
"cmp"
,
builtin_cmp
,
1
},
{
"coerce"
,
builtin_coerce
,
1
},
{
"coerce"
,
builtin_coerce
,
1
},
{
"compile"
,
builtin_compile
,
1
},
{
"compile"
,
builtin_compile
,
1
},
#ifndef WITHOUT_COMPLEX
{
"complex"
,
builtin_complex
,
1
},
#endif
{
"delattr"
,
builtin_delattr
,
1
},
{
"delattr"
,
builtin_delattr
,
1
},
{
"dir"
,
builtin_dir
,
1
},
{
"dir"
,
builtin_dir
,
1
},
{
"divmod"
,
builtin_divmod
,
1
},
{
"divmod"
,
builtin_divmod
,
1
},
...
...
Python/getargs.c
View file @
0a84691d
...
@@ -498,6 +498,17 @@ convertsimple1(arg, p_format, p_va)
...
@@ -498,6 +498,17 @@ convertsimple1(arg, p_format, p_va)
break
;
break
;
}
}
case
'D'
:
/* complex double */
{
complex
*
p
=
va_arg
(
*
p_va
,
complex
*
);
complex
cval
=
PyComplex_AsCComplex
(
arg
);
if
(
err_occurred
())
return
"complex<D>"
;
else
*
p
=
cval
;
break
;
}
case
'c'
:
/* char */
case
'c'
:
/* char */
{
{
char
*
p
=
va_arg
(
*
p_va
,
char
*
);
char
*
p
=
va_arg
(
*
p_va
,
char
*
);
...
...
Python/marshal.c
View file @
0a84691d
...
@@ -39,6 +39,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
...
@@ -39,6 +39,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define TYPE_NONE 'N'
#define TYPE_NONE 'N'
#define TYPE_INT 'i'
#define TYPE_INT 'i'
#define TYPE_FLOAT 'f'
#define TYPE_FLOAT 'f'
#define TYPE_COMPLEX 'x'
#define TYPE_LONG 'l'
#define TYPE_LONG 'l'
#define TYPE_STRING 's'
#define TYPE_STRING 's'
#define TYPE_TUPLE '('
#define TYPE_TUPLE '('
...
@@ -150,6 +151,26 @@ w_object(v, p)
...
@@ -150,6 +151,26 @@ w_object(v, p)
w_byte
(
n
,
p
);
w_byte
(
n
,
p
);
w_string
(
buf
,
n
,
p
);
w_string
(
buf
,
n
,
p
);
}
}
#ifndef WITHOUT_COMPLEX
else
if
(
is_complexobject
(
v
))
{
extern
void
float_buf_repr
PROTO
((
char
*
,
floatobject
*
));
char
buf
[
256
];
/* Plenty to format any double */
floatobject
*
temp
;
w_byte
(
TYPE_COMPLEX
,
p
);
temp
=
(
floatobject
*
)
newfloatobject
(
PyComplex_RealAsDouble
(
v
));
float_buf_repr
(
buf
,
temp
);
DECREF
(
temp
);
n
=
strlen
(
buf
);
w_byte
(
n
,
p
);
w_string
(
buf
,
n
,
p
);
temp
=
(
floatobject
*
)
newfloatobject
(
PyComplex_ImagAsDouble
(
v
));
float_buf_repr
(
buf
,
temp
);
DECREF
(
temp
);
n
=
strlen
(
buf
);
w_byte
(
n
,
p
);
w_string
(
buf
,
n
,
p
);
}
#endif
else
if
(
is_stringobject
(
v
))
{
else
if
(
is_stringobject
(
v
))
{
w_byte
(
TYPE_STRING
,
p
);
w_byte
(
TYPE_STRING
,
p
);
n
=
getstringsize
(
v
);
n
=
getstringsize
(
v
);
...
@@ -329,6 +350,32 @@ r_object(p)
...
@@ -329,6 +350,32 @@ r_object(p)
return
newfloatobject
(
atof
(
buf
));
return
newfloatobject
(
atof
(
buf
));
}
}
#ifndef WITHOUT_COMPLEX
case
TYPE_COMPLEX
:
{
extern
double
atof
PROTO
((
const
char
*
));
char
buf
[
256
];
complex
c
;
n
=
r_byte
(
p
);
if
(
r_string
(
buf
,
(
int
)
n
,
p
)
!=
n
)
{
err_setstr
(
EOFError
,
"EOF read where object expected"
);
return
NULL
;
}
buf
[
n
]
=
'\0'
;
c
.
real
=
atof
(
buf
);
n
=
r_byte
(
p
);
if
(
r_string
(
buf
,
(
int
)
n
,
p
)
!=
n
)
{
err_setstr
(
EOFError
,
"EOF read where object expected"
);
return
NULL
;
}
buf
[
n
]
=
'\0'
;
c
.
imag
=
atof
(
buf
);
return
newcomplexobject
(
c
);
}
#endif
case
TYPE_STRING
:
case
TYPE_STRING
:
n
=
r_long
(
p
);
n
=
r_long
(
p
);
v
=
newsizedstringobject
((
char
*
)
NULL
,
n
);
v
=
newsizedstringobject
((
char
*
)
NULL
,
n
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment