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
2f4d35ff
Commit
2f4d35ff
authored
Nov 12, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converting uint bits back into floats
R=rsc DELTA=32 (32 added, 0 deleted, 0 changed) OCL=19084 CL=19091
parent
2727abe4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
0 deletions
+32
-0
sys.go
src/cmd/gc/sys.go
+2
-0
sysimport.c
src/cmd/gc/sysimport.c
+2
-0
runtime.c
src/runtime/runtime.c
+28
-0
No files found.
src/cmd/gc/sys.go
View file @
2f4d35ff
...
...
@@ -51,6 +51,8 @@ export func Inf(int) float64; // return signed Inf
export
func
NaN
()
float64
;
// return a NaN
export
func
float32bits
(
float32
)
uint32
;
// raw bits
export
func
float64bits
(
float64
)
uint64
;
// raw bits
export
func
float32frombits
(
uint32
)
float32
;
// raw bits
export
func
float64frombits
(
uint64
)
float64
;
// raw bits
export
func
newmap
(
keysize
int
,
valsize
int
,
keyalg
int
,
valalg
int
,
...
...
src/cmd/gc/sysimport.c
View file @
2f4d35ff
...
...
@@ -41,6 +41,8 @@ char *sysimport =
"export func sys.NaN () (? float64)
\n
"
"export func sys.float32bits (? float32) (? uint32)
\n
"
"export func sys.float64bits (? float64) (? uint64)
\n
"
"export func sys.float32frombits (? uint32) (? float32)
\n
"
"export func sys.float64frombits (? uint64) (? float64)
\n
"
"export func sys.newmap (keysize int, valsize int, keyalg int, valalg int, hint int) (hmap *map[any] any)
\n
"
"export func sys.mapaccess1 (hmap *map[any] any, key any) (val any)
\n
"
"export func sys.mapaccess2 (hmap *map[any] any, key any) (val any, pres bool)
\n
"
...
...
src/runtime/runtime.c
View file @
2f4d35ff
...
...
@@ -204,6 +204,19 @@ float64frombits(uint64 i)
return
u
.
f
;
}
static
float32
float32frombits
(
uint32
i
)
{
// The obvious cast-and-pointer code is technically
// not valid, and gcc miscompiles it. Use a union instead.
union
{
float32
f
;
uint32
i
;
}
u
;
u
.
i
=
i
;
return
u
.
f
;
}
bool
isInf
(
float64
f
,
int32
sign
)
{
...
...
@@ -387,6 +400,21 @@ sys·float64bits(float64 din, uint64 iou)
FLUSH
(
&
iou
);
}
// func float32frombits(uint32) float32; // raw bits to float32
void
sys
·
float32frombits
(
uint32
uin
,
float32
dou
)
{
dou
=
float32frombits
(
uin
);
FLUSH
(
&
dou
);
}
// func float64frombits(uint64) float64; // raw bits to float64
void
sys
·
float64frombits
(
uint64
uin
,
float64
dou
)
{
dou
=
float64frombits
(
uin
);
FLUSH
(
&
dou
);
}
static
int32
argc
;
static
uint8
**
argv
;
...
...
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