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
22f84c5b
Commit
22f84c5b
authored
Apr 27, 2010
by
Charles L. Dorian
Committed by
Russ Cox
Apr 27, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
math: more special cases for signed zero
R=rsc CC=golang-dev
https://golang.org/cl/937042
parent
d6e4e18c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
28 additions
and
12 deletions
+28
-12
all_test.go
src/pkg/math/all_test.go
+0
-0
asin.go
src/pkg/math/asin.go
+6
-2
atan.go
src/pkg/math/atan.go
+7
-0
cbrt.go
src/pkg/math/cbrt.go
+3
-3
fabs.go
src/pkg/math/fabs.go
+4
-1
floor.go
src/pkg/math/floor.go
+2
-2
frexp.go
src/pkg/math/frexp.go
+2
-3
ldexp.go
src/pkg/math/ldexp.go
+4
-1
No files found.
src/pkg/math/all_test.go
View file @
22f84c5b
This diff is collapsed.
Click to expand it.
src/pkg/math/asin.go
View file @
22f84c5b
...
...
@@ -14,16 +14,20 @@ package math
// Asin returns the arcsine of x.
//
// Special case is:
// Special cases are:
// Asin(±0) = ±0
// Asin(x) = NaN if x < -1 or x > 1
func
Asin
(
x
float64
)
float64
{
if
x
==
0
{
return
x
// special case
}
sign
:=
false
if
x
<
0
{
x
=
-
x
sign
=
true
}
if
x
>
1
{
return
NaN
()
return
NaN
()
// special case
}
temp
:=
Sqrt
(
1
-
x
*
x
)
...
...
src/pkg/math/atan.go
View file @
22f84c5b
...
...
@@ -47,7 +47,14 @@ func satan(arg float64) float64 {
}
// Atan returns the arctangent of x.
//
// Special cases are:
// Atan(±0) = ±0
// Atan(±Inf) = ±Pi/2
func
Atan
(
x
float64
)
float64
{
if
x
==
0
{
return
x
}
if
x
>
0
{
return
satan
(
x
)
}
...
...
src/pkg/math/cbrt.go
View file @
22f84c5b
...
...
@@ -15,8 +15,8 @@ package math
// Cbrt returns the cube root of its argument.
//
// Special cases are:
// Exp(
+Inf) = +Inf
// Exp(
-Inf) = -
Inf
// Exp(
±0) = ±0
// Exp(
±Inf) = ±
Inf
// Exp(NaN) = NaN
func
Cbrt
(
x
float64
)
float64
{
const
(
...
...
@@ -37,7 +37,7 @@ func Cbrt(x float64) float64 {
// when compiler does it for us
// special cases
switch
{
case
x
!=
x
||
x
<
-
MaxFloat64
||
x
>
MaxFloat64
:
//
IsNaN(x) || IsInf(x, 0):
case
x
==
0
||
x
!=
x
||
x
<
-
MaxFloat64
||
x
>
MaxFloat64
:
// x == 0 ||
IsNaN(x) || IsInf(x, 0):
return
x
}
sign
:=
false
...
...
src/pkg/math/fabs.go
View file @
22f84c5b
...
...
@@ -11,8 +11,11 @@ package math
// Fabs(-Inf) = +Inf
// Fabs(NaN) = NaN
func
Fabs
(
x
float64
)
float64
{
if
x
<
0
{
switch
{
case
x
<
0
:
return
-
x
case
x
==
0
:
return
0
// return correctly fabs(-0)
}
return
x
}
src/pkg/math/floor.go
View file @
22f84c5b
...
...
@@ -14,7 +14,7 @@ package math
func
Floor
(
x
float64
)
float64
{
// TODO(rsc): Remove manual inlining of IsNaN, IsInf
// when compiler does it for us
if
x
!=
x
||
x
>
MaxFloat64
||
x
<
-
MaxFloat64
{
//
IsNaN(x) || IsInf(x, 0)
if
x
==
0
||
x
!=
x
||
x
>
MaxFloat64
||
x
<
-
MaxFloat64
{
// x == 0 ||
IsNaN(x) || IsInf(x, 0)
return
x
}
if
x
<
0
{
...
...
@@ -45,7 +45,7 @@ func Ceil(x float64) float64 { return -Floor(-x) }
func
Trunc
(
x
float64
)
float64
{
// TODO(rsc): Remove manual inlining of IsNaN, IsInf
// when compiler does it for us
if
x
!=
x
||
x
>
MaxFloat64
||
x
<
-
MaxFloat64
{
//
IsNaN(x) || IsInf(x, 0)
if
x
==
0
||
x
!=
x
||
x
>
MaxFloat64
||
x
<
-
MaxFloat64
{
// x == 0 ||
IsNaN(x) || IsInf(x, 0)
return
x
}
d
,
_
:=
Modf
(
x
)
...
...
src/pkg/math/frexp.go
View file @
22f84c5b
...
...
@@ -14,10 +14,9 @@ func Frexp(f float64) (frac float64, exp int) {
// special cases
switch
{
case
f
==
0
:
return
return
f
,
0
// correctly return -0
case
f
<
-
MaxFloat64
||
f
>
MaxFloat64
||
f
!=
f
:
// IsInf(f, 0) || IsNaN(f):
frac
=
f
return
return
f
,
0
}
x
:=
Float64bits
(
f
)
exp
=
int
((
x
>>
shift
)
&
mask
)
-
bias
...
...
src/pkg/math/ldexp.go
View file @
22f84c5b
...
...
@@ -10,7 +10,10 @@ func Ldexp(frac float64, exp int) float64 {
// TODO(rsc): Remove manual inlining of IsNaN, IsInf
// when compiler does it for us
// special cases
if
frac
!=
frac
{
// IsNaN(frac)
switch
{
case
frac
==
0
:
return
frac
// correctly return -0
case
frac
!=
frac
:
// IsNaN(frac):
return
NaN
()
}
x
:=
Float64bits
(
frac
)
...
...
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