Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
8ce36643
Commit
8ce36643
authored
Apr 11, 2020
by
dearblue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Supports width specifier with `mrb_float_to_str()`
Based on src/stdio/vfprintf.c in
git://git.musl-libc.org/musl
parent
ccd84851
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
src/fmt_fp.c
src/fmt_fp.c
+18
-14
No files found.
src/fmt_fp.c
View file @
8ce36643
...
@@ -92,7 +92,7 @@ typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long double)
...
@@ -92,7 +92,7 @@ typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long double)
#endif
#endif
static
int
static
int
fmt_fp
(
struct
fmt_args
*
f
,
long
double
y
,
ptrdiff_t
p
,
uint8_t
fl
,
int
t
)
fmt_fp
(
struct
fmt_args
*
f
,
long
double
y
,
ptrdiff_t
w
,
ptrdiff_t
p
,
uint8_t
fl
,
int
t
)
{
{
uint32_t
big
[(
LDBL_MANT_DIG
+
28
)
/
29
+
1
// mantissa expansion
uint32_t
big
[(
LDBL_MANT_DIG
+
28
)
/
29
+
1
// mantissa expansion
+
(
LDBL_MAX_EXP
+
LDBL_MANT_DIG
+
28
+
8
)
/
9
];
// exponent expansion
+
(
LDBL_MAX_EXP
+
LDBL_MANT_DIG
+
28
+
8
)
/
9
];
// exponent expansion
...
@@ -117,11 +117,11 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
...
@@ -117,11 +117,11 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
if
(
!
isfinite
(
y
))
{
if
(
!
isfinite
(
y
))
{
const
char
*
ss
=
(
t
&
32
)
?
"inf"
:
"INF"
;
const
char
*
ss
=
(
t
&
32
)
?
"inf"
:
"INF"
;
if
(
y
!=
y
)
ss
=
(
t
&
32
)
?
"nan"
:
"NAN"
;
if
(
y
!=
y
)
ss
=
(
t
&
32
)
?
"nan"
:
"NAN"
;
pad
(
f
,
' '
,
0
,
3
+
pl
,
fl
&~
ZERO_PAD
);
pad
(
f
,
' '
,
w
,
3
+
pl
,
fl
&~
ZERO_PAD
);
out
(
f
,
prefix
,
pl
);
out
(
f
,
prefix
,
pl
);
out
(
f
,
ss
,
3
);
out
(
f
,
ss
,
3
);
pad
(
f
,
' '
,
0
,
3
+
pl
,
fl
^
LEFT_ADJ
);
pad
(
f
,
' '
,
w
,
3
+
pl
,
fl
^
LEFT_ADJ
);
return
3
+
(
int
)
pl
;
return
MAX
(
w
,
3
+
(
int
)
pl
)
;
}
}
y
=
frexp
((
double
)
y
,
&
e2
)
*
2
;
y
=
frexp
((
double
)
y
,
&
e2
)
*
2
;
...
@@ -169,14 +169,14 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
...
@@ -169,14 +169,14 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
else
else
l
=
(
s
-
buf
)
+
(
ebuf
-
estr
);
l
=
(
s
-
buf
)
+
(
ebuf
-
estr
);
pad
(
f
,
' '
,
0
,
pl
+
l
,
fl
);
pad
(
f
,
' '
,
w
,
pl
+
l
,
fl
);
out
(
f
,
prefix
,
pl
);
out
(
f
,
prefix
,
pl
);
pad
(
f
,
'0'
,
0
,
pl
+
l
,
fl
^
ZERO_PAD
);
pad
(
f
,
'0'
,
w
,
pl
+
l
,
fl
^
ZERO_PAD
);
out
(
f
,
buf
,
s
-
buf
);
out
(
f
,
buf
,
s
-
buf
);
pad
(
f
,
'0'
,
l
-
(
ebuf
-
estr
)
-
(
s
-
buf
),
0
,
0
);
pad
(
f
,
'0'
,
l
-
(
ebuf
-
estr
)
-
(
s
-
buf
),
0
,
0
);
out
(
f
,
estr
,
ebuf
-
estr
);
out
(
f
,
estr
,
ebuf
-
estr
);
pad
(
f
,
' '
,
0
,
pl
+
l
,
fl
^
LEFT_ADJ
);
pad
(
f
,
' '
,
w
,
pl
+
l
,
fl
^
LEFT_ADJ
);
return
(
int
)
pl
+
(
int
)
l
;
return
MAX
(
w
,
(
int
)
pl
+
(
int
)
l
)
;
}
}
if
(
p
<
0
)
p
=
6
;
if
(
p
<
0
)
p
=
6
;
...
@@ -288,9 +288,9 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
...
@@ -288,9 +288,9 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
l
+=
ebuf
-
estr
;
l
+=
ebuf
-
estr
;
}
}
pad
(
f
,
' '
,
0
,
pl
+
l
,
fl
);
pad
(
f
,
' '
,
w
,
pl
+
l
,
fl
);
out
(
f
,
prefix
,
pl
);
out
(
f
,
prefix
,
pl
);
pad
(
f
,
'0'
,
0
,
pl
+
l
,
fl
^
ZERO_PAD
);
pad
(
f
,
'0'
,
w
,
pl
+
l
,
fl
^
ZERO_PAD
);
if
((
t
|
32
)
==
'f'
)
{
if
((
t
|
32
)
==
'f'
)
{
if
(
a
>
r
)
a
=
r
;
if
(
a
>
r
)
a
=
r
;
...
@@ -325,21 +325,25 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
...
@@ -325,21 +325,25 @@ fmt_fp(struct fmt_args *f, long double y, ptrdiff_t p, uint8_t fl, int t)
out
(
f
,
estr
,
ebuf
-
estr
);
out
(
f
,
estr
,
ebuf
-
estr
);
}
}
pad
(
f
,
' '
,
0
,
pl
+
l
,
fl
^
LEFT_ADJ
);
pad
(
f
,
' '
,
w
,
pl
+
l
,
fl
^
LEFT_ADJ
);
return
(
int
)
pl
+
(
int
)
l
;
return
MAX
(
w
,
(
int
)
pl
+
(
int
)
l
)
;
}
}
static
int
static
int
fmt_core
(
struct
fmt_args
*
f
,
const
char
*
fmt
,
mrb_float
flo
)
fmt_core
(
struct
fmt_args
*
f
,
const
char
*
fmt
,
mrb_float
flo
)
{
{
ptrdiff_t
p
;
ptrdiff_t
w
,
p
;
if
(
*
fmt
!=
'%'
)
{
if
(
*
fmt
!=
'%'
)
{
return
-
1
;
return
-
1
;
}
}
++
fmt
;
++
fmt
;
for
(
w
=
0
;
ISDIGIT
(
*
fmt
);
++
fmt
)
{
w
=
10
*
w
+
(
*
fmt
-
'0'
);
}
if
(
*
fmt
==
'.'
)
{
if
(
*
fmt
==
'.'
)
{
++
fmt
;
++
fmt
;
for
(
p
=
0
;
ISDIGIT
(
*
fmt
);
++
fmt
)
{
for
(
p
=
0
;
ISDIGIT
(
*
fmt
);
++
fmt
)
{
...
@@ -353,7 +357,7 @@ fmt_core(struct fmt_args *f, const char *fmt, mrb_float flo)
...
@@ -353,7 +357,7 @@ fmt_core(struct fmt_args *f, const char *fmt, mrb_float flo)
switch
(
*
fmt
)
{
switch
(
*
fmt
)
{
case
'e'
:
case
'f'
:
case
'g'
:
case
'a'
:
case
'e'
:
case
'f'
:
case
'g'
:
case
'a'
:
case
'E'
:
case
'F'
:
case
'G'
:
case
'A'
:
case
'E'
:
case
'F'
:
case
'G'
:
case
'A'
:
return
fmt_fp
(
f
,
flo
,
p
,
0
,
*
fmt
);
return
fmt_fp
(
f
,
flo
,
w
,
p
,
0
,
*
fmt
);
default:
default:
return
-
1
;
return
-
1
;
}
}
...
...
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