Skip to content

Commit 4f5e835

Browse files
committed
refactor: update sind function to improve modular reduction and edge case handling
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent bd251c3 commit 4f5e835

File tree

6 files changed

+96
-24
lines changed

6 files changed

+96
-24
lines changed

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

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

2121
// MODULES //
2222

23-
var sin = require( '@stdlib/math/base/special/sin' );
2423
var deg2rad = require( '@stdlib/math/base/special/deg2rad' );
25-
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
26-
var isInfinite = require( '@stdlib/assert/is-infinite' );
24+
var kernelSin = require( '@stdlib/math/base/special/kernel-sin' );
25+
var kernelCos = require( '@stdlib/math/base/special/kernel-cos' );
26+
var fmod = require( '@stdlib/math/base/special/fmod' );
27+
var signum = require( '@stdlib/math/base/special/signum' );
28+
var abs = require( '@stdlib/math/base/special/abs' );
29+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
30+
var isInfinite = require( '@stdlib/math/base/assert/is-infinite' );
2731

2832

2933
// MAIN //
@@ -52,17 +56,43 @@ var isInfinite = require( '@stdlib/assert/is-infinite' );
5256
*/
5357
function sind( x ) {
5458
var xRad;
59+
var arx;
60+
var rx;
5561

56-
if ( isInfinite( x ) ) {
62+
if (
63+
isInfinite( x ) ||
64+
isnan( x )
65+
) {
5766
return NaN;
5867
}
5968

60-
if ( isInteger( x / 180.0 ) ) {
69+
rx = fmod( x, 360.0 );
70+
arx = abs( rx );
71+
72+
if ( rx === 0.0 ) {
6173
return 0.0;
6274
}
63-
64-
xRad = deg2rad( x );
65-
return sin( xRad );
75+
if ( arx < 45.0 ) {
76+
xRad = deg2rad( rx );
77+
return kernelSin( xRad, 0.0 );
78+
}
79+
if ( arx <= 135.0 ) {
80+
xRad = deg2rad( 90.0 - arx );
81+
return signum( rx ) * kernelCos( xRad, 0.0 );
82+
}
83+
if ( arx === 180.0 ) {
84+
return signum( rx ) * 0.0;
85+
}
86+
if ( arx < 225.0 ) {
87+
xRad = deg2rad( ( 180.0-arx ) * signum( rx ) );
88+
return kernelSin( xRad, 0.0 );
89+
}
90+
if ( arx <= 315.0 ) {
91+
xRad = deg2rad( 270.0 - arx );
92+
return -signum( rx ) * kernelCos( xRad, 0.0 );
93+
}
94+
xRad = deg2rad( rx - ( 360.0*signum( rx ) ) );
95+
return kernelSin( xRad, 0.0 );
6696
}
6797

6898

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@
3737
"libpath": [],
3838
"dependencies": [
3939
"@stdlib/math/base/napi/unary",
40-
"@stdlib/math/base/assert/is-integer",
40+
"@stdlib/math/base/assert/is-nan",
4141
"@stdlib/math/base/assert/is-infinite",
4242
"@stdlib/math/base/special/deg2rad",
43-
"@stdlib/math/base/special/sin"
43+
"@stdlib/math/base/special/kernel-sin",
44+
"@stdlib/math/base/special/kernel-cos",
45+
"@stdlib/math/base/special/signum",
46+
"@stdlib/math/base/special/abs",
47+
"@stdlib/math/base/special/fmod"
4448
]
4549
},
4650
{
@@ -54,10 +58,14 @@
5458
"libraries": [],
5559
"libpath": [],
5660
"dependencies": [
57-
"@stdlib/math/base/assert/is-integer",
61+
"@stdlib/math/base/assert/is-nan",
5862
"@stdlib/math/base/assert/is-infinite",
5963
"@stdlib/math/base/special/deg2rad",
60-
"@stdlib/math/base/special/sin"
64+
"@stdlib/math/base/special/kernel-sin",
65+
"@stdlib/math/base/special/kernel-cos",
66+
"@stdlib/math/base/special/signum",
67+
"@stdlib/math/base/special/abs",
68+
"@stdlib/math/base/special/fmod"
6169
]
6270
},
6371
{
@@ -71,10 +79,14 @@
7179
"libraries": [],
7280
"libpath": [],
7381
"dependencies": [
74-
"@stdlib/math/base/assert/is-integer",
82+
"@stdlib/math/base/assert/is-nan",
7583
"@stdlib/math/base/assert/is-infinite",
7684
"@stdlib/math/base/special/deg2rad",
77-
"@stdlib/math/base/special/sin"
85+
"@stdlib/math/base/special/kernel-sin",
86+
"@stdlib/math/base/special/kernel-cos",
87+
"@stdlib/math/base/special/signum",
88+
"@stdlib/math/base/special/abs",
89+
"@stdlib/math/base/special/fmod"
7890
]
7991
}
8092
]

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

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
*/
1818

1919
#include "stdlib/math/base/special/sind.h"
20-
#include "stdlib/math/base/special/sin.h"
20+
#include "stdlib/math/base/special/kernel_sin.h"
21+
#include "stdlib/math/base/special/kernel_cos.h"
2122
#include "stdlib/math/base/special/deg2rad.h"
22-
#include "stdlib/math/base/assert/is_integer.h"
23+
#include "stdlib/math/base/special/signum.h"
24+
#include "stdlib/math/base/special/abs.h"
25+
#include "stdlib/math/base/special/fmod.h"
26+
#include "stdlib/math/base/assert/is_nan.h"
2327
#include "stdlib/math/base/assert/is_infinite.h"
2428

2529
/**
@@ -34,12 +38,38 @@
3438
*/
3539
double stdlib_base_sind( const double x ) {
3640
double xRad;
37-
if ( stdlib_base_is_infinite( x ) ) {
41+
double arx;
42+
double rx;
43+
44+
if ( stdlib_base_is_infinite( x ) || stdlib_base_is_nan( x ) ) {
3845
return 0.0 / 0.0; // NaN
3946
}
40-
if ( stdlib_base_is_integer( x / 180.0 ) ) {
47+
48+
rx = stdlib_base_fmod( x, 360.0 );
49+
arx = stdlib_base_abs( rx );
50+
51+
if ( rx == 0.0 ) {
4152
return 0.0;
4253
}
43-
xRad = stdlib_base_deg2rad( x );
44-
return stdlib_base_sin( xRad );
54+
if ( arx < 45.0 ) {
55+
xRad = stdlib_base_deg2rad( rx );
56+
return stdlib_base_kernel_sin( xRad, 0.0 );
57+
}
58+
if ( arx <= 135.0 ) {
59+
xRad = stdlib_base_deg2rad( 90.0 - arx );
60+
return stdlib_base_signum( rx ) * stdlib_base_kernel_cos( xRad, 0.0 );
61+
}
62+
if ( arx == 180.0 ) {
63+
return stdlib_base_signum( rx ) * 0.0;
64+
}
65+
if ( arx < 225.0 ) {
66+
xRad = stdlib_base_deg2rad( ( 180.0-arx ) * stdlib_base_signum( rx ) );
67+
return stdlib_base_kernel_sin( xRad, 0.0 );
68+
}
69+
if ( arx <= 315.0 ) {
70+
xRad = stdlib_base_deg2rad( 270.0 - arx );
71+
return -stdlib_base_signum( rx ) * stdlib_base_kernel_cos( xRad, 0.0 );
72+
}
73+
xRad = stdlib_base_deg2rad( rx - ( 360.0*stdlib_base_signum( rx ) ) );
74+
return stdlib_base_kernel_sin( xRad, 0.0 );
4575
}

lib/node_modules/@stdlib/math/base/special/sind/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/sind/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/sind/test/fixtures/julia/runner.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ file = @__FILE__;
6262
dir = dirname( file );
6363

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

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

0 commit comments

Comments
 (0)