Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
b5f45827
Commit
b5f45827
authored
Jan 12, 2014
by
Dave Hylands
Browse files
Added a hacky implementation for %g
parent
fd17921b
Changes
1
Hide whitespace changes
Inline
Side-by-side
stm/printf.c
View file @
b5f45827
...
...
@@ -206,6 +206,21 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
case
'P'
:
// ?
chrs
+=
pfenv_print_int
(
pfenv
,
va_arg
(
args
,
int
),
0
,
16
,
'A'
,
flags
,
width
);
break
;
case
'g'
:
{
// This is a very hacky approach to printing floats. Micropython
// uses %g when using print, and I just wanted to see somthing
// usable. I expect that this will be replaced with something
// more appropriate.
char
dot
=
'.'
;
double
d
=
va_arg
(
args
,
double
);
int
left
=
(
int
)
d
;
int
right
=
(
int
)((
d
-
(
double
)(
int
)
d
)
*
1000000
.
0
);
chrs
+=
pfenv_print_int
(
pfenv
,
left
,
1
,
10
,
'a'
,
flags
,
width
);
chrs
+=
pfenv_print_strn
(
pfenv
,
&
dot
,
1
,
flags
,
width
);
chrs
+=
pfenv_print_int
(
pfenv
,
right
,
0
,
10
,
'a'
,
PF_FLAG_ZERO_PAD
,
6
);
break
;
}
default:
pfenv
->
print_strn
(
pfenv
->
data
,
fmt
,
1
);
chrs
+=
1
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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