Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
f49782f0
Commit
f49782f0
authored
Feb 02, 2015
by
Damien George
Browse files
py: Fix cmath.log10; fix printing of complex number with negative imag.
parent
471b2a89
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/modcmath.c
View file @
f49782f0
...
...
@@ -97,7 +97,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log_obj, mp_cmath_log);
STATIC
mp_obj_t
mp_cmath_log10
(
mp_obj_t
z_obj
)
{
mp_float_t
real
,
imag
;
mp_obj_get_complex
(
z_obj
,
&
real
,
&
imag
);
return
mp_obj_new_complex
(
0
.
5
*
MICROPY_FLOAT_C_FUN
(
log10
)(
real
*
real
+
imag
*
imag
),
MICROPY_FLOAT_C_FUN
(
atan2
)(
imag
,
real
));
return
mp_obj_new_complex
(
0
.
5
*
MICROPY_FLOAT_C_FUN
(
log10
)(
real
*
real
+
imag
*
imag
),
0
.
4342944819032518
*
MICROPY_FLOAT_C_FUN
(
atan2
)(
imag
,
real
));
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_cmath_log10_obj
,
mp_cmath_log10
);
...
...
py/objcomplex.c
View file @
f49782f0
...
...
@@ -58,7 +58,10 @@ STATIC void complex_print(void (*print)(void *env, const char *fmt, ...), void *
print
(
env
,
"%sj"
,
buf
);
}
else
{
mp_format_float
(
o
->
real
,
buf
,
sizeof
(
buf
),
'g'
,
7
,
'\0'
);
print
(
env
,
"(%s+"
,
buf
);
print
(
env
,
"(%s"
,
buf
);
if
(
o
->
imag
>=
0
)
{
print
(
env
,
"+"
);
}
mp_format_float
(
o
->
imag
,
buf
,
sizeof
(
buf
),
'g'
,
7
,
'\0'
);
print
(
env
,
"%sj)"
,
buf
);
}
...
...
@@ -69,7 +72,10 @@ STATIC void complex_print(void (*print)(void *env, const char *fmt, ...), void *
print
(
env
,
"%sj"
,
buf
);
}
else
{
sprintf
(
buf
,
"%.16g"
,
(
double
)
o
->
real
);
print
(
env
,
"(%s+"
,
buf
);
print
(
env
,
"(%s"
,
buf
);
if
(
o
->
imag
>=
0
)
{
print
(
env
,
"+"
);
}
sprintf
(
buf
,
"%.16g"
,
(
double
)
o
->
imag
);
print
(
env
,
"%sj)"
,
buf
);
}
...
...
Write
Preview
Supports
Markdown
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