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
3630bfbe
Commit
3630bfbe
authored
Nov 05, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gofmt-ify math, expvar, exp/spacewar
R=rsc
http://go/go-review/1018061
parent
e57acdca
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
103 additions
and
106 deletions
+103
-106
pdp1.go
src/pkg/exp/spacewar/pdp1.go
+60
-61
spacewar.go
src/pkg/exp/spacewar/spacewar.go
+20
-20
expvar_test.go
src/pkg/expvar/expvar_test.go
+11
-11
all_test.go
src/pkg/math/all_test.go
+2
-2
bits.go
src/pkg/math/bits.go
+10
-11
unsafe.go
src/pkg/math/unsafe.go
+0
-1
No files found.
src/pkg/exp/spacewar/pdp1.go
View file @
3630bfbe
...
...
@@ -64,11 +64,11 @@ import (
type
Word
uint32
const
mask
=
0777777
;
const
sign
=
0400000
;
const
mask
=
0777777
const
sign
=
0400000
const
(
_
=
iota
;
// 00
_
=
iota
;
// 00
opAND
;
opIOR
;
opXOR
;
...
...
@@ -109,17 +109,17 @@ const (
// The machine calls the Trap method to implement the
// PDP-1 IOT instruction.
type
Trapper
interface
{
Trap
(
y
Word
)
Trap
(
y
Word
)
;
}
// An M represents the machine state of a PDP-1.
// Clients can set Display to install an output device.
type
M
struct
{
AC
,
IO
,
PC
,
OV
Word
;
Mem
[
010000
]
Word
;
Flag
[
7
]
bool
;
Sense
[
7
]
bool
;
Halt
bool
;
AC
,
IO
,
PC
,
OV
Word
;
Mem
[
010000
]
Word
;
Flag
[
7
]
bool
;
Sense
[
7
]
bool
;
Halt
bool
;
}
...
...
@@ -142,8 +142,8 @@ func norm(i Word) Word {
}
type
UnknownInstrError
struct
{
Inst
Word
;
PC
Word
;
Inst
Word
;
PC
Word
;
}
func
(
e
UnknownInstrError
)
String
()
string
{
...
...
@@ -168,9 +168,9 @@ func (m *M) run(inst Word, t Trapper) os.Error {
if
op
<
opSKP
&&
op
!=
opCALJDA
{
for
n
:=
0
;
ib
!=
0
;
n
++
{
if
n
>
07777
{
return
LoopError
(
m
.
PC
-
1
);
return
LoopError
(
m
.
PC
-
1
);
}
ib
=
(
m
.
Mem
[
y
]
>>
12
)
&
1
;
ib
=
(
m
.
Mem
[
y
]
>>
12
)
&
1
;
y
=
m
.
Mem
[
y
]
&
07777
;
}
}
...
...
@@ -190,8 +190,8 @@ func (m *M) run(inst Word, t Trapper) os.Error {
a
=
64
;
}
m
.
Mem
[
a
]
=
m
.
AC
;
m
.
AC
=
(
m
.
OV
<<
17
)
+
m
.
PC
;
m
.
PC
=
a
+
1
;
m
.
AC
=
(
m
.
OV
<<
17
)
+
m
.
PC
;
m
.
PC
=
a
+
1
;
case
opLAC
:
m
.
AC
=
m
.
Mem
[
y
];
case
opLIO
:
...
...
@@ -199,29 +199,29 @@ func (m *M) run(inst Word, t Trapper) os.Error {
case
opDAC
:
m
.
Mem
[
y
]
=
m
.
AC
;
case
opDAP
:
m
.
Mem
[
y
]
=
m
.
Mem
[
y
]
&
0770000
|
m
.
AC
&
07777
;
m
.
Mem
[
y
]
=
m
.
Mem
[
y
]
&
0770000
|
m
.
AC
&
07777
;
case
opDIO
:
m
.
Mem
[
y
]
=
m
.
IO
;
case
opDZM
:
m
.
Mem
[
y
]
=
0
;
case
opADD
:
m
.
AC
+=
m
.
Mem
[
y
];
m
.
OV
=
m
.
AC
>>
18
;
m
.
OV
=
m
.
AC
>>
18
;
m
.
AC
=
norm
(
m
.
AC
);
case
opSUB
:
diffSigns
:=
(
m
.
AC
^
m
.
Mem
[
y
])
>>
17
==
1
;
m
.
AC
+=
m
.
Mem
[
y
]
^
mask
;
m
.
AC
+=
m
.
Mem
[
y
]
^
mask
;
m
.
AC
=
norm
(
m
.
AC
);
if
diffSigns
&&
m
.
Mem
[
y
]
>>
17
==
m
.
AC
>>
17
{
if
diffSigns
&&
m
.
Mem
[
y
]
>>
17
==
m
.
AC
>>
17
{
m
.
OV
=
1
;
}
case
opIDX
:
m
.
AC
=
norm
(
m
.
Mem
[
y
]
+
1
);
m
.
AC
=
norm
(
m
.
Mem
[
y
]
+
1
);
m
.
Mem
[
y
]
=
m
.
AC
;
case
opISP
:
m
.
AC
=
norm
(
m
.
Mem
[
y
]
+
1
);
m
.
AC
=
norm
(
m
.
Mem
[
y
]
+
1
);
m
.
Mem
[
y
]
=
m
.
AC
;
if
m
.
AC
&
sign
==
0
{
if
m
.
AC
&
sign
==
0
{
m
.
PC
++
;
}
case
opSAD
:
...
...
@@ -233,17 +233,17 @@ func (m *M) run(inst Word, t Trapper) os.Error {
m
.
PC
++
;
}
case
opMUS
:
if
m
.
IO
&
1
==
1
{
if
m
.
IO
&
1
==
1
{
m
.
AC
+=
m
.
Mem
[
y
];
m
.
AC
=
norm
(
m
.
AC
)
m
.
AC
=
norm
(
m
.
AC
)
;
}
m
.
IO
=
(
m
.
IO
>>
1
|
m
.
AC
<<
17
)
&
mask
;
m
.
IO
=
(
m
.
IO
>>
1
|
m
.
AC
<<
17
)
&
mask
;
m
.
AC
>>=
1
;
case
opDIS
:
m
.
AC
,
m
.
IO
=
(
m
.
AC
<<
1
|
m
.
IO
>>
17
)
&
mask
,
((
m
.
IO
<<
1
|
m
.
AC
>>
17
)
&
mask
)
^
1
;
if
m
.
IO
&
1
==
1
{
m
.
AC
=
m
.
AC
+
(
m
.
Mem
[
y
]
^
mask
);
m
.
AC
,
m
.
IO
=
(
m
.
AC
<<
1
|
m
.
IO
>>
17
)
&
mask
,
((
m
.
IO
<<
1
|
m
.
AC
>>
17
)
&
mask
)
^
1
;
if
m
.
IO
&
1
==
1
{
m
.
AC
=
m
.
AC
+
(
m
.
Mem
[
y
]
^
mask
);
}
else
{
m
.
AC
=
m
.
AC
+
1
+
m
.
Mem
[
y
];
}
...
...
@@ -251,18 +251,18 @@ func (m *M) run(inst Word, t Trapper) os.Error {
case
opJMP
:
m
.
PC
=
y
;
case
opJSP
:
m
.
AC
=
(
m
.
OV
<<
17
)
+
m
.
PC
;
m
.
AC
=
(
m
.
OV
<<
17
)
+
m
.
PC
;
m
.
PC
=
y
;
case
opSKP
:
cond
:=
y
&
0100
==
0100
&&
m
.
AC
==
0
||
y
&
0200
==
0200
&&
m
.
AC
>>
17
==
0
||
y
&
0400
==
0400
&&
m
.
AC
>>
17
==
1
||
y
&
01000
==
01000
&&
m
.
OV
==
0
||
y
&
02000
==
02000
&&
m
.
IO
>>
17
==
0
||
y
&
7
!=
0
&&
!
m
.
Flag
[
y
&
7
]
||
y
&
070
!=
0
&&
!
m
.
Sense
[(
y
&
070
)
>>
3
]
||
y
&
070
==
010
;
if
(
ib
==
0
)
==
cond
{
cond
:=
y
&
0100
==
0100
&&
m
.
AC
==
0
||
y
&
0200
==
0200
&&
m
.
AC
>>
17
==
0
||
y
&
0400
==
0400
&&
m
.
AC
>>
17
==
1
||
y
&
01000
==
01000
&&
m
.
OV
==
0
||
y
&
02000
==
02000
&&
m
.
IO
>>
17
==
0
||
y
&
7
!=
0
&&
!
m
.
Flag
[
y
&
7
]
||
y
&
070
!=
0
&&
!
m
.
Sense
[(
y
&
070
)
>>
3
]
||
y
&
070
==
010
;
if
(
ib
==
0
)
==
cond
{
m
.
PC
++
;
}
if
y
&
01000
==
01000
{
...
...
@@ -275,41 +275,41 @@ func (m *M) run(inst Word, t Trapper) os.Error {
}
switch
(
inst
>>
9
)
&
017
{
case
001
:
// rotate AC left
m
.
AC
=
(
m
.
AC
<<
1
|
m
.
AC
>>
17
)
&
mask
;
m
.
AC
=
(
m
.
AC
<<
1
|
m
.
AC
>>
17
)
&
mask
;
case
002
:
// rotate IO left
m
.
IO
=
(
m
.
IO
<<
1
|
m
.
IO
>>
17
)
&
mask
;
m
.
IO
=
(
m
.
IO
<<
1
|
m
.
IO
>>
17
)
&
mask
;
case
003
:
// rotate AC and IO left.
w
:=
uint64
(
m
.
AC
)
<<
18
|
uint64
(
m
.
IO
);
w
=
w
<<
1
|
w
>>
35
;
m
.
AC
=
Word
(
w
>>
18
)
&
mask
;
m
.
IO
=
Word
(
w
)
&
mask
;
m
.
AC
=
Word
(
w
>>
18
)
&
mask
;
m
.
IO
=
Word
(
w
)
&
mask
;
case
005
:
// shift AC left (excluding sign bit)
m
.
AC
=
(
m
.
AC
<<
1
|
m
.
AC
>>
17
)
&
mask
&^
sign
|
m
.
AC
&
sign
;
m
.
AC
=
(
m
.
AC
<<
1
|
m
.
AC
>>
17
)
&
mask
&^
sign
|
m
.
AC
&
sign
;
case
006
:
// shift IO left (excluding sign bit)
m
.
IO
=
(
m
.
IO
<<
1
|
m
.
IO
>>
17
)
&
mask
&^
sign
|
m
.
IO
&
sign
;
m
.
IO
=
(
m
.
IO
<<
1
|
m
.
IO
>>
17
)
&
mask
&^
sign
|
m
.
IO
&
sign
;
case
007
:
// shift AC and IO left (excluding AC's sign bit)
w
:=
uint64
(
m
.
AC
)
<<
18
|
uint64
(
m
.
IO
);
w
=
w
<<
1
|
w
>>
35
;
m
.
AC
=
Word
(
w
>>
18
)
&
mask
&^
sign
|
m
.
AC
&
sign
;
m
.
IO
=
Word
(
w
)
&
mask
&^
sign
|
m
.
AC
&
sign
;
m
.
AC
=
Word
(
w
>>
18
)
&
mask
&^
sign
|
m
.
AC
&
sign
;
m
.
IO
=
Word
(
w
)
&
mask
&^
sign
|
m
.
AC
&
sign
;
case
011
:
// rotate AC right
m
.
AC
=
(
m
.
AC
>>
1
|
m
.
AC
<<
17
)
&
mask
;
m
.
AC
=
(
m
.
AC
>>
1
|
m
.
AC
<<
17
)
&
mask
;
case
012
:
// rotate IO right
m
.
IO
=
(
m
.
IO
>>
1
|
m
.
IO
<<
17
)
&
mask
;
m
.
IO
=
(
m
.
IO
>>
1
|
m
.
IO
<<
17
)
&
mask
;
case
013
:
// rotate AC and IO right
w
:=
uint64
(
m
.
AC
)
<<
18
|
uint64
(
m
.
IO
);
w
=
w
>>
1
|
w
<<
35
;
m
.
AC
=
Word
(
w
>>
18
)
&
mask
;
m
.
IO
=
Word
(
w
)
&
mask
;
m
.
AC
=
Word
(
w
>>
18
)
&
mask
;
m
.
IO
=
Word
(
w
)
&
mask
;
case
015
:
// shift AC right (excluding sign bit)
m
.
AC
=
m
.
AC
>>
1
|
m
.
AC
&
sign
;
m
.
AC
=
m
.
AC
>>
1
|
m
.
AC
&
sign
;
case
016
:
// shift IO right (excluding sign bit)
m
.
IO
=
m
.
IO
>>
1
|
m
.
IO
&
sign
;
m
.
IO
=
m
.
IO
>>
1
|
m
.
IO
&
sign
;
case
017
:
// shift AC and IO right (excluding AC's sign bit)
w
:=
uint64
(
m
.
AC
)
<<
18
|
uint64
(
m
.
IO
);
w
=
w
>>
1
;
m
.
AC
=
Word
(
w
>>
18
)
|
m
.
AC
&
sign
;
m
.
IO
=
Word
(
w
)
&
mask
;
m
.
AC
=
Word
(
w
>>
18
)
|
m
.
AC
&
sign
;
m
.
IO
=
Word
(
w
)
&
mask
;
default
:
goto
Unknown
;
}
...
...
@@ -336,7 +336,7 @@ func (m *M) run(inst Word, t Trapper) os.Error {
m
.
PC
--
;
return
HaltError
(
m
.
PC
);
}
switch
i
,
f
:=
y
&
7
,
y
&
010
==
010
;
{
switch
i
,
f
:=
y
&
7
,
y
&
010
==
010
;
{
case
i
==
7
:
for
i
:=
2
;
i
<
7
;
i
++
{
m
.
Flag
[
i
]
=
f
;
...
...
@@ -346,7 +346,7 @@ func (m *M) run(inst Word, t Trapper) os.Error {
}
default
:
Unknown
:
return
UnknownInstrError
{
inst
,
m
.
PC
-
1
};
return
UnknownInstrError
{
inst
,
m
.
PC
-
1
};
}
return
nil
;
}
...
...
@@ -371,15 +371,15 @@ func (m *M) Load(r io.Reader) os.Error {
i
:=
1
;
a
:=
Word
(
0
);
for
;
i
<
len
(
line
)
&&
'0'
<=
line
[
i
]
&&
line
[
i
]
<=
'7'
;
i
++
{
a
=
a
*
8
+
Word
(
line
[
i
]
-
'0'
);
a
=
a
*
8
+
Word
(
line
[
i
]
-
'0'
);
}
if
i
>=
len
(
line
)
||
line
[
i
]
!=
'\t'
||
i
==
1
{
if
i
>=
len
(
line
)
||
line
[
i
]
!=
'\t'
||
i
==
1
{
continue
;
}
v
:=
Word
(
0
);
j
:=
i
;
for
i
++
;
i
<
len
(
line
)
&&
'0'
<=
line
[
i
]
&&
line
[
i
]
<=
'7'
;
i
++
{
v
=
v
*
8
+
Word
(
line
[
i
]
-
'0'
);
v
=
v
*
8
+
Word
(
line
[
i
]
-
'0'
);
}
if
i
==
j
{
continue
;
...
...
@@ -388,4 +388,3 @@ func (m *M) Load(r io.Reader) os.Error {
}
return
nil
;
}
src/pkg/exp/spacewar/spacewar.go
View file @
3630bfbe
...
...
@@ -75,23 +75,23 @@ func quitter(c <-chan bool) {
// instruction 02051.
type
SpacewarPDP1
struct
{
pdp1
.
M
;
nframe
int
;
frameTime
int64
;
ctxt
draw
.
Context
;
dx
,
dy
int
;
screen
draw
.
Image
;
ctl
pdp1
.
Word
;
kc
<-
chan
int
;
colorModel
image
.
ColorModel
;
cmap
[]
image
.
Color
;
pix
[][]
uint8
;
nframe
int
;
frameTime
int64
;
ctxt
draw
.
Context
;
dx
,
dy
int
;
screen
draw
.
Image
;
ctl
pdp1
.
Word
;
kc
<-
chan
int
;
colorModel
image
.
ColorModel
;
cmap
[]
image
.
Color
;
pix
[][]
uint8
;
}
func
min
(
a
,
b
int
)
int
{
if
a
<
b
{
return
a
return
a
;
}
return
b
return
b
;
}
func
(
m
*
SpacewarPDP1
)
Init
(
ctxt
draw
.
Context
)
{
...
...
@@ -116,10 +116,10 @@ func (m *SpacewarPDP1) Init(ctxt draw.Context) {
}
const
(
frameDelay
=
56
*
1e6
;
// 56 ms
frameDelay
=
56
*
1e6
;
// 56 ms
)
var
ctlBits
=
[
...
]
pdp1
.
Word
{
var
ctlBits
=
[
...
]
pdp1
.
Word
{
'f'
:
0000001
,
'd'
:
0000002
,
'a'
:
0000004
,
...
...
@@ -134,10 +134,10 @@ func (m *SpacewarPDP1) Step() os.Error {
if
m
.
PC
==
02051
{
m
.
pollInput
();
m
.
nframe
++
;
if
m
.
nframe
&
1
==
0
{
if
m
.
nframe
&
1
==
0
{
m
.
flush
();
t
:=
time
.
Nanoseconds
();
if
t
>=
m
.
frameTime
+
3
*
frameDelay
{
if
t
>=
m
.
frameTime
+
3
*
frameDelay
{
m
.
frameTime
=
t
;
}
else
{
m
.
frameTime
+=
frameDelay
;
...
...
@@ -154,10 +154,10 @@ func (m *SpacewarPDP1) Step() os.Error {
func
(
m
*
SpacewarPDP1
)
Trap
(
y
pdp1
.
Word
)
{
switch
y
&
077
{
case
7
:
x
:=
int
(
m
.
AC
+
0400000
)
&
0777777
;
y
:=
int
(
m
.
IO
+
0400000
)
&
0777777
;
x
=
x
*
m
.
dx
/
0777777
;
y
=
y
*
m
.
dy
/
0777777
;
x
:=
int
(
m
.
AC
+
0400000
)
&
0777777
;
y
:=
int
(
m
.
IO
+
0400000
)
&
0777777
;
x
=
x
*
m
.
dx
/
0777777
;
y
=
y
*
m
.
dy
/
0777777
;
if
0
<=
x
&&
x
<
m
.
dx
&&
0
<=
y
&&
y
<
m
.
dy
{
n
:=
uint8
(
min
(
int
(
m
.
pix
[
y
][
x
])
+
128
,
255
));
m
.
pix
[
y
][
x
]
=
n
;
...
...
src/pkg/expvar/expvar_test.go
View file @
3630bfbe
...
...
@@ -12,16 +12,16 @@ import (
func
TestInt
(
t
*
testing
.
T
)
{
reqs
:=
NewInt
(
"requests"
);
if
reqs
.
i
!=
0
{
t
.
Errorf
(
"reqs.i = %v, want 4"
,
reqs
.
i
)
t
.
Errorf
(
"reqs.i = %v, want 4"
,
reqs
.
i
)
;
}
if
reqs
!=
Get
(
"requests"
)
.
(
*
Int
)
{
t
.
Errorf
(
"Get() failed."
)
t
.
Errorf
(
"Get() failed."
)
;
}
reqs
.
Add
(
1
);
reqs
.
Add
(
3
);
if
reqs
.
i
!=
4
{
t
.
Errorf
(
"reqs.i = %v, want 4"
,
reqs
.
i
)
t
.
Errorf
(
"reqs.i = %v, want 4"
,
reqs
.
i
)
;
}
if
s
:=
reqs
.
String
();
s
!=
"4"
{
...
...
@@ -32,12 +32,12 @@ func TestInt(t *testing.T) {
func
TestString
(
t
*
testing
.
T
)
{
name
:=
NewString
(
"my-name"
);
if
name
.
s
!=
""
{
t
.
Errorf
(
"name.s = %q, want
\"\"
"
,
name
.
s
)
t
.
Errorf
(
"name.s = %q, want
\"\"
"
,
name
.
s
)
;
}
name
.
Set
(
"Mike"
);
if
name
.
s
!=
"Mike"
{
t
.
Errorf
(
"name.s = %q, want
\"
Mike
\"
"
,
name
.
s
)
t
.
Errorf
(
"name.s = %q, want
\"
Mike
\"
"
,
name
.
s
)
;
}
if
s
:=
name
.
String
();
s
!=
"
\"
Mike
\"
"
{
...
...
@@ -52,10 +52,10 @@ func TestMapCounter(t *testing.T) {
colours
.
Add
(
"red"
,
2
);
colours
.
Add
(
"blue"
,
4
);
if
x
:=
colours
.
m
[
"red"
]
.
(
*
Int
)
.
i
;
x
!=
3
{
t
.
Errorf
(
"colours.m[
\"
red
\"
] = %v, want 3"
,
x
)
t
.
Errorf
(
"colours.m[
\"
red
\"
] = %v, want 3"
,
x
)
;
}
if
x
:=
colours
.
m
[
"blue"
]
.
(
*
Int
)
.
i
;
x
!=
4
{
t
.
Errorf
(
"colours.m[
\"
blue
\"
] = %v, want 4"
,
x
)
t
.
Errorf
(
"colours.m[
\"
blue
\"
] = %v, want 4"
,
x
)
;
}
// colours.String() should be '{"red":3, "blue":4}',
...
...
@@ -63,17 +63,17 @@ func TestMapCounter(t *testing.T) {
s
:=
colours
.
String
();
j
,
ok
,
errtok
:=
json
.
StringToJson
(
s
);
if
!
ok
{
t
.
Errorf
(
"colours.String() isn't valid JSON: %v"
,
errtok
)
t
.
Errorf
(
"colours.String() isn't valid JSON: %v"
,
errtok
)
;
}
if
j
.
Kind
()
!=
json
.
MapKind
{
t
.
Error
(
"colours.String() didn't produce a map."
)
t
.
Error
(
"colours.String() didn't produce a map."
)
;
}
red
:=
j
.
Get
(
"red"
);
if
red
.
Kind
()
!=
json
.
NumberKind
{
t
.
Error
(
"red.Kind() is not a NumberKind."
)
t
.
Error
(
"red.Kind() is not a NumberKind."
)
;
}
if
x
:=
red
.
Number
();
x
!=
3
{
t
.
Error
(
"red = %v, want 3"
,
x
)
t
.
Error
(
"red = %v, want 3"
,
x
)
;
}
}
...
...
src/pkg/math/all_test.go
View file @
3630bfbe
...
...
@@ -5,8 +5,8 @@
package
math_test
import
(
.
"math"
;
"testing"
;
.
"math"
;
"testing"
;
)
var
vf
=
[]
float64
{
...
...
src/pkg/math/bits.go
View file @
3630bfbe
...
...
@@ -5,12 +5,12 @@
package
math
const
(
uvnan
=
0x7FF0000000000001
;
uvinf
=
0x7FF0000000000000
;
uvneginf
=
0xFFF0000000000000
;
mask
=
0x7FF
;
shift
=
64
-
11
-
1
;
bias
=
1022
;
uvnan
=
0x7FF0000000000001
;
uvinf
=
0x7FF0000000000000
;
uvneginf
=
0xFFF0000000000000
;
mask
=
0x7FF
;
shift
=
64
-
11
-
1
;
bias
=
1022
;
)
// Inf returns positive infinity if sign >= 0, negative infinity if sign < 0.
...
...
@@ -32,7 +32,7 @@ func NaN() float64 {
// IsNaN returns whether f is an IEEE 754 ``not-a-number'' value.
func
IsNaN
(
f
float64
)
(
is
bool
)
{
x
:=
Float64bits
(
f
);
return
uint32
(
x
>>
shift
)
&
mask
==
mask
&&
x
!=
uvinf
&&
x
!=
uvneginf
;
return
uint32
(
x
>>
shift
)
&
mask
==
mask
&&
x
!=
uvinf
&&
x
!=
uvneginf
;
}
// IsInf returns whether f is an infinity, according to sign.
...
...
@@ -53,7 +53,7 @@ func Frexp(f float64) (frac float64, exp int) {
return
;
}
x
:=
Float64bits
(
f
);
exp
=
int
((
x
>>
shift
)
&
mask
)
-
bias
;
exp
=
int
((
x
>>
shift
)
&
mask
)
-
bias
;
x
&^=
mask
<<
shift
;
x
|=
bias
<<
shift
;
frac
=
Float64frombits
(
x
);
...
...
@@ -64,7 +64,7 @@ func Frexp(f float64) (frac float64, exp int) {
// It returns frac × 2<sup>exp</sup>.
func
Ldexp
(
frac
float64
,
exp
int
)
float64
{
x
:=
Float64bits
(
frac
);
exp
+=
int
(
x
>>
shift
)
&
mask
;
exp
+=
int
(
x
>>
shift
)
&
mask
;
if
exp
<=
0
{
return
0
;
// underflow
}
...
...
@@ -99,7 +99,6 @@ func Modf(f float64) (int float64, frac float64) {
x
&^=
1
<<
(
64
-
11
-
e
)
-
1
;
}
int
=
Float64frombits
(
x
);
frac
=
f
-
int
;
frac
=
f
-
int
;
return
;
}
src/pkg/math/unsafe.go
View file @
3630bfbe
...
...
@@ -27,4 +27,3 @@ func Float64bits(f float64) uint64 {
func
Float64frombits
(
b
uint64
)
float64
{
return
*
(
*
float64
)(
unsafe
.
Pointer
(
&
b
));
}
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