Skip to content

fix: update math/base/special/tand to match correct reference implementation #5807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 11, 2025
Merged
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
24 changes: 3 additions & 21 deletions lib/node_modules/@stdlib/math/base/special/tand/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

// MODULES //

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


// MAIN //
Expand Down Expand Up @@ -51,23 +49,7 @@ var isInfinite = require( '@stdlib/assert/is-infinite' );
* // returns NaN
*/
function tand( x ) {
var xRad;

if ( isInfinite( x ) ) {
return NaN;
}

if ( isInteger( ( ( x / 90.0 ) - 1.0 ) / 2.0 ) ) {
return Infinity;
}

if ( isInteger( ( x / 90.0 ) / 2.0 ) ) {
return 0.0;
}

xRad = deg2rad( x );

return tan( xRad );
return sind( x ) / cosd( x );
}


Expand Down
18 changes: 6 additions & 12 deletions lib/node_modules/@stdlib/math/base/special/tand/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/math/base/special/deg2rad",
"@stdlib/math/base/special/tan",
"@stdlib/math/base/assert/is-integer",
"@stdlib/math/base/assert/is-infinite"
"@stdlib/math/base/special/sind",
"@stdlib/math/base/special/cosd"
]
},
{
Expand All @@ -54,10 +52,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/deg2rad",
"@stdlib/math/base/special/tan",
"@stdlib/math/base/assert/is-integer",
"@stdlib/math/base/assert/is-infinite"
"@stdlib/math/base/special/sind",
"@stdlib/math/base/special/cosd"
]
},
{
Expand All @@ -71,10 +67,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/deg2rad",
"@stdlib/math/base/special/tan",
"@stdlib/math/base/assert/is-integer",
"@stdlib/math/base/assert/is-infinite"
"@stdlib/math/base/special/sind",
"@stdlib/math/base/special/cosd"
]
}
]
Expand Down
19 changes: 3 additions & 16 deletions lib/node_modules/@stdlib/math/base/special/tand/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
*/

#include "stdlib/math/base/special/tand.h"
#include "stdlib/math/base/special/tan.h"
#include "stdlib/math/base/special/deg2rad.h"
#include "stdlib/math/base/assert/is_integer.h"
#include "stdlib/math/base/assert/is_infinite.h"
#include "stdlib/math/base/special/sind.h"
#include "stdlib/math/base/special/cosd.h"

/**
* Computes the tangent of an angle measured in degrees.
Expand All @@ -33,16 +31,5 @@
* // returns 0.0
*/
double stdlib_base_tand( const double x ) {
double xRad;
if ( stdlib_base_is_infinite( x ) ) {
return 0.0 / 0.0; // NaN
}
if ( stdlib_base_is_integer( ( ( x / 90.0 ) - 1.0 ) / 2.0 ) ) {
return x / 0.0; // Infinity
}
if ( stdlib_base_is_integer( ( x / 90.0 ) / 2.0 ) ) {
return 0.0;
}
xRad = stdlib_base_deg2rad( x );
return stdlib_base_tan( xRad );
return stdlib_base_sind( x ) / stdlib_base_cosd( x );
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/tand/test/fixtures/julia/runner.jl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import JSON

"""
gen( domain, name )
gen( domain, name )

Generate fixture data and write to file.

Expand Down Expand Up @@ -62,9 +62,9 @@ file = @__FILE__;
dir = dirname( file );

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

# Generate fixture data for positive values:
x = range( 1.0, stop = 10.0, length = 1000 );
x = range( 0.0, stop = 180.0, length = 1000 );
gen( x, "positive.json" );
14 changes: 7 additions & 7 deletions lib/node_modules/@stdlib/math/base/special/tand/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tape( 'the function computes the tangent of an angle measured in degrees (negati
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 1.4 * EPS * abs( expected[i] );
tol = 2.0 * EPS * abs( expected[i] );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to increase the tolerance by a little amount, from 1.4 to 2.0

t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
Expand All @@ -84,7 +84,7 @@ tape( 'the function computes the tangent of an angle measured in degrees (positi
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 1.4 * EPS * abs( expected[i] );
tol = 2.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
Expand All @@ -97,13 +97,13 @@ tape( 'if provided a `NaN`, the function returns `NaN`', function test( t ) {
t.end();
});

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

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

tape( 'if provided `180.0`, the function returns `Infinity`', function test( t ) {
var v = tand( 180.0 );
t.equal( v, 0.0, 'returns expected value' );
tape( 'if provided `-90.0`, the function returns `-Infinity`', function test( t ) {
var v = tand( -90.0 );
t.equal( v, NINF, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ tape( 'the function computes the tangent of an angle measured in degrees (negati
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 1.4 * EPS * abs( expected[i] );
tol = 2.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
Expand All @@ -93,7 +93,7 @@ tape( 'the function computes the tangent of an angle measured in degrees (positi
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = 1.4 * EPS * abs( expected[i] );
tol = 2.0 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
Expand All @@ -106,13 +106,13 @@ tape( 'if provided a `NaN`, the function returns `NaN`', opts, function test( t
t.end();
});

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

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

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