-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: add number/float16/base/identity
#9425
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
Open
Neerajpathak07
wants to merge
5
commits into
stdlib-js:develop
Choose a base branch
from
Neerajpathak07:float16/base/identity
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add number/float16/base/identity
#9425
Neerajpathak07
wants to merge
5
commits into
stdlib-js:develop
from
Neerajpathak07:float16/base/identity
+545
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
Member
Author
|
@kgryte for the C implementation I was thinking of writing the addon as:- #include "stdlib/number/float16/base/identity.h"
#include "stdlib/number/float64/base/to_float16.h"
#include <node_api.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
/**
* 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 ) {
napi_status status;
// Get callback arguments:
size_t argc = 1;
napi_value argv[ 1 ];
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
assert( status == napi_ok );
// Check whether we were provided the correct number of arguments:
if ( argc < 1 ) {
status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." );
assert( status == napi_ok );
return NULL;
}
if ( argc > 1 ) {
status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." );
assert( status == napi_ok );
return NULL;
}
napi_valuetype vtype0;
status = napi_typeof( env, argv[ 0 ], &vtype0 );
assert( status == napi_ok );
if ( vtype0 != napi_number ) {
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
assert( status == napi_ok );
return NULL;
}
double value;
status = napi_get_value_double( env, argv[ 0 ], &value );
assert( status == napi_ok );
uint16_t out = stdlib_base_float16_identity( stdlib_base_float64_to_float16( value ) );
napi_value v;
status = napi_create_int32( env, (uint16_t)out, &v );
assert( status == napi_ok );
return v;
}
/**
* Initializes a Node-API module.
*
* @param env environment under which the function is invoked
* @param exports exports object
* @return main export
*/
static napi_value init( napi_env env, napi_value exports ) {
napi_value fcn;
napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn );
assert( status == napi_ok );
return fcn;
}
NAPI_MODULE( NODE_GYP_MODULE_NAME, init )Since we do not have macro support for |
Neerajpathak07
commented
Dec 29, 2025
lib/node_modules/@stdlib/number/float16/base/identity/lib/main.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Neeraj Pathak <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Feature
Issue or pull request for adding a new feature.
JavaScript
Issue involves or relates to JavaScript.
Needs Review
A pull request which needs code review.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #none.
Description
This pull request:
number/float16/base/identityRelated 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
{{TODO: add disclosure if applicable}}
@stdlib-js/reviewers