From 020c54359e54e722cb09ab8a5b352a285c6745be Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 7 Sep 2026 18:44:36 +0500 Subject: [PATCH 1/2] feat: add C implementation to number/float64/base/assert/is-almost-same-value --- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - 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: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../assert/is-almost-same-value/README.md | 117 ++++++++++++ .../benchmark/benchmark.native.js | 70 ++++++++ .../is-almost-same-value/benchmark/c/Makefile | 146 +++++++++++++++ .../benchmark/c/benchmark.c | 141 +++++++++++++++ .../assert/is-almost-same-value/binding.gyp | 170 ++++++++++++++++++ .../is-almost-same-value/examples/c/Makefile | 146 +++++++++++++++ .../is-almost-same-value/examples/c/example.c | 56 ++++++ .../assert/is-almost-same-value/include.gypi | 53 ++++++ .../base/assert/is_almost_same_value.h | 41 +++++ .../assert/is-almost-same-value/lib/native.js | 59 ++++++ .../assert/is-almost-same-value/manifest.json | 82 +++++++++ .../assert/is-almost-same-value/package.json | 3 + .../assert/is-almost-same-value/src/Makefile | 70 ++++++++ .../assert/is-almost-same-value/src/addon.c | 45 +++++ .../assert/is-almost-same-value/src/main.c | 48 +++++ .../is-almost-same-value/test/test.native.js | 91 ++++++++++ 16 files changed, 1338 insertions(+) create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/binding.gyp create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/include.gypi create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/include/stdlib/number/float64/base/assert/is_almost_same_value.h create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/lib/native.js create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/manifest.json create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/src/Makefile create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/src/addon.c create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/src/main.c create mode 100644 lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/test/test.native.js diff --git a/lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/README.md b/lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/README.md index a7f64ae35aab..ef0fc086545c 100644 --- a/lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/README.md +++ b/lib/node_modules/@stdlib/number/float64/base/assert/is-almost-same-value/README.md @@ -117,6 +117,123 @@ console.log( bool ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/number/float64/base/assert/is_almost_same_value.h" +``` + +#### stdlib_base_float64_is_almost_same_value( a, b, maxULP ) + +Tests if two double-precision floating-point numbers `a` and `b` are approximately the same value within a specified number of ULPs (units in the last place). + +```c +#include + +bool v = stdlib_base_float64_is_almost_same_value( 1.0, 1.0 + 2.220446049250313e-16, 1 ); +// returns true + +v = stdlib_base_float64_is_almost_same_value( 0.0, -0.0, 0 ); +// returns false +``` + +The function accepts the following arguments: + +- **a**: `[in] double` first input value. +- **b**: `[in] double` second input value. +- **maxULP**: `[in] int32_t` maximum allowed ULP difference. + +```c +bool stdlib_base_float64_is_almost_same_value( const double a, const double b, const int32_t maxULP ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/number/float64/base/assert/is_almost_same_value.h" +#include +#include +#include + +int main( void ) { + const double a[] = { + 5.0, + -2.0, + 0.0, + 0.0/0.0, + 1.0, + 1.0 + 2.220446049250313e-16 + }; + const double b[] = { + 5.0, + 2.0, + -0.0, + 0.0/0.0, + 1.0 + 2.220446049250313e-16, + 1.0 + }; + const int32_t maxULP[] = { + 0, + 1, + 0, + 1, + 1, + 0 + }; + + bool v; + int i; + for ( i = 0; i < 6; i++ ) { + v = stdlib_base_float64_is_almost_same_value( a[ i ], b[ i ], maxULP[ i ] ); + printf( "Almost same value? %s\n", ( v ) ? "True" : "False" ); + } +} +``` + +
+ + + +
+ + +