Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
0e198da6
Commit
0e198da6
authored
Nov 23, 2008
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix %g 20 -> "2e+01" want "20"
R=r DELTA=11 (10 added, 0 deleted, 1 changed) OCL=19885 CL=19887
parent
a6182dab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
1 deletion
+11
-1
src/lib/strconv/ftoa.go
src/lib/strconv/ftoa.go
+8
-1
src/lib/strconv/ftoa_test.go
src/lib/strconv/ftoa_test.go
+3
-0
No files found.
src/lib/strconv/ftoa.go
View file @
0e198da6
...
...
@@ -94,7 +94,9 @@ func GenericFtoa(bits uint64, fmt byte, prec int, flt *FloatInfo) string {
// Round appropriately.
// Negative precision means "only as much as needed to be exact."
shortest
:=
false
;
if
prec
<
0
{
shortest
=
true
;
RoundShortest
(
d
,
mant
,
exp
,
flt
);
switch
fmt
{
case
'e'
:
...
...
@@ -130,8 +132,13 @@ func GenericFtoa(bits uint64, fmt byte, prec int, flt *FloatInfo) string {
}
// %e is used if the exponent from the conversion
// is less than -4 or greater than or equal to the precision.
// if precision was the shortest possible, use precision 6 for this decision.
eprec
:=
prec
;
if
shortest
{
eprec
=
6
}
exp
:=
d
.
dp
-
1
;
if
exp
<
-
4
||
exp
>=
prec
{
if
exp
<
-
4
||
exp
>=
e
prec
{
return
FmtE
(
neg
,
d
,
prec
-
1
);
}
return
FmtF
(
neg
,
d
,
Max
(
prec
-
d
.
dp
,
0
));
...
...
src/lib/strconv/ftoa_test.go
View file @
0e198da6
...
...
@@ -24,6 +24,9 @@ var ftests = []Test {
Test
{
1
,
'f'
,
5
,
"1.00000"
},
Test
{
1
,
'g'
,
5
,
"1"
},
Test
{
1
,
'g'
,
-
1
,
"1"
},
Test
{
20
,
'g'
,
-
1
,
"20"
},
Test
{
200000
,
'g'
,
-
1
,
"200000"
},
Test
{
2000000
,
'g'
,
-
1
,
"2e+06"
},
Test
{
0
,
'e'
,
5
,
"0.00000e+00"
},
Test
{
0
,
'f'
,
5
,
"0.00000"
},
...
...
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