Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/math/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2736,6 +2736,20 @@ func TestJ1(t *testing.T) {
t.Errorf("J1(%g) = %g, want %g", vfj0SC[i], f, j1SC[i])
}
}

// test for https://github.com/golang/go/issues/82101
// J1 is an odd function: J1(-x) = -J1(x).
for _, x := range []float64{SmallestNonzeroFloat64, 1e-30, 1e-9, 1.0 / (1 << 27), 1e-4, 1, 2.5, 1e10} {
if f, g := J1(-x), -J1(x); f != g {
t.Errorf("J1(%g) = %g, want %g", -x, f, g)
}
if f, g := Jn(1, -x), -J1(x); f != g {
t.Errorf("Jn(1, %g) = %g, want %g", -x, f, g)
}
if f, g := Jn(-1, x), -J1(x); f != g {
t.Errorf("Jn(-1, %g) = %g, want %g", x, f, g)
}
}
}

func TestJn(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions src/math/j1.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func J1(x float64) float64 {
return z
}
if x < TwoM27 { // |x|<2**-27
if sign {
return -0.5 * x
}
return 0.5 * x // inexact if x!=0 necessary
}
z := x * x
Expand Down
Loading