Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
ac5a887d
Commit
ac5a887d
authored
Jul 05, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
floating point print
SVN=126038
parent
b0273023
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
1 deletion
+57
-1
print.c
src/runtime/print.c
+57
-1
No files found.
src/runtime/print.c
View file @
ac5a887d
...
@@ -49,7 +49,63 @@ sys·printbool(bool v)
...
@@ -49,7 +49,63 @@ sys·printbool(bool v)
void
void
sys
·
printfloat
(
float64
v
)
sys
·
printfloat
(
float64
v
)
{
{
sys
·
write
(
1
,
"printfloat"
,
10
);
byte
buf
[
20
];
int32
e
,
s
,
i
,
n
;
float64
h
;
n
=
5
;
// digits printed
e
=
0
;
// exp
s
=
0
;
// sign
if
(
v
!=
0
)
{
// sign
if
(
v
<
0
)
{
v
=
-
v
;
s
=
1
;
}
// normalize
while
(
v
>=
10
)
{
e
++
;
v
/=
10
;
}
while
(
v
<
1
)
{
e
--
;
v
*=
10
;
}
// round
h
=
5
;
for
(
i
=
0
;
i
<
n
;
i
++
)
h
/=
10
;
v
+=
h
;
if
(
v
>=
10
)
{
e
++
;
v
/=
10
;
}
}
// format +d.dddd+edd
buf
[
0
]
=
'+'
;
if
(
s
)
buf
[
0
]
=
'-'
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
s
=
v
;
buf
[
i
+
2
]
=
s
+
'0'
;
v
-=
s
;
v
*=
10
.;
}
buf
[
1
]
=
buf
[
2
];
buf
[
2
]
=
'.'
;
buf
[
n
+
2
]
=
'+'
;
if
(
e
<
0
)
{
e
=
-
e
;
buf
[
n
+
2
]
=
'-'
;
}
buf
[
n
+
3
]
=
'e'
;
buf
[
n
+
4
]
=
(
e
/
10
)
+
'0'
;
buf
[
n
+
5
]
=
(
e
%
10
)
+
'0'
;
sys
·
write
(
1
,
buf
,
n
+
6
);
}
}
void
void
...
...
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