diff --git a/lib/node_modules/@stdlib/math/base/special/sin/binding.gyp b/lib/node_modules/@stdlib/math/base/special/sin/binding.gyp new file mode 100644 index 000000000000..c22d32a5e0a9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sin/binding.gyp @@ -0,0 +1,52 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on for the sin function. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + "targets": [ + { + "target_name": "sin-addon", + "sources": [ "addon.c" ], + "include_dirs": [ "include" ], + "cflags_cc": [ "-std=c99" ], + "cflags_cc!": [ "-fno-exceptions" ], + "conditions": [ + ["OS=='linux'", { + "cflags": [ "-O3", "-Wall", "-Wextra" ], + "xcode_settings": { + "GCC_PREPROCESSOR_DEFINITIONS": [ "GNUC" ] + } + }], + ["OS=='mac'", { + "cflags": [ "-O3", "-Wall", "-Wextra" ], + "xcode_settings": { + "OTHER_CFLAGS": [ "-fno-objc-arc" ] + } + }], + ["OS=='win'", { + "cflags": [ "/O2", "/W4" ], + "msvs_settings": { + "VCCLCompilerTool": { "ExceptionHandling": 1 } + } + }] + ] + } + ] +} + diff --git a/lib/node_modules/@stdlib/math/base/special/sin/include.gypi b/lib/node_modules/@stdlib/math/base/special/sin/include.gypi new file mode 100644 index 000000000000..0e949b15c6d5 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sin/include.gypi @@ -0,0 +1,35 @@ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +{ + "variables": { + "src_dir": "./src", + "include_dirs": [ + " +#include + +// Exported function to compute the sine of a number +napi_value Sin(napi_env env, napi_callback_info info) { + + size_t argc = 1; + napi_value args[1]; + double x; + napi_get_cb_info(env, info, &argc, args, NULL, NULL); + napi_get_value_double(env, args[0], &x); + + // Call the stdlib sin function + double result = stdlib_base_sin(x); + + napi_value js_result; + napi_create_double(env, result, &js_result); + + return js_result; +} + + +napi_value Init(napi_env env, napi_value exports) { + //The 'sin' function is hence available for export + napi_property_descriptor desc = { "sin", NULL, Sin, NULL, NULL, NULL, napi_default, NULL }; + napi_define_properties(env, exports, 1, &desc); + + return exports; +} + +// Create a Node.js addon module +NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) + + + diff --git a/lib/node_modules/@stdlib/math/base/special/sin/src/main.c b/lib/node_modules/@stdlib/math/base/special/sin/src/main.c new file mode 100644 index 000000000000..da1d3ee2e417 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/sin/src/main.c @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* ## Notice +* +* The following copyright, license, and long comment were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/k_sin.c}. The implementation follows the original, but has been modified according to project conventions. +* +* ```text +* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. +* +* Developed at SunPro, a Sun Microsystems, Inc. business. +* Permission to use, copy, modify, and distribute this +* software is freely granted, provided that this notice +* is preserved. +* ``` +*/ + +#include "stdlib/math/base/special/kernel_sin.h" +#include +#include + +#define M_PI 3.141592653589793 + +double stdlib_base_sin(const double x) { + + double reduced_x = fmod(x, 2.0 * M_PI); // Here x is reduced to the range [-pi, pi] + if (reduced_x < -M_PI) { + reduced_x += 2.0 * M_PI; + } + else if (reduced_x > M_PI) { + reduced_x -= 2.0 * M_PI; + } + + if (reduced_x < 0) { + return -stdlib_base_kernel_sin(-reduced_x, 0.0); + } + else { + return stdlib_base_kernel_sin(reduced_x, 0.0); + } +} +