Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
9038de03
Commit
9038de03
authored
Jun 30, 2010
by
Charles L. Dorian
Committed by
Russ Cox
Jun 30, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmath: correct IsNaN for argument cmplx(Inf, NaN)
R=rsc CC=golang-dev
https://golang.org/cl/1705041
parent
47c85ec9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
6 deletions
+38
-6
src/pkg/cmath/cmath_test.go
src/pkg/cmath/cmath_test.go
+32
-4
src/pkg/cmath/isnan.go
src/pkg/cmath/isnan.go
+6
-2
No files found.
src/pkg/cmath/cmath_test.go
View file @
9038de03
...
...
@@ -38,8 +38,7 @@ var vc = []complex128{
// at http://keisan.casio.com/. More exact input values (array vc[], above)
// were obtained by printing them with "%.26f". The answers were calculated
// to 26 digits (by using the "Digit number" drop-down control of each
// calculator). Twenty-six digits were chosen so that the answers would be
// accurate even for a float128 type.
// calculator).
var
abs
=
[]
float64
{
9.2022120669932650313380972e+00
,
...
...
@@ -355,6 +354,28 @@ var vcExpSC = []complex128{
var
expSC
=
[]
complex128
{
NaN
(),
}
var
vcIsNaNSC
=
[]
complex128
{
cmplx
(
math
.
Inf
(
-
1
),
math
.
Inf
(
-
1
)),
cmplx
(
math
.
Inf
(
-
1
),
math
.
NaN
()),
cmplx
(
math
.
NaN
(),
math
.
Inf
(
-
1
)),
cmplx
(
0
,
math
.
NaN
()),
cmplx
(
math
.
NaN
(),
0
),
cmplx
(
math
.
Inf
(
1
),
math
.
Inf
(
1
)),
cmplx
(
math
.
Inf
(
1
),
math
.
NaN
()),
cmplx
(
math
.
NaN
(),
math
.
Inf
(
1
)),
cmplx
(
math
.
NaN
(),
math
.
NaN
()),
}
var
isNaNSC
=
[]
bool
{
false
,
false
,
false
,
true
,
true
,
false
,
false
,
false
,
true
,
}
var
vcLogSC
=
[]
complex128
{
NaN
(),
}
...
...
@@ -432,7 +453,7 @@ func alike(a, b float64) bool {
case
a
!=
a
&&
b
!=
b
:
// math.IsNaN(a) && math.IsNaN(b):
return
true
case
a
==
b
:
return
true
return
math
.
Signbit
(
a
)
==
math
.
Signbit
(
b
)
}
return
false
}
...
...
@@ -454,7 +475,7 @@ func cAlike(a, b complex128) bool {
case
IsNaN
(
a
)
&&
IsNaN
(
b
)
:
return
true
case
a
==
b
:
return
true
return
math
.
Signbit
(
real
(
a
))
==
math
.
Signbit
(
real
(
b
))
&&
math
.
Signbit
(
imag
(
a
))
==
math
.
Signbit
(
imag
(
b
))
}
return
false
}
...
...
@@ -591,6 +612,13 @@ func TestExp(t *testing.T) {
}
}
}
func
TestIsNaN
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
len
(
vcIsNaNSC
);
i
++
{
if
f
:=
IsNaN
(
vcIsNaNSC
[
i
]);
isNaNSC
[
i
]
!=
f
{
t
.
Errorf
(
"IsNaN(%g) = %g, want %g
\n
"
,
vcIsNaNSC
[
i
],
f
,
isNaNSC
[
i
])
}
}
}
func
TestLog
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
len
(
vc
);
i
++
{
if
f
:=
Log
(
vc
[
i
]);
!
cVeryclose
(
log
[
i
],
f
)
{
...
...
src/pkg/cmath/isnan.go
View file @
9038de03
...
...
@@ -6,9 +6,13 @@ package cmath
import
"math"
// IsNaN returns true if either real(x) or imag(x) is NaN.
// IsNaN returns true if either real(x) or imag(x) is NaN
// and neither is an infinity.
func
IsNaN
(
x
complex128
)
bool
{
if
math
.
IsNaN
(
real
(
x
))
||
math
.
IsNaN
(
imag
(
x
))
{
switch
{
case
math
.
IsInf
(
real
(
x
),
0
)
||
math
.
IsInf
(
imag
(
x
),
0
)
:
return
false
case
math
.
IsNaN
(
real
(
x
))
||
math
.
IsNaN
(
imag
(
x
))
:
return
true
}
return
false
...
...
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