Skip to content

Commit 874ec3b

Browse files
fix: update math/base/special/tand to match correct reference implementation
PR-URL: #5807 Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 6b3f9c5 commit 874ec3b

File tree

8 files changed

+31
-68
lines changed

8 files changed

+31
-68
lines changed

lib/node_modules/@stdlib/math/base/special/tand/lib/main.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020

2121
// MODULES //
2222

23-
var tan = require( '@stdlib/math/base/special/tan' );
24-
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
25-
var deg2rad = require( '@stdlib/math/base/special/deg2rad' );
26-
var isInfinite = require( '@stdlib/assert/is-infinite' );
23+
var sind = require( '@stdlib/math/base/special/sind' );
24+
var cosd = require( '@stdlib/math/base/special/cosd' );
2725

2826

2927
// MAIN //
@@ -51,23 +49,7 @@ var isInfinite = require( '@stdlib/assert/is-infinite' );
5149
* // returns NaN
5250
*/
5351
function tand( x ) {
54-
var xRad;
55-
56-
if ( isInfinite( x ) ) {
57-
return NaN;
58-
}
59-
60-
if ( isInteger( ( ( x / 90.0 ) - 1.0 ) / 2.0 ) ) {
61-
return Infinity;
62-
}
63-
64-
if ( isInteger( ( x / 90.0 ) / 2.0 ) ) {
65-
return 0.0;
66-
}
67-
68-
xRad = deg2rad( x );
69-
70-
return tan( xRad );
52+
return sind( x ) / cosd( x );
7153
}
7254

7355

lib/node_modules/@stdlib/math/base/special/tand/manifest.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@
3737
"libpath": [],
3838
"dependencies": [
3939
"@stdlib/math/base/napi/unary",
40-
"@stdlib/math/base/special/deg2rad",
41-
"@stdlib/math/base/special/tan",
42-
"@stdlib/math/base/assert/is-integer",
43-
"@stdlib/math/base/assert/is-infinite"
40+
"@stdlib/math/base/special/sind",
41+
"@stdlib/math/base/special/cosd"
4442
]
4543
},
4644
{
@@ -54,10 +52,8 @@
5452
"libraries": [],
5553
"libpath": [],
5654
"dependencies": [
57-
"@stdlib/math/base/special/deg2rad",
58-
"@stdlib/math/base/special/tan",
59-
"@stdlib/math/base/assert/is-integer",
60-
"@stdlib/math/base/assert/is-infinite"
55+
"@stdlib/math/base/special/sind",
56+
"@stdlib/math/base/special/cosd"
6157
]
6258
},
6359
{
@@ -71,10 +67,8 @@
7167
"libraries": [],
7268
"libpath": [],
7369
"dependencies": [
74-
"@stdlib/math/base/special/deg2rad",
75-
"@stdlib/math/base/special/tan",
76-
"@stdlib/math/base/assert/is-integer",
77-
"@stdlib/math/base/assert/is-infinite"
70+
"@stdlib/math/base/special/sind",
71+
"@stdlib/math/base/special/cosd"
7872
]
7973
}
8074
]

lib/node_modules/@stdlib/math/base/special/tand/src/main.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
*/
1818

1919
#include "stdlib/math/base/special/tand.h"
20-
#include "stdlib/math/base/special/tan.h"
21-
#include "stdlib/math/base/special/deg2rad.h"
22-
#include "stdlib/math/base/assert/is_integer.h"
23-
#include "stdlib/math/base/assert/is_infinite.h"
20+
#include "stdlib/math/base/special/sind.h"
21+
#include "stdlib/math/base/special/cosd.h"
2422

2523
/**
2624
* Computes the tangent of an angle measured in degrees.
@@ -33,16 +31,5 @@
3331
* // returns 0.0
3432
*/
3533
double stdlib_base_tand( const double x ) {
36-
double xRad;
37-
if ( stdlib_base_is_infinite( x ) ) {
38-
return 0.0 / 0.0; // NaN
39-
}
40-
if ( stdlib_base_is_integer( ( ( x / 90.0 ) - 1.0 ) / 2.0 ) ) {
41-
return x / 0.0; // Infinity
42-
}
43-
if ( stdlib_base_is_integer( ( x / 90.0 ) / 2.0 ) ) {
44-
return 0.0;
45-
}
46-
xRad = stdlib_base_deg2rad( x );
47-
return stdlib_base_tan( xRad );
34+
return stdlib_base_sind( x ) / stdlib_base_cosd( x );
4835
}

lib/node_modules/@stdlib/math/base/special/tand/test/fixtures/julia/negative.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lib/node_modules/@stdlib/math/base/special/tand/test/fixtures/julia/positive.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lib/node_modules/@stdlib/math/base/special/tand/test/fixtures/julia/runner.jl

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import JSON
2020

2121
"""
22-
gen( domain, name )
22+
gen( domain, name )
2323
2424
Generate fixture data and write to file.
2525
@@ -62,9 +62,9 @@ file = @__FILE__;
6262
dir = dirname( file );
6363

6464
# Generate fixture data for negative values:
65-
x = range( -1.0, stop = -10.0, length = 1000 );
65+
x = range( -180.0, stop = 0.0, length = 1000 );
6666
gen( x, "negative.json" );
6767

6868
# Generate fixture data for positive values:
69-
x = range( 1.0, stop = 10.0, length = 1000 );
69+
x = range( 0.0, stop = 180.0, length = 1000 );
7070
gen( x, "positive.json" );

lib/node_modules/@stdlib/math/base/special/tand/test/test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ tape( 'the function computes the tangent of an angle measured in degrees (negati
6060
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
6161
} else {
6262
delta = abs( y - expected[i] );
63-
tol = 1.4 * EPS * abs( expected[i] );
63+
tol = 2.0 * EPS * abs( expected[i] );
6464
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
6565
}
6666
}
@@ -84,7 +84,7 @@ tape( 'the function computes the tangent of an angle measured in degrees (positi
8484
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
8585
} else {
8686
delta = abs( y - expected[i] );
87-
tol = 1.4 * EPS * abs( expected[i] );
87+
tol = 2.0 * EPS * abs( expected[i] );
8888
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
8989
}
9090
}
@@ -97,13 +97,13 @@ tape( 'if provided a `NaN`, the function returns `NaN`', function test( t ) {
9797
t.end();
9898
});
9999

100-
tape( 'if provided `+infinity`, the function returns `NaN`', function test( t ) {
100+
tape( 'if provided `+Infinity`, the function returns `NaN`', function test( t ) {
101101
var v = tand( PINF );
102102
t.equal( isnan( v ), true, 'returns expected value' );
103103
t.end();
104104
});
105105

106-
tape( 'if provided `-infinity`, the function returns `NaN`', function test( t ) {
106+
tape( 'if provided `-Infinity`, the function returns `NaN`', function test( t ) {
107107
var v = tand( NINF );
108108
t.equal( isnan( v ), true, 'returns expected value' );
109109
t.end();
@@ -115,8 +115,8 @@ tape( 'if provided `90.0`, the function returns `Infinity`', function test( t )
115115
t.end();
116116
});
117117

118-
tape( 'if provided `180.0`, the function returns `Infinity`', function test( t ) {
119-
var v = tand( 180.0 );
120-
t.equal( v, 0.0, 'returns expected value' );
118+
tape( 'if provided `-90.0`, the function returns `-Infinity`', function test( t ) {
119+
var v = tand( -90.0 );
120+
t.equal( v, NINF, 'returns expected value' );
121121
t.end();
122122
});

lib/node_modules/@stdlib/math/base/special/tand/test/test.native.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ tape( 'the function computes the tangent of an angle measured in degrees (negati
6969
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
7070
} else {
7171
delta = abs( y - expected[i] );
72-
tol = 1.4 * EPS * abs( expected[i] );
72+
tol = 2.0 * EPS * abs( expected[i] );
7373
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
7474
}
7575
}
@@ -93,7 +93,7 @@ tape( 'the function computes the tangent of an angle measured in degrees (positi
9393
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
9494
} else {
9595
delta = abs( y - expected[i] );
96-
tol = 1.4 * EPS * abs( expected[i] );
96+
tol = 2.0 * EPS * abs( expected[i] );
9797
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
9898
}
9999
}
@@ -106,13 +106,13 @@ tape( 'if provided a `NaN`, the function returns `NaN`', opts, function test( t
106106
t.end();
107107
});
108108

109-
tape( 'if provided `+infinity`, the function returns `NaN`', opts, function test( t ) {
109+
tape( 'if provided `+Infinity`, the function returns `NaN`', opts, function test( t ) {
110110
var v = tand( PINF );
111111
t.equal( isnan( v ), true, 'returns expected value' );
112112
t.end();
113113
});
114114

115-
tape( 'if provided `-infinity`, the function returns `NaN`', opts, function test( t ) {
115+
tape( 'if provided `-Infinity`, the function returns `NaN`', opts, function test( t ) {
116116
var v = tand( NINF );
117117
t.equal( isnan( v ), true, 'returns expected value' );
118118
t.end();
@@ -124,8 +124,8 @@ tape( 'if provided `90.0`, the function returns `Infinity`', opts, function test
124124
t.end();
125125
});
126126

127-
tape( 'if provided `180.0`, the function returns `Infinity`', opts, function test( t ) {
128-
var v = tand( 180.0 );
129-
t.equal( v, 0.0, 'returns expected value' );
127+
tape( 'if provided `-90.0`, the function returns `-Infinity`', opts, function test( t ) {
128+
var v = tand( -90.0 );
129+
t.equal( v, NINF, 'returns expected value' );
130130
t.end();
131131
});

0 commit comments

Comments
 (0)