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
1e9e7ec4
Commit
1e9e7ec4
authored
Dec 16, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
math: faster, easier to inline IsNaN, IsInf
R=r CC=golang-dev
https://golang.org/cl/180046
parent
d16bc7a9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
+10
-4
bits.go
src/pkg/math/bits.go
+10
-4
No files found.
src/pkg/math/bits.go
View file @
1e9e7ec4
...
...
@@ -29,8 +29,11 @@ func NaN() float64 { return Float64frombits(uvnan) }
// 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
// IEEE 754 says that only NaNs satisfy f != f.
// To avoid the floating-point hardware, could use:
// x := Float64bits(f);
// return uint32(x>>shift)&mask == mask && x != uvinf && x != uvneginf
return
f
!=
f
}
// IsInf returns whether f is an infinity, according to sign.
...
...
@@ -38,8 +41,11 @@ func IsNaN(f float64) (is bool) {
// If sign < 0, IsInf returns whether f is negative infinity.
// If sign == 0, IsInf returns whether f is either infinity.
func
IsInf
(
f
float64
,
sign
int
)
bool
{
x
:=
Float64bits
(
f
)
return
sign
>=
0
&&
x
==
uvinf
||
sign
<=
0
&&
x
==
uvneginf
// Test for infinity by comparing against maximum float.
// To avoid the floating-point hardware, could use:
// x := Float64bits(f);
// return sign >= 0 && x == uvinf || sign <= 0 && x == uvneginf;
return
sign
>=
0
&&
f
>
MaxFloat64
||
sign
<=
0
&&
f
<
-
MaxFloat64
}
// Frexp breaks f into a normalized fraction
...
...
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