Skip to content

feat: add C implementation for math/base/special/sin #2031

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

Closed
wants to merge 1 commit into from
Closed
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
52 changes: 52 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/sin/binding.gyp
Original file line number Diff line number Diff line change
@@ -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 }
}
}]
]
}
]
}

35 changes: 35 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/sin/include.gypi
Original file line number Diff line number Diff line change
@@ -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": [
"<!@(node -e \"var arr = require('@stdlib/utils/library-manifest')('./manifest.json',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).include; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }\")"
],
"addon_output_dir": "./src",
"src_files": [
"<(src_dir)/addon.c",
"<!@(node -e \"var arr = require('@stdlib/utils/library-manifest')('./manifest.json',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }\")"
],
"libraries": [
"<!@(node -e \"var arr = require('@stdlib/utils/library-manifest')('./manifest.json',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libraries; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }\")"
],
"library_dirs": [
"<!@(node -e \"var arr = require('@stdlib/utils/library-manifest')('./manifest.json',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }\")"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @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.
*/

#ifndef STDLIB_MATH_BASE_SPECIAL_KERNEL_SIN_H
#define STDLIB_MATH_BASE_SPECIAL_KERNEL_SIN_H

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
#ifdef __cplusplus
extern "C" {
#endif

/**
* Computes the sine of a double-precision floating-point number on [-π/4, π/4].
*/
double stdlib_base_kernel_sin( const double x, const double y );

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_MATH_BASE_SPECIAL_KERNEL_SIN_H

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @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.
*/

#ifndef #ifndef STDLIB_MATH_BASE_SPECIAL_SIN_H
#define #ifndef STDLIB_MATH_BASE_SPECIAL_SIN_H

#ifdef __cplusplus
extern "C" {
#endif

double stdlib_base_sin(const double x);

#ifdef __cplusplus
}
#endif

#endif /* SIN_H */
76 changes: 76 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/sin/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "sin",
"version": "1.0.0",
"description": "Node.js addon for computing the sine function.",
"main": "index.js",
"scripts": {
"build": "node-gyp configure build",
"clean": "node-gyp clean"
},
"dependencies": {},
"devDependencies": {
"node-addon-api": "^4.0.6"
},
"options": {
"task": "build"
},
"fields": [
{
"field": "src",
"resolve": true,
"relative": true
},
{
"field": "include",
"resolve": true,
"relative": true
},
{
"field": "libraries",
"resolve": false,
"relative": false
},
{
"field": "libpath",
"resolve": true,
"relative": false
}
],
"confs": [
{
"task": "build",
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": []
},
{
"task": "benchmark",
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": []
},
{
"task": "examples",
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": []
}
]
}
21 changes: 12 additions & 9 deletions lib/node_modules/@stdlib/math/base/special/sin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@stdlib/math/base/special/sin",
"version": "0.0.0",
"description": "Compute the sine of a number.",
"version": "1.0.0",
"description": "Node.js addon for computing the sine function.",
"license": "Apache-2.0",
"author": {
"name": "The Stdlib Authors",
Expand All @@ -14,15 +14,17 @@
}
],
"main": "./lib",
"gypfile": true,
"directories": {
"benchmark": "./benchmark",
"doc": "./docs",
"example": "./examples",
"include": "./include",
"lib": "./lib",
"src": "./src",
"test": "./test"
},
"types": "./docs/types",
"scripts": {},
"homepage": "https://github.com/stdlib-js/stdlib",
"repository": {
"type": "git",
Expand Down Expand Up @@ -53,12 +55,13 @@
"stdmath",
"mathematics",
"math",
"math.sin",
"sin",
"sine",
"trig",
"special functions",
"special",
"function",
"trigonometry",
"radians",
"angle"
"sine",
"sin"
]
}

}
43 changes: 43 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/sin/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## @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 #

CC := gcc
CFLAGS := -std=c99 -pedantic-errors -Wall -Wextra -Werror
LDFLAGS := -lm
TARGET := sin

# src files #

SRC := $(wildcard *.c)
OBJ := $(SRC:.c=.o)

# rules and terminologies #

all: $(TARGET)

$(TARGET): $(OBJ)
$(CC) $(CFLAGS) $(OBJ) -o $(TARGET) $(LDFLAGS)

%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

clean:
rm -f $(OBJ) $(TARGET)

.PHONY: all clean

56 changes: 56 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/sin/src/addon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @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.
*/

#include "stdlib/math/base/special/sin.h"
#include "stdlib/napi/export.h"
#include "stdlib/napi/argv.h"
#include <assert.h>
#include <node_api.h>

// 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)



Loading