Skip to content

fix: update math/base/special/secd to match correct reference implementation #5810

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 4 commits into from
Mar 5, 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
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/secd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ var secd = require( '@stdlib/math/base/special/secd' );
Computes the [secant][secant] of `x` (in degrees).

```javascript
var v = secd( 30 );
var v = secd( 30.0 );
// returns ~1.15

v = secd( 45 );
v = secd( 45.0 );
// returns ~1.41

v = secd( 60 );
v = secd( 60.0 );
// returns ~2.0

v = secd( 90 );
// returns 16331239353195370
v = secd( 90.0 );
// returns Infinity

v = secd( 0 );
v = secd( 0.0 );
// returns 1.0

v = secd( NaN );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@
* @returns secant
*
* @example
* var v = secd( 30 );
* var v = secd( 30.0 );
* // returns ~1.15
*
* @example
* var v = secd( 45 );
* var v = secd( 45.0 );
* // returns ~1.41
*
* @example
* var v = secd( 60 );
* var v = secd( 60.0 );
* // returns ~2.0
*
* @example
* var v = secd( 90 );
* // returns 16331239353195370.0
* var v = secd( 90.0 );
* // returns Infinity
*
* @example
* var v = secd( 0 );
* var v = secd( 0.0 );
* // returns 1.0
*
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import secd = require( './index' );

// The function returns a number...
{
secd( 60 ); // $ExpectType number
secd( 60.0 ); // $ExpectType number
}

// The compiler throws an error if the function is provided a value other than a number...
Expand Down
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/secd/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@
* @example
* var secd = require( '@stdlib/math/base/special/secd' );
*
* var v = secd( 30 );
* var v = secd( 30.0 );
* // returns ~1.15
*
* v = secd( 45 );
* v = secd( 45.0 );
* // returns ~1.41
*
* v = secd( 60 );
* v = secd( 60.0 );
* // returns ~2.0
*
* v = secd( 90 );
* // returns 16331239353195370
* v = secd( 90.0 );
* // returns Infinity
*
* v = secd( 0 );
* v = secd( 0.0 );
* // returns 1.0
*
* v = secd( NaN );
Expand Down
18 changes: 8 additions & 10 deletions lib/node_modules/@stdlib/math/base/special/secd/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

// MODULES //

var cos = require( '@stdlib/math/base/special/cos' );
var deg2rad = require( '@stdlib/math/base/special/deg2rad' );
var cosd = require( '@stdlib/math/base/special/cosd' );


// MAIN //
Expand All @@ -33,32 +32,31 @@ var deg2rad = require( '@stdlib/math/base/special/deg2rad' );
* @returns {number} secant
*
* @example
* var v = secd( 30 );
* var v = secd( 30.0 );
* // returns ~1.15
*
* @example
* var v = secd( 45 );
* var v = secd( 45.0 );
* // returns ~1.41
*
* @example
* var v = secd( 60 );
* var v = secd( 60.0 );
* // returns ~2.0
*
* @example
* var v = secd( 90 );
* // returns 16331239353195370.0
* var v = secd( 90.0 );
* // returns Infinity
*
* @example
* var v = secd( 0 );
* var v = secd( 0.0 );
* // returns 1.0
*
* @example
* var v = secd( NaN );
* // returns NaN
*/
function secd( x ) {
var rad = deg2rad( x );
return 1.0 / cos( rad );
return 1.0 / cosd( x );
}


Expand Down
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/secd/lib/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ var addon = require( './../src/addon.node' );
* @returns {number} secant
*
* @example
* var v = secd( 30 );
* var v = secd( 30.0 );
* // returns ~1.15
*
* @example
* var v = secd( 45 );
* var v = secd( 45.0 );
* // returns ~1.41
*
* @example
* var v = secd( 60 );
* var v = secd( 60.0 );
* // returns ~2.0
*
* @example
* var v = secd( 90 );
* // returns 16331239353195370.0
* var v = secd( 90.0 );
* // returns Infinity
*
* @example
* var v = secd( 0 );
* var v = secd( 0.0 );
* // returns 1.0
*
* @example
Expand Down
9 changes: 3 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/secd/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/math/base/special/deg2rad",
"@stdlib/math/base/special/cos"
"@stdlib/math/base/special/cosd"
]
},
{
Expand All @@ -52,8 +51,7 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/deg2rad",
"@stdlib/math/base/special/cos"
"@stdlib/math/base/special/cosd"
]
},
{
Expand All @@ -67,8 +65,7 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/deg2rad",
"@stdlib/math/base/special/cos"
"@stdlib/math/base/special/cosd"
]
}
]
Expand Down
5 changes: 2 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/secd/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/

#include "stdlib/math/base/special/secd.h"
#include "stdlib/math/base/special/cos.h"
#include "stdlib/math/base/special/deg2rad.h"
#include "stdlib/math/base/special/cosd.h"

/**
* Computes the secant of an angle measured in degrees.
Expand All @@ -31,5 +30,5 @@
* // returns ~1.15
*/
double stdlib_base_secd( const double x ) {
return 1.0 / stdlib_base_cos( stdlib_base_deg2rad( x ) );
return 1.0 / stdlib_base_cosd( x );
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions lib/node_modules/@stdlib/math/base/special/secd/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);

# Positive values:
x = range( 1.0, stop=10.0, length=2003 );
gen( x, "positive.json" );
x = range( -360.0, stop = 0.0, length = 1000 );
gen( x, "negative.json" );

# Negative values:
x = range( -1.0, stop=-10.0, length=2003 );
gen( x, "negative.json" );
x = range( 0.0, stop = 360.0, length = 1000 );
Comment on lines +65 to +69
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing over the period of secd

gen( x, "positive.json" );
19 changes: 16 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/secd/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
var EPS = require( '@stdlib/constants/float64/eps' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var secd = require( './../lib' );


Expand Down Expand Up @@ -58,7 +59,7 @@ tape( 'the function computes the secant of an angle measured in degrees (negativ
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = EPS * abs( expected[i] );
tol = 1.4 * 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.

The tolerance had to be increased slightly from 1.0 to 1.4 for the JS and native tests.

t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
Expand All @@ -82,7 +83,7 @@ tape( 'the function computes the secant of an angle measured in degrees (positiv
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = EPS * abs( expected[i] );
tol = 1.4 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
Expand All @@ -91,6 +92,18 @@ tape( 'the function computes the secant of an angle measured in degrees (positiv

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

tape( 'the function returns `+Infinity` if provided an odd multiple of `90`', function test( t ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also added this test since it was not being checked by the test fixtures.

var v = secd( 90.0 );
t.equal( v, PINF, 'returns expected value' );
v = secd( -90.0 );
t.equal( v, PINF, 'returns expected value' );
v = secd( 270.0 );
t.equal( v, PINF, 'returns expected value' );
v = secd( -270.0 );
t.equal( v, PINF, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
var EPS = require( '@stdlib/constants/float64/eps' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var tryRequire = require( '@stdlib/utils/try-require' );


Expand Down Expand Up @@ -67,7 +68,7 @@ tape( 'the function computes the secant of an angle measured in degrees (negativ
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = EPS * abs( expected[i] );
tol = 1.4 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
Expand All @@ -91,7 +92,7 @@ tape( 'the function computes the secant of an angle measured in degrees (positiv
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
delta = abs( y - expected[i] );
tol = EPS * abs( expected[i] );
tol = 1.4 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
Expand All @@ -100,6 +101,18 @@ tape( 'the function computes the secant of an angle measured in degrees (positiv

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

tape( 'the function returns `+Infinity` if provided an odd multiple of `90`', opts, function test( t ) {
var v = secd( 90.0 );
t.equal( v, PINF, 'returns expected value' );
v = secd( -90.0 );
t.equal( v, PINF, 'returns expected value' );
v = secd( 270.0 );
t.equal( v, PINF, 'returns expected value' );
v = secd( -270.0 );
t.equal( v, PINF, 'returns expected value' );
t.end();
});