-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: add math/base/special/truncbf
#8915
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
base: develop
Are you sure you want to change the base?
feat: add math/base/special/truncbf
#8915
Conversation
- Add C implementation for truncbf (single-precision floating-point rounding) - Add JavaScript wrapper with native addon support - Add comprehensive tests (21 test cases, all passing) - Add benchmarks for C, native, Julia, and JavaScript - Add TypeScript declarations and documentation - Add examples for both C and JavaScript - Implement using stdlib's own pow/trunc functions (no math.h dependency) - Support rounding to n digits in arbitrary base b - Handle all edge cases (NaN, ±0, ±Infinity, base=0) Closes stdlib-js#649
- Replace pow with powf in JavaScript and C implementations - Replace trunc with truncf in JavaScript and C implementations - Update variable types from double to float in C code - Update manifest.json dependencies to powf and truncf - Ensures proper single-precision floating-point operations throughout
- Add runtime dependencies (powf, truncf, is-nanf, is-infinitef, float64-to-float32) - Add devDependencies for testing (tape, istanbul, tap-min, constants, abs)
- Add detailed parameter specifications with example values (20 per param) - Add domain definitions and random value generators - Add proper schema version (math/[email protected]) - Include base_alias (truncb) and alias (truncbf) fields - Add test configuration (hermitian: false, symmetric: false) - Complete metadata for automated tooling and documentation
- Revert C code to use pow/trunc (powf/truncf headers not available in build) - Use double precision internally, cast final result to float32 - Fix TypeScript doc examples to show actual float32 precision values - Update manifest.json dependencies back to pow/trunc - Add Apache-2.0 license headers to binding.gyp and include.gypi Fixes: - Compilation errors (missing powf.h, truncf.h) - TypeScript lint errors (incorrect expected values) - License header lint errors
…ry-manifest for dependency resolution
…t values for float32 precision, remove duplicate keyword
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "stdlib/math/base/special/truncbf.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to manually do argument munging. You can use an existing macro. E.g., https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/napi/ternary#stdlib_math_base_napi_module_dii_d-fcn-
| #include "stdlib/math/base/special/pow.h" | ||
| #include "stdlib/math/base/special/trunc.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to use single-precision packages.
| "task": "build", | ||
| "wasm": false, | ||
| "src": [ | ||
| "./src/main.c", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to study other packages to see what gets counted as source and what doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah Sure, i will do it.
…le values in package.json
Coverage Report
The above coverage report was generated for the changes in this PR. |
…n.c, NAPI macro in addon.c, and proper manifest.json
…n.c, NAPI macro in addon.c, and proper manifest.json
|
@kgryte I have addressed all your feedback:
Additionally, I fixed the benchmarks to use |
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Resolves a part of #649
Description
This pull request:
@stdlib/math/base/special/truncbf.The package computes the value of a single-precision floating-point number rounded toward zero to
ndigits in an arbitrary baseb.Implementation Details
Function Signature
Algorithm
The implementation uses the following formula:
It leverages the recently added C implementations of powf (for scaling) and truncf (for truncation) to ensure single-precision accuracy.
Examples
Related Issues
This pull request has the following related issues:
Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
@stdlib-js/reviewers