From b4e274b293918203f8dadbb2b1951d5881c2e08c Mon Sep 17 00:00:00 2001 From: DhruvArvindSingh Date: Mon, 6 Jan 2025 21:51:26 +0000 Subject: [PATCH] refactor: update math/base/assert/is-infinite native addon from C++ to C --- 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: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - 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 --- --- .../math/base/assert/is-infinite/include.gypi | 2 +- .../base/assert/is-infinite/manifest.json | 108 ++++++++++++------ .../math/base/assert/is-infinite/src/addon.c | 41 +++++++ .../base/assert/is-infinite/src/addon.cpp | 80 ------------- .../math/base/assert/is-infinite/test/test.js | 24 ---- 5 files changed, 112 insertions(+), 143 deletions(-) create mode 100644 lib/node_modules/@stdlib/math/base/assert/is-infinite/src/addon.c delete mode 100644 lib/node_modules/@stdlib/math/base/assert/is-infinite/src/addon.cpp diff --git a/lib/node_modules/@stdlib/math/base/assert/is-infinite/include.gypi b/lib/node_modules/@stdlib/math/base/assert/is-infinite/include.gypi index ffd7702dc420..de5f9994b817 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-infinite/include.gypi +++ b/lib/node_modules/@stdlib/math/base/assert/is-infinite/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); + STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 ); + STDLIB_NAPI_CREATE_INT32( env, stdlib_base_is_infinite( x ), out ); + return out; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/math/base/assert/is-infinite/src/addon.cpp b/lib/node_modules/@stdlib/math/base/assert/is-infinite/src/addon.cpp deleted file mode 100644 index 8116723b1a31..000000000000 --- a/lib/node_modules/@stdlib/math/base/assert/is-infinite/src/addon.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 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/assert/is_infinite.h" -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_math_base_assert_is_infinite { - - /** - * Tests if a double-precision floating-point numeric value is infinite. - * - * ## Notes - * - * - When called from JavaScript, the function expects one argument: - * - * - `x`: a number - */ - napi_value node_is_infinite( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 1; - napi_value argv[ 1 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 1 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide a number." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - - napi_value v; - double x; - if ( vtype0 == napi_number ) { - status = napi_get_value_double( env, argv[ 0 ], &x ); - assert( status == napi_ok ); - - status = napi_create_int32( env, (int32_t)stdlib_base_is_infinite( x ), &v ); - assert( status == napi_ok ); - } else { - status = napi_create_int32( env, 0, &v ); - assert( status == napi_ok ); - } - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_is_infinite, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_math_base_assert_is_infinite diff --git a/lib/node_modules/@stdlib/math/base/assert/is-infinite/test/test.js b/lib/node_modules/@stdlib/math/base/assert/is-infinite/test/test.js index 60033968c3cc..426335ddd715 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-infinite/test/test.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-infinite/test/test.js @@ -43,27 +43,3 @@ tape( 'the function returns `true` if provided `-infinity`', function test( t ) t.equal( isInfinite( NINF ), true, 'returns true' ); t.end(); }); - -tape( 'the function returns `false` if not provided an infinite number', function test( t ) { - var values; - var i; - - values = [ - '5', - 5.0, - -1.0e308, - 4.0e-324, - NaN, - true, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( isInfinite( values[i] ), false, 'returns false' ); - } - t.end(); -});