@@ -1715,9 +1715,16 @@ func tolerance(a, b, e float32) bool {
1715
1715
}
1716
1716
return d < e
1717
1717
}
1718
- func close (a , b float32 ) bool { return tolerance (a , b , 1e-5 ) } // the number gotten from the cfloat standard. Haskell's Linear package uses 1e-6 for floats
1719
- func veryclose (a , b float32 ) bool { return tolerance (a , b , 1e-6 ) } // from wiki
1720
- func soclose (a , b , e float32 ) bool { return tolerance (a , b , e ) }
1718
+
1719
+ // 5e-1 tolerance
1720
+ func nearby (a , b float32 ) bool { return tolerance (a , b , 5e-1 ) } // for large trig inputs results may be far apart.
1721
+
1722
+ // 1e-5 tolerance
1723
+ func close (a , b float32 ) bool { return tolerance (a , b , 1e-5 ) } // the number gotten from the cfloat standard. Haskell's Linear package uses 1e-6 for floats
1724
+
1725
+ // 1e-6 tolerance
1726
+ func veryclose (a , b float32 ) bool { return tolerance (a , b , 1e-6 ) } // from wiki
1727
+ func thisclose (a , b , e float32 ) bool { return tolerance (a , b , e ) }
1721
1728
func alike (a , b float32 ) bool {
1722
1729
switch {
1723
1730
case IsNaN (a ) && IsNaN (b ):
@@ -2108,7 +2115,7 @@ func TestFrexp(t *testing.T) {
2108
2115
2109
2116
func TestGamma (t * testing.T ) {
2110
2117
for i := 0 ; i < len (vf ); i ++ {
2111
- if f := Gamma (vf [i ]); ! close (gamma [i ], f ) {
2118
+ if f := Gamma (vf [i ]); ! thisclose (gamma [i ], f , 1e-4 ) {
2112
2119
t .Errorf ("Gamma(%g) = %g, want %g" , vf [i ], f , gamma [i ])
2113
2120
}
2114
2121
}
@@ -2154,7 +2161,7 @@ func TestIlogb(t *testing.T) {
2154
2161
2155
2162
func TestJ0 (t * testing.T ) {
2156
2163
for i := 0 ; i < len (vf ); i ++ {
2157
- if f := J0 (vf [i ]); ! soclose (j0 [i ], f , 4e-6 ) {
2164
+ if f := J0 (vf [i ]); ! thisclose (j0 [i ], f , 4e-5 ) {
2158
2165
t .Errorf ("J0(%g) = %g, want %g" , vf [i ], f , j0 [i ])
2159
2166
}
2160
2167
}
@@ -2227,7 +2234,7 @@ func TestLdexp(t *testing.T) {
2227
2234
2228
2235
func TestLgamma (t * testing.T ) {
2229
2236
for i := 0 ; i < len (vf ); i ++ {
2230
- if f , s := Lgamma (vf [i ]); ! close (lgamma [i ].f , f ) || lgamma [i ].i != s {
2237
+ if f , s := Lgamma (vf [i ]); ! thisclose (lgamma [i ].f , f , 1e-4 ) || lgamma [i ].i != s {
2231
2238
t .Errorf ("Lgamma(%g) = %g, %d, want %g, %d" , vf [i ], f , s , lgamma [i ].f , lgamma [i ].i )
2232
2239
}
2233
2240
}
@@ -2334,7 +2341,7 @@ func TestLog2(t *testing.T) {
2334
2341
2335
2342
func TestModf (t * testing.T ) {
2336
2343
for i := 0 ; i < len (vf ); i ++ {
2337
- if f , g := Modf (vf [i ]); ! veryclose (modf [i ][0 ], f ) || ! veryclose (modf [i ][1 ], g ) {
2344
+ if f , g := Modf (vf [i ]); ! veryclose (modf [i ][0 ], f ) || ! thisclose (modf [i ][1 ], g , 1e-4 ) {
2338
2345
t .Errorf ("Modf(%g) = %g, %g, want %g, %g" , vf [i ], f , g , modf [i ][0 ], modf [i ][1 ])
2339
2346
}
2340
2347
}
@@ -2382,7 +2389,7 @@ func TestPow10(t *testing.T) {
2382
2389
2383
2390
func TestRemainder (t * testing.T ) {
2384
2391
for i := 0 ; i < len (vf ); i ++ {
2385
- if f := Remainder (10 , vf [i ]); ! close (remainder [i ], f ) {
2392
+ if f := Remainder (10 , vf [i ]); ! thisclose (remainder [i ], f , 1e-4 ) {
2386
2393
t .Errorf ("Remainder(10, %g) = %g, want %g" , vf [i ], f , remainder [i ])
2387
2394
}
2388
2395
}
@@ -2407,7 +2414,7 @@ func TestSignbit(t *testing.T) {
2407
2414
}
2408
2415
func TestSin (t * testing.T ) {
2409
2416
for i := 0 ; i < len (vf ); i ++ {
2410
- if f := Sin (vf [i ]); ! veryclose (sin [i ], f ) {
2417
+ if f := Sin (vf [i ]); ! close (sin [i ], f ) {
2411
2418
t .Errorf ("Sin(%g) = %g, want %g" , vf [i ], f , sin [i ])
2412
2419
}
2413
2420
}
@@ -2420,7 +2427,7 @@ func TestSin(t *testing.T) {
2420
2427
2421
2428
func TestSincos (t * testing.T ) {
2422
2429
for i := 0 ; i < len (vf ); i ++ {
2423
- if s , c := Sincos (vf [i ]); ! veryclose (sin [i ], s ) || ! veryclose (cos [i ], c ) {
2430
+ if s , c := Sincos (vf [i ]); ! close (sin [i ], s ) || ! close (cos [i ], c ) {
2424
2431
t .Errorf ("Sincos(%g) = %g, %g want %g, %g" , vf [i ], s , c , sin [i ], cos [i ])
2425
2432
}
2426
2433
}
@@ -2440,13 +2447,13 @@ func TestSinh(t *testing.T) {
2440
2447
}
2441
2448
2442
2449
func TestSqrt (t * testing.T ) {
2450
+ const tol = 1e-7
2443
2451
for i := 0 ; i < len (vf ); i ++ {
2444
2452
a := Abs (vf [i ])
2445
- if f := SqrtGo (a ); sqrt [i ] != f {
2453
+ if f := SqrtGo (a ); ! thisclose ( f , sqrt [i ], tol ) {
2446
2454
t .Errorf ("SqrtGo(%g) = %g, want %g" , a , f , sqrt [i ])
2447
2455
}
2448
- a = Abs (vf [i ])
2449
- if f := Sqrt (a ); sqrt [i ] != f {
2456
+ if f := Sqrt (a ); ! thisclose (f , sqrt [i ], tol ) {
2450
2457
t .Errorf ("Sqrt(%g) = %g, want %g" , a , f , sqrt [i ])
2451
2458
}
2452
2459
}
@@ -2462,7 +2469,7 @@ func TestSqrt(t *testing.T) {
2462
2469
2463
2470
func TestTan (t * testing.T ) {
2464
2471
for i := 0 ; i < len (vf ); i ++ {
2465
- if f := Tan (vf [i ]); ! veryclose (tan [i ], f ) {
2472
+ if f := Tan (vf [i ]); ! close (tan [i ], f ) {
2466
2473
t .Errorf ("Tan(%g) = %g, want %g" , vf [i ], f , tan [i ])
2467
2474
}
2468
2475
}
@@ -2517,7 +2524,7 @@ func TestY0(t *testing.T) {
2517
2524
func TestY1 (t * testing.T ) {
2518
2525
for i := 0 ; i < len (vf ); i ++ {
2519
2526
a := Abs (vf [i ])
2520
- if f := Y1 (a ); ! soclose (y1 [i ], f , 2e-14 ) {
2527
+ if f := Y1 (a ); ! close (y1 [i ], f ) {
2521
2528
t .Errorf ("Y1(%g) = %g, want %g" , a , f , y1 [i ])
2522
2529
}
2523
2530
}
@@ -2557,7 +2564,7 @@ func TestLargeCos(t *testing.T) {
2557
2564
for i := 0 ; i < len (vf ); i ++ {
2558
2565
f1 := cosLarge [i ]
2559
2566
f2 := Cos (vf [i ] + large )
2560
- if ! close (f1 , f2 ) {
2567
+ if ! nearby (f1 , f2 ) {
2561
2568
t .Errorf ("Cos(%g) = %g, want %g" , vf [i ]+ large , f2 , f1 )
2562
2569
}
2563
2570
}
@@ -2568,7 +2575,7 @@ func TestLargeSin(t *testing.T) {
2568
2575
for i := 0 ; i < len (vf ); i ++ {
2569
2576
f1 := sinLarge [i ]
2570
2577
f2 := Sin (vf [i ] + large )
2571
- if ! close (f1 , f2 ) {
2578
+ if ! nearby (f1 , f2 ) {
2572
2579
t .Errorf ("Sin(%g) = %g, want %g" , vf [i ]+ large , f2 , f1 )
2573
2580
}
2574
2581
}
@@ -2579,7 +2586,7 @@ func TestLargeSincos(t *testing.T) {
2579
2586
for i := 0 ; i < len (vf ); i ++ {
2580
2587
f1 , g1 := sinLarge [i ], cosLarge [i ]
2581
2588
f2 , g2 := Sincos (vf [i ] + large )
2582
- if ! close (f1 , f2 ) || ! close (g1 , g2 ) {
2589
+ if ! nearby (f1 , f2 ) || ! nearby (g1 , g2 ) {
2583
2590
t .Errorf ("Sincos(%g) = %g, %g, want %g, %g" , vf [i ]+ large , f2 , g2 , f1 , g1 )
2584
2591
}
2585
2592
}
@@ -2590,7 +2597,7 @@ func TestLargeTan(t *testing.T) {
2590
2597
for i := 0 ; i < len (vf ); i ++ {
2591
2598
f1 := tanLarge [i ]
2592
2599
f2 := Tan (vf [i ] + large )
2593
- if ! close (f1 , f2 ) {
2600
+ if ! nearby (f1 , f2 ) {
2594
2601
t .Errorf ("Tan(%g) = %g, want %g" , vf [i ]+ large , f2 , f1 )
2595
2602
}
2596
2603
}
0 commit comments