Socket
Socket
Sign inDemoInstall

@stdlib/number-float64-base-to-words

Package Overview
Dependencies
79
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.6 to 0.0.7

lib/assign.js

42

docs/repl.txt
{{alias}}( [out,] x )
{{alias}}( x )
Splits a double-precision floating-point number into a higher order word

@@ -13,5 +13,2 @@ (unsigned 32-bit integer) and a lower order word (unsigned 32-bit integer).

----------
out: Array|TypedArray|Object (optional)
Output array.
x: number

@@ -22,3 +19,3 @@ Double-precision floating-point number.

-------
out: Array|TypedArray|Object
out: Array<integer>
Higher and lower order words.

@@ -31,5 +28,36 @@

// Provide an output array:
{{alias}}.assign( x, out, stride, offset )
Splits a double-precision floating-point number into a higher order word
(unsigned 32-bit integer) and a lower order word (unsigned 32-bit integer)
and assigns results to a provided output array.
When provided a destination object, the function returns an array with two
elements: a higher order word and a lower order word, respectively. The
lower order word contains the less significant bits, while the higher order
word contains the more significant bits and includes the exponent and sign.
Parameters
----------
x: number
Double-precision floating-point number.
out: Array|TypedArray|Object
Output array.
stride: integer
Output array stride.
offset: integer
Output array index offset.
Returns
-------
out: Array|TypedArray|Object
Higher and lower order words.
Examples
--------
> var out = new {{alias:@stdlib/array/uint32}}( 2 );
> w = {{alias}}( out, 3.14e201 )
> var w = {{alias}}.assign( 3.14e201, out, 1, 0 )
<Uint32Array>[ 1774486211, 2479577218 ]

@@ -36,0 +64,0 @@ > var bool = ( w === out )

59

docs/types/index.d.ts

@@ -23,24 +23,43 @@ /*

import { ArrayLike } from '@stdlib/types/array';
import { Collection } from '@stdlib/types/object';
/**
* Splits a double-precision floating-point number into a higher order word (unsigned 32-bit integer) and a lower order word (unsigned 32-bit integer).
*
* @param out - output array
* @param x - input value
* @returns output array
*
* @example
* var Uint32Array = require( `@stdlib/array/uint32` );
*
* var out = new Uint32Array( 2 );
*
* var w = toWords( out, 3.14e201 );
* // returns <Uint32Array>[ 1774486211, 2479577218 ]
*
* var bool = ( w === out );
* // returns true
*/
declare function toWords( out: ArrayLike<number>, x: number ): ArrayLike<number>; // tslint-disable-line max-line-length
* Interface describing `toWords`.
*/
interface ToWords {
/**
* Splits a double-precision floating-point number into a higher order word (unsigned 32-bit integer) and a lower order word (unsigned 32-bit integer).
*
* @param x - input value
* @returns output array
*
* @example
* var w = toWords( 3.14e201 );
* // returns [ 1774486211, 2479577218 ]
*/
( x: number ): Array<number>;
/**
* Splits a double-precision floating-point number into a higher order word (unsigned 32-bit integer) and a lower order word (unsigned 32-bit integer) and assigns results to a provided output array.
*
* @param x - input value
* @param out - output array
* @param stride - output array stride
* @param offset - output array index offset
* @returns output array
*
* @example
* var Uint32Array = require( `@stdlib/array/uint32` );
*
* var out = new Uint32Array( 2 );
*
* var w = toWords.assign( 3.14e201, out, 1, 0 );
* // returns <Uint32Array>[ 1774486211, 2479577218 ]
*
* var bool = ( w === out );
* // returns true
*/
assign( x: number, out: Collection, stride: number, offset: number ): Collection; // tslint-disable-line max-line-length
}
/**

@@ -56,3 +75,3 @@ * Splits a double-precision floating-point number into a higher order word (unsigned 32-bit integer) and a lower order word (unsigned 32-bit integer).

*/
declare function toWords( x: number ): ArrayLike<number>;
declare var toWords: ToWords;

@@ -59,0 +78,0 @@

@@ -26,5 +26,3 @@ /*

{
toWords( 3.14e201 ); // $ExpectType ArrayLike<number>
const out = [ 0, 0 ];
toWords( out, 3.14e201 ); // $ExpectType ArrayLike<number>
toWords( 3.14e201 ); // $ExpectType number[]
}

@@ -40,25 +38,73 @@

toWords( ( x: number ): number => x ); // $ExpectError
}
const out = [ 0, 0 ];
toWords( out, '5' ); // $ExpectError
toWords( out, true ); // $ExpectError
toWords( out, false ); // $ExpectError
toWords( out, null ); // $ExpectError
toWords( out, {} ); // $ExpectError
toWords( out, ( x: number ): number => x ); // $ExpectError
// The compiler throws an error if the function is provided insufficient arguments...
{
toWords(); // $ExpectError
}
// The compiler throws an error if the function is provided an output array that is not an array-like object of numbers...
// Attached to the main export is an `assign` method which returns an array-like object containing numbers...
{
toWords( '5', 3.14e201 ); // $ExpectError
toWords( true, 3.14e201 ); // $ExpectError
toWords( false, 3.14e201 ); // $ExpectError
toWords( null, 3.14e201 ); // $ExpectError
toWords( {}, 3.14e201 ); // $ExpectError
toWords( ( x: number ): number => x, 3.14e201 ); // $ExpectError
const out = [ 0.0, 0.0 ];
toWords.assign( 3.14e-319, out, 1, 0 ); // $ExpectType Collection
}
// The compiler throws an error if the function is provided insufficient arguments...
// The compiler throws an error if the `assign` method is provided a first argument which is not a number...
{
toWords(); // $ExpectError
const out = [ 0.0, 0.0 ];
toWords.assign( true, out, 1, 0 ); // $ExpectError
toWords.assign( false, out, 1, 0 ); // $ExpectError
toWords.assign( '5', out, 1, 0 ); // $ExpectError
toWords.assign( null, out, 1, 0 ); // $ExpectError
toWords.assign( [], out, 1, 0 ); // $ExpectError
toWords.assign( {}, out, 1, 0 ); // $ExpectError
toWords.assign( ( x: number ): number => x, out, 1, 0 ); // $ExpectError
}
// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object...
{
toWords.assign( 1.0, 1, 1, 0 ); // $ExpectError
toWords.assign( 1.0, true, 1, 0 ); // $ExpectError
toWords.assign( 1.0, false, 1, 0 ); // $ExpectError
toWords.assign( 1.0, null, 1, 0 ); // $ExpectError
toWords.assign( 1.0, {}, 1, 0 ); // $ExpectError
}
// The compiler throws an error if the `assign` method is provided a third argument which is not a number...
{
const out = [ 0.0, 0.0 ];
toWords.assign( 1.0, out, '5', 0 ); // $ExpectError
toWords.assign( 1.0, out, true, 0 ); // $ExpectError
toWords.assign( 1.0, out, false, 0 ); // $ExpectError
toWords.assign( 1.0, out, null, 0 ); // $ExpectError
toWords.assign( 1.0, out, [], 0 ); // $ExpectError
toWords.assign( 1.0, out, {}, 0 ); // $ExpectError
toWords.assign( 1.0, out, ( x: number ): number => x, 0 ); // $ExpectError
}
// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number...
{
const out = [ 0.0, 0.0 ];
toWords.assign( 1.0, out, 1, '5' ); // $ExpectError
toWords.assign( 1.0, out, 1, true ); // $ExpectError
toWords.assign( 1.0, out, 1, false ); // $ExpectError
toWords.assign( 1.0, out, 1, null ); // $ExpectError
toWords.assign( 1.0, out, 1, [] ); // $ExpectError
toWords.assign( 1.0, out, 1, {} ); // $ExpectError
toWords.assign( 1.0, out, 1, ( x: number ): number => x ); // $ExpectError
}
// The compiler throws an error if the `assign` method is provided an unsupported number of arguments...
{
const out = [ 0.0, 0.0 ];
toWords.assign(); // $ExpectError
toWords.assign( 1.0 ); // $ExpectError
toWords.assign( 1.0, out ); // $ExpectError
toWords.assign( 1.0, out, 1 ); // $ExpectError
toWords.assign( 1.0, out, 1, 0, 1 ); // $ExpectError
}

@@ -38,3 +38,3 @@ /**

*
* var w = toWords( out, 3.14e201 );
* var w = toWords.assign( 3.14e201, out, 1, 0 );
* // returns <Uint32Array>[ 1774486211, 2479577218 ]

@@ -48,7 +48,14 @@ *

var toWords = require( './main.js' );
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
var main = require( './main.js' );
var assign = require( './assign.js' );
// MAIN //
setReadOnly( main, 'assign', assign );
// EXPORTS //
module.exports = toWords;
module.exports = main;

@@ -23,3 +23,3 @@ /**

var fcn = require( './to_words.js' );
var fcn = require( './assign.js' );

@@ -32,5 +32,4 @@

*
* @param {(Array|TypedArray|Object)} [out] - output array
* @param {number} x - input value
* @returns {(Array|TypedArray|Object)} output array
* @returns {Array<number>} output array
*

@@ -40,19 +39,5 @@ * @example

* // returns [ 1774486211, 2479577218 ]
*
* @example
* var Uint32Array = require( '@stdlib/array-uint32' );
*
* var out = new Uint32Array( 2 );
*
* var w = toWords( out, 3.14e201 );
* // returns <Uint32Array>[ 1774486211, 2479577218 ]
*
* var bool = ( w === out );
* // returns true
*/
function toWords( out, x ) {
if ( arguments.length === 1 ) {
return fcn( [ 0, 0 ], out );
}
return fcn( out, x );
function toWords( x ) {
return fcn( x, [ 0>>>0, 0>>>0 ], 1, 0 );
}

@@ -59,0 +44,0 @@

@@ -28,3 +28,3 @@ {

"src": [
"./src/to_words.c"
"./src/main.c"
],

@@ -31,0 +31,0 @@ "include": [

{
"name": "@stdlib/number-float64-base-to-words",
"version": "0.0.6",
"version": "0.0.7",
"description": "Split a double-precision floating-point number into a higher order word and a lower order word.",

@@ -49,5 +49,7 @@ "license": "Apache-2.0",

"@stdlib/types": "^0.0.x",
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x",
"@stdlib/utils-library-manifest": "^0.0.x"
},
"devDependencies": {
"@stdlib/assert-has-own-property": "^0.0.x",
"@stdlib/assert-is-array": "^0.0.x",

@@ -54,0 +56,0 @@ "@stdlib/bench": "^0.0.x",

@@ -45,3 +45,3 @@ <!--

#### toWords( \[out,] x )
#### toWords( x )

@@ -68,4 +68,6 @@ Splits a [double-precision floating-point number][ieee754] into a higher order word (unsigned 32-bit `integer`) and a lower order word (unsigned 32-bit `integer`).

To avoid unnecessary memory allocation, the function supports providing an output (destination) object.
#### toWords.assign( x, out, stride, offset )
Splits a [double-precision floating-point number][ieee754] into a higher order word (unsigned 32-bit `integer`) and a lower order word (unsigned 32-bit `integer`) and assigns results to a provided output array.
```javascript

@@ -76,3 +78,3 @@ var Uint32Array = require( '@stdlib/array-uint32' );

var w = toWords( out, 3.14e201 );
var w = toWords.assign( 3.14e201, out, 1, 0 );
// returns <Uint32Array>[ 1774486211, 2479577218 ]

@@ -286,4 +288,4 @@

[test-image]: https://github.com/stdlib-js/number-float64-base-to-words/actions/workflows/test.yml/badge.svg
[test-url]: https://github.com/stdlib-js/number-float64-base-to-words/actions/workflows/test.yml
[test-image]: https://github.com/stdlib-js/number-float64-base-to-words/actions/workflows/test.yml/badge.svg?branch=v0.0.7
[test-url]: https://github.com/stdlib-js/number-float64-base-to-words/actions/workflows/test.yml?query=branch:v0.0.7

@@ -300,2 +302,9 @@ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/number-float64-base-to-words/main.svg

[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
[chat-url]: https://gitter.im/stdlib-js/stdlib/
[stdlib]: https://github.com/stdlib-js/stdlib
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
[umd]: https://github.com/umdjs/umd

@@ -307,10 +316,4 @@ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

[esm-url]: https://github.com/stdlib-js/number-float64-base-to-words/tree/esm
[branches-url]: https://github.com/stdlib-js/number-float64-base-to-words/blob/main/branches.md
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
[chat-url]: https://gitter.im/stdlib-js/stdlib/
[stdlib]: https://github.com/stdlib-js/stdlib
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/number-float64-base-to-words/main/LICENSE

@@ -317,0 +320,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc