Skip to content

Commit c96d02a

Browse files
committed
fix: update the function according to reference implementation
--- 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 2d34cb3 commit c96d02a

File tree

3 files changed

+73
-23
lines changed

3 files changed

+73
-23
lines changed

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

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020

2121
// MODULES //
2222

23-
var cos = require( '@stdlib/math/base/special/cos' );
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 abs = require( '@stdlib/math/base/special/abs' );
28+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
29+
var isInfinite = require( '@stdlib/math/base/assert/is-infinite' );
2730

2831

2932
// MAIN //
@@ -52,18 +55,35 @@ var isInfinite = require( '@stdlib/assert/is-infinite' );
5255
*/
5356
function cosd( x ) {
5457
var xRad;
58+
var rx;
5559

56-
if ( isInfinite( x ) ) {
60+
if (
61+
isInfinite( x ) ||
62+
isnan( x )
63+
) {
5764
return NaN;
5865
}
5966

60-
if ( isInteger( ( ( x / 90.0 ) - 1.0 ) / 2.0 ) ) {
61-
return 0.0;
62-
}
63-
64-
xRad = deg2rad( x );
67+
rx = abs( fmod( x, 360.0 ) );
6568

66-
return cos( xRad );
69+
if ( rx <= 45.0 ) {
70+
xRad = deg2rad( rx );
71+
return kernelCos( xRad, 0.0 );
72+
}
73+
if ( rx < 135.0 ) {
74+
xRad = deg2rad( 90.0-rx );
75+
return kernelSin( xRad, 0.0 );
76+
}
77+
if ( rx <= 225.0 ) {
78+
xRad = deg2rad( 180.0-rx );
79+
return -kernelCos( xRad, 0.0 );
80+
}
81+
if ( rx < 315.0 ) {
82+
xRad = deg2rad( rx-270.0 );
83+
return kernelSin( xRad, 0.0 );
84+
}
85+
xRad = deg2rad( 360.0-rx );
86+
return kernelCos( xRad, 0.0 );
6787
}
6888

6989

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@
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/cos"
43+
"@stdlib/math/base/special/kernel-sin",
44+
"@stdlib/math/base/special/kernel-cos",
45+
"@stdlib/math/base/special/abs",
46+
"@stdlib/math/base/special/fmod"
4447
]
4548
},
4649
{
@@ -54,10 +57,13 @@
5457
"libraries": [],
5558
"libpath": [],
5659
"dependencies": [
57-
"@stdlib/math/base/assert/is-integer",
60+
"@stdlib/math/base/assert/is-nan",
5861
"@stdlib/math/base/assert/is-infinite",
5962
"@stdlib/math/base/special/deg2rad",
60-
"@stdlib/math/base/special/cos"
63+
"@stdlib/math/base/special/kernel-sin",
64+
"@stdlib/math/base/special/kernel-cos",
65+
"@stdlib/math/base/special/abs",
66+
"@stdlib/math/base/special/fmod"
6167
]
6268
},
6369
{
@@ -71,10 +77,13 @@
7177
"libraries": [],
7278
"libpath": [],
7379
"dependencies": [
74-
"@stdlib/math/base/assert/is-integer",
80+
"@stdlib/math/base/assert/is-nan",
7581
"@stdlib/math/base/assert/is-infinite",
7682
"@stdlib/math/base/special/deg2rad",
77-
"@stdlib/math/base/special/cos"
83+
"@stdlib/math/base/special/kernel-sin",
84+
"@stdlib/math/base/special/kernel-cos",
85+
"@stdlib/math/base/special/abs",
86+
"@stdlib/math/base/special/fmod"
7887
]
7988
}
8089
]

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
*/
1818

1919
#include "stdlib/math/base/special/cosd.h"
20-
#include "stdlib/math/base/special/cos.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/abs.h"
24+
#include "stdlib/math/base/special/fmod.h"
25+
#include "stdlib/math/base/assert/is_nan.h"
2326
#include "stdlib/math/base/assert/is_infinite.h"
2427

2528
/**
@@ -34,12 +37,30 @@
3437
*/
3538
double stdlib_base_cosd( const double x ) {
3639
double xRad;
37-
if ( stdlib_base_is_infinite( x ) ) {
40+
double rx;
41+
42+
if ( stdlib_base_is_infinite( x ) || stdlib_base_is_nan( x ) ) {
3843
return 0.0 / 0.0; // NaN
3944
}
40-
if ( stdlib_base_is_integer( ( ( x / 90.0 ) - 1.0 ) / 2.0 ) ) {
41-
return 0.0;
45+
46+
rx = stdlib_base_abs( stdlib_base_fmod( x, 360.0 ) );
47+
48+
if ( rx <= 45.0 ) {
49+
xRad = stdlib_base_deg2rad( rx );
50+
return stdlib_base_kernel_cos( xRad, 0.0 );
51+
}
52+
if ( rx < 135.0 ) {
53+
xRad = stdlib_base_deg2rad( 90.0-rx );
54+
return stdlib_base_kernel_sin( xRad, 0.0 );
55+
}
56+
if ( rx <= 225.0 ) {
57+
xRad = stdlib_base_deg2rad( 180.0-rx );
58+
return -stdlib_base_kernel_cos( xRad, 0.0 );
59+
}
60+
if ( rx < 315.0 ) {
61+
xRad = stdlib_base_deg2rad( rx-270.0 );
62+
return stdlib_base_kernel_sin( xRad, 0.0 );
4263
}
43-
xRad = stdlib_base_deg2rad( x );
44-
return stdlib_base_cos( xRad );
64+
xRad = stdlib_base_deg2rad( 360.0-rx );
65+
return stdlib_base_kernel_cos( xRad, 0.0 );
4566
}

0 commit comments

Comments
 (0)