Skip to content

Conversation

@Neerajpathak07
Copy link
Member

Resolves none.

Description

What is the purpose of this pull request?

This pull request:

  • Adds number/float16/base/to-uint32

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • none

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

{{TODO: add disclosure if applicable}}


@stdlib-js/reviewers

@Neerajpathak07 Neerajpathak07 added the Feature Issue or pull request for adding a new feature. label Dec 21, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Dec 21, 2025

Coverage Report

Package Statements Branches Functions Lines
number/float16/base/to-uint32 $\color{green}129/129$
$\color{green}+0.00%$
$\color{green}3/3$
$\color{green}+0.00%$
$\color{green}1/1$
$\color{green}+0.00%$
$\color{green}129/129$
$\color{green}+0.00%$

The above coverage report was generated for the changes in this PR.

@Neerajpathak07 Neerajpathak07 marked this pull request as ready for review December 21, 2025 18:55
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Dec 21, 2025
@Neerajpathak07
Copy link
Member Author

Not sure why repl is throwing a lint error at this point.

Comment on lines +27 to +61
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( 4294967297.0 ) );
* // returns 0
*
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( 3.14 ) );
* // returns 3
*
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( -3.14 ) );
* // returns 4294967293
*
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( NaN ) );
* // returns 0
*
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( Infinity ) );
* // returns 0
*
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( -Infinity ) );
* // returns 0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( 4294967297.0 ) );
* // returns 0
*
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( 3.14 ) );
* // returns 3
*
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( -3.14 ) );
* // returns 4294967293
*
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( NaN ) );
* // returns 0
*
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( Infinity ) );
* // returns 0
*
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( -Infinity ) );
* // returns 0
* @example
* var float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' );
*
* var y = float16ToUint32( float64ToFloat16( 4294967297.0 ) );
* // returns 0
*
* var y = float16ToUint32( float64ToFloat16( 3.14 ) );
* // returns 3
*
* var y = float16ToUint32( float64ToFloat16( -3.14 ) );
* // returns 4294967293
*
* var y = float16ToUint32( float64ToFloat16( NaN ) );
* // returns 0
*
* var y = float16ToUint32( float64ToFloat16( Infinity ) );
* // returns 0
*
* var y = float16ToUint32( float64ToFloat16( -Infinity ) );
* // returns 0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was wondering if this would be a better way to represent the examples. Keeps the code readable and organized.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly for lib/main.js as well.

Comment on lines +29 to +38
// Generate an array of random numbers:
var f64 = uniform( 100, 0.0, 100.0, {
'dtype': 'float64'
});

// Convert each value to a half-precision floating-point number:
var f16 = map( f64, naryFunction( float64ToFloat16, 1 ) );

// Convert each half-precision floating-point number to the nearest unsigned 32-bit integer:
logEachMap( 'float16: %f => uint32: %d', f16, pickArguments( float16ToUint32, [ 1 ] ) );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created map for half-precision values deriving it from f64 and using the suitable toFloat16 variable.
The recursive way does give out desirable examples in a much smaller time complexity.

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. Needs Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants