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
788b4175
Commit
788b4175
authored
Mar 06, 2010
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PTAL
R=r CC=golang-dev
https://golang.org/cl/254043
parent
426099f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
65 deletions
+80
-65
format.go
src/pkg/fmt/format.go
+54
-0
print.go
src/pkg/fmt/print.go
+26
-65
No files found.
src/pkg/fmt/format.go
View file @
788b4175
...
...
@@ -420,6 +420,60 @@ func (f *fmt) fmt_G32(v float32) { f.plusSpace(strconv.Ftoa32(v, 'G', doPrec(f,
// fmt_fb32 formats a float32 in the form -123p3 (exponent is power of 2).
func
(
f
*
fmt
)
fmt_fb32
(
v
float32
)
{
f
.
padString
(
strconv
.
Ftoa32
(
v
,
'b'
,
0
))
}
// fmt_c64 formats a complex64 according to its fmt_x argument.
// TODO pass in a method rather than a byte when the compilers mature.
func
(
f
*
fmt
)
fmt_c64
(
v
complex64
,
fmt_x
byte
)
{
f
.
buf
.
WriteByte
(
'('
)
r
:=
real
(
v
)
for
i
:=
0
;
;
i
++
{
switch
fmt_x
{
case
'e'
:
f
.
fmt_e32
(
r
)
case
'E'
:
f
.
fmt_E32
(
r
)
case
'f'
:
f
.
fmt_f32
(
r
)
case
'g'
:
f
.
fmt_g32
(
r
)
case
'G'
:
f
.
fmt_G32
(
r
)
}
if
i
!=
0
{
break
}
f
.
plus
=
true
r
=
imag
(
v
)
}
f
.
buf
.
Write
(
irparenBytes
)
}
// fmt_c128 formats a complex128 according to its fmt_x argument.
// TODO pass in a method rather than a byte when the compilers mature.
func
(
f
*
fmt
)
fmt_c128
(
v
complex128
,
fmt_x
byte
)
{
f
.
buf
.
WriteByte
(
'('
)
r
:=
real
(
v
)
for
i
:=
0
;
;
i
++
{
switch
fmt_x
{
case
'e'
:
f
.
fmt_e64
(
r
)
case
'E'
:
f
.
fmt_E64
(
r
)
case
'f'
:
f
.
fmt_f64
(
r
)
case
'g'
:
f
.
fmt_g64
(
r
)
case
'G'
:
f
.
fmt_G64
(
r
)
}
if
i
!=
0
{
break
}
f
.
plus
=
true
r
=
imag
(
v
)
}
f
.
buf
.
Write
(
irparenBytes
)
}
// float
func
(
x
*
fmt
)
f
(
a
float
)
{
if
strconv
.
FloatSize
==
32
{
...
...
src/pkg/fmt/print.go
View file @
788b4175
...
...
@@ -24,7 +24,7 @@
%o base 8
%x base 16, with lower-case letters for a-f
%X base 16, with upper-case letters for A-F
Floating-point:
Floating-point
and complex constituents
:
%e scientific notation, e.g. -1234.456e+78
%E scientific notation, e.g. -1234.456E+78
%f decimal point but no exponent, e.g. 123.456
...
...
@@ -558,19 +558,19 @@ func (p *pp) printField(field interface{}, plus, sharp bool, depth int) (was_str
p
.
fmt
.
fmt_g64
(
float64
(
f
))
}
return
false
//
case complex64:
// p.fmt.fmt_c64(f
)
//
return false
//
case complex128:
// p.fmt.fmt_c128(f
)
//
return false
//
case complex:
// if complexBits == 128
{
// p.fmt.fmt_c128(complex128(f)
)
//
} else {
// p.fmt.fmt_c64(complex64(f)
)
//
}
//
return false
case
complex64
:
p
.
fmt
.
fmt_c64
(
f
,
'g'
)
return
false
case
complex128
:
p
.
fmt
.
fmt_c128
(
f
,
'g'
)
return
false
case
complex
:
if
complexBits
==
64
{
p
.
fmt
.
fmt_c64
(
complex64
(
f
),
'g'
)
}
else
{
p
.
fmt
.
fmt_c128
(
complex128
(
f
),
'g'
)
}
return
false
case
int
,
int8
,
int16
,
int32
,
int64
,
uint
,
uint8
,
uint16
,
uint32
,
uint64
,
uintptr
:
v
,
signed
,
ok
:=
getInt
(
field
)
if
!
ok
{
...
...
@@ -917,24 +917,17 @@ func (p *pp) doprintf(format string, a []interface{}) {
goto
badtype
}
// float
// float
/complex
case
'e'
:
if
v
,
ok
:=
getFloat32
(
field
);
ok
{
p
.
fmt
.
fmt_e32
(
v
)
}
else
if
v
,
ok
:=
getFloat64
(
field
);
ok
{
p
.
fmt
.
fmt_e64
(
v
)
}
else
if
v
,
ok
:=
getComplex64
(
field
);
ok
{
p
.
buf
.
WriteByte
(
'('
)
p
.
fmt
.
fmt_e32
(
real
(
v
))
p
.
fmt
.
plus
=
true
p
.
fmt
.
fmt_e32
(
imag
(
v
))
p
.
buf
.
Write
(
irparenBytes
)
p
.
fmt
.
fmt_c64
(
v
,
'e'
)
}
else
if
v
,
ok
:=
getComplex128
(
field
);
ok
{
p
.
buf
.
WriteByte
(
'('
)
p
.
fmt
.
fmt_e64
(
real
(
v
))
p
.
fmt
.
plus
=
true
p
.
fmt
.
fmt_e64
(
imag
(
v
))
p
.
buf
.
Write
(
irparenBytes
)
p
.
fmt
.
fmt_c128
(
v
,
'e'
)
}
else
{
goto
badtype
}
...
...
@@ -944,17 +937,9 @@ func (p *pp) doprintf(format string, a []interface{}) {
}
else
if
v
,
ok
:=
getFloat64
(
field
);
ok
{
p
.
fmt
.
fmt_E64
(
v
)
}
else
if
v
,
ok
:=
getComplex64
(
field
);
ok
{
p
.
buf
.
WriteByte
(
'('
)
p
.
fmt
.
fmt_E32
(
real
(
v
))
p
.
fmt
.
plus
=
true
p
.
fmt
.
fmt_E32
(
imag
(
v
))
p
.
buf
.
Write
(
irparenBytes
)
p
.
fmt
.
fmt_c64
(
v
,
'E'
)
}
else
if
v
,
ok
:=
getComplex128
(
field
);
ok
{
p
.
buf
.
WriteByte
(
'('
)
p
.
fmt
.
fmt_E64
(
real
(
v
))
p
.
fmt
.
plus
=
true
p
.
fmt
.
fmt_E64
(
imag
(
v
))
p
.
buf
.
Write
(
irparenBytes
)
p
.
fmt
.
fmt_c128
(
v
,
'E'
)
}
else
{
goto
badtype
}
...
...
@@ -964,17 +949,9 @@ func (p *pp) doprintf(format string, a []interface{}) {
}
else
if
v
,
ok
:=
getFloat64
(
field
);
ok
{
p
.
fmt
.
fmt_f64
(
v
)
}
else
if
v
,
ok
:=
getComplex64
(
field
);
ok
{
p
.
buf
.
WriteByte
(
'('
)
p
.
fmt
.
fmt_f32
(
real
(
v
))
p
.
fmt
.
plus
=
true
p
.
fmt
.
fmt_f32
(
imag
(
v
))
p
.
buf
.
Write
(
irparenBytes
)
p
.
fmt
.
fmt_c64
(
v
,
'f'
)
}
else
if
v
,
ok
:=
getComplex128
(
field
);
ok
{
p
.
buf
.
WriteByte
(
'('
)
p
.
fmt
.
fmt_f64
(
real
(
v
))
p
.
fmt
.
plus
=
true
p
.
fmt
.
fmt_f64
(
imag
(
v
))
p
.
buf
.
Write
(
irparenBytes
)
p
.
fmt
.
fmt_c128
(
v
,
'f'
)
}
else
{
goto
badtype
}
...
...
@@ -984,17 +961,9 @@ func (p *pp) doprintf(format string, a []interface{}) {
}
else
if
v
,
ok
:=
getFloat64
(
field
);
ok
{
p
.
fmt
.
fmt_g64
(
v
)
}
else
if
v
,
ok
:=
getComplex64
(
field
);
ok
{
p
.
buf
.
WriteByte
(
'('
)
p
.
fmt
.
fmt_g32
(
real
(
v
))
p
.
fmt
.
plus
=
true
p
.
fmt
.
fmt_g32
(
imag
(
v
))
p
.
buf
.
Write
(
irparenBytes
)
p
.
fmt
.
fmt_c64
(
v
,
'g'
)
}
else
if
v
,
ok
:=
getComplex128
(
field
);
ok
{
p
.
buf
.
WriteByte
(
'('
)
p
.
fmt
.
fmt_g64
(
real
(
v
))
p
.
fmt
.
plus
=
true
p
.
fmt
.
fmt_g64
(
imag
(
v
))
p
.
buf
.
Write
(
irparenBytes
)
p
.
fmt
.
fmt_c128
(
v
,
'g'
)
}
else
{
goto
badtype
}
...
...
@@ -1004,17 +973,9 @@ func (p *pp) doprintf(format string, a []interface{}) {
}
else
if
v
,
ok
:=
getFloat64
(
field
);
ok
{
p
.
fmt
.
fmt_G64
(
v
)
}
else
if
v
,
ok
:=
getComplex64
(
field
);
ok
{
p
.
buf
.
WriteByte
(
'('
)
p
.
fmt
.
fmt_G32
(
real
(
v
))
p
.
fmt
.
plus
=
true
p
.
fmt
.
fmt_G32
(
imag
(
v
))
p
.
buf
.
Write
(
irparenBytes
)
p
.
fmt
.
fmt_c64
(
v
,
'G'
)
}
else
if
v
,
ok
:=
getComplex128
(
field
);
ok
{
p
.
buf
.
WriteByte
(
'('
)
p
.
fmt
.
fmt_G64
(
real
(
v
))
p
.
fmt
.
plus
=
true
p
.
fmt
.
fmt_G64
(
imag
(
v
))
p
.
buf
.
Write
(
irparenBytes
)
p
.
fmt
.
fmt_c128
(
v
,
'G'
)
}
else
{
goto
badtype
}
...
...
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