diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/binding.gyp b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/binding.gyp new file mode 100644 index 000000000000..dda7e38044e5 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/binding.gyp @@ -0,0 +1,71 @@ +# @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. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + // Define the targets for building the add-on + "targets": [ + { + // Name of the target + "target_name": "uint32-sqrt-addon", + + // Source files required for building the add-on + "sources": [ "src/main.c", "src/addon.c" ], + + // Directory containing header files + "include_dirs": [ "src" ], + + // C compiler flags + "cflags_cc": [ "-std=c99" ], + + // Exclude exception handling flags + "cflags_cc!": [ "-fno-exceptions" ], + + // Conditions based on the host OS + "conditions": [ + // Linux-specific compiler flags + ["OS=='linux'", { + "cflags": [ "-O3", "-Wall", "-Wextra" ], + "xcode_settings": { + "GCC_PREPROCESSOR_DEFINITIONS": [ "GNUC" ] + } + }], + + // macOS-specific compiler flags + ["OS=='mac'", { + "cflags": [ "-O3", "-Wall", "-Wextra" ], + "xcode_settings": { + "OTHER_CFLAGS": [ "-fno-objc-arc" ] + } + }], + + // Windows-specific compiler flags + ["OS=='win'", { + "cflags": [ "/O2", "/W4" ], + "msvs_settings": { + "VCCLCompilerTool": { "ExceptionHandling": 1 } + } + }] + ] + } + ] +} + + ] +} diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/include.gypi b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/include.gypi new file mode 100644 index 000000000000..0bf4c11160c8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/include.gypi @@ -0,0 +1,19 @@ +{ + "variables": { + "src_dir": "./src", + "include_dirs": [ + " + +/** +* Computes the integer square root of a 32-bit unsigned integer. +*/ +uint32_t stdlib_base_fast_uint32_sqrt( uint32_t x ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_SPECIAL_FAST_UINT32_SQRT_H diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/manifest.json b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/manifest.json new file mode 100644 index 000000000000..482f4090f14c --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/manifest.json @@ -0,0 +1,27 @@ +{ + "name": "uint32-sqrt", + "version": "1.0.0", + "description": "A Node.js native add-on for computing the integer square root of a 32-bit unsigned integer.", + "keywords": [ + "stdlib", + "math", + "base", + "special", + "fast", + "uint32-sqrt" + ], + "repository": { + "type": "git", + "url": "https://github.com/your-username/uint32-sqrt" + }, + "author": "Your Name", + "license": "Apache-2.0", + "include": [ + "./src" + ], + "src": [ + "./src/addon.c" + ], + "libraries": [], + "libpath": [] +} diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/src/Makefile b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/src/Makefile new file mode 100644 index 000000000000..3a75e9ab9a62 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/src/Makefile @@ -0,0 +1,48 @@ +#/ +# @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 # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/src/addon.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/src/addon.c new file mode 100644 index 000000000000..046c1a4ab0f8 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/src/addon.c @@ -0,0 +1,36 @@ +/** +* @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/fast/uint32-sqrt.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv_uint32.h" +#include +#include + +static napi_value addon(napi_env env, napi_callback_info info) { + STDLIB_NAPI_ARGV(env, info, argv, argc, 1); + STDLIB_NAPI_ARGV_UINT32(env, value, argv, 0); + + napi_value v; + napi_status status = napi_create_uint32(env, stdlib_base_fast_uint32_sqrt(value), &v); + assert(status == napi_ok); + + return v; +} + +STDLIB_NAPI_MODULE( stdlib_base_fast_uint32_sqrt, addon ) diff --git a/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/src/main.c b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/src/main.c new file mode 100644 index 000000000000..c63d0c1d6106 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/fast/uint32-sqrt/src/main.c @@ -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. +*/ + +#include "stdlib/math/base/special/fast/uint32_sqrt.h" +#include + +uint32_t stdlib_base_fast_uint32_sqrt(uint32_t x) { + uint32_t root = 0; + uint32_t bit = 1 << 30; // Set the second most significant bit + + // Adjust the initial bit + while (bit > x) { + bit >>= 2; + } + + // Perform a digit-by-digit computation + while (bit != 0) { + uint32_t sum = root + bit; + root >>= 1; + if (x >= sum) { + x -= sum; + root += bit; + } + bit >>= 2; + } + + return root; +}