Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions lib/node_modules/@stdlib/number/uint64/base/add/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# add

> Add two unsigned 64-bit integers.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var add = require( '@stdlib/number/uint64/base/add' );
```

#### add( a, b )

Adds two unsigned 64-bit integers.

```javascript
var Uint64 = require( '@stdlib/number/uint64/ctor' );

var a = new Uint64( 5 );
var b = new Uint64( 10 );

var v = add( a, b );
// returns <Uint64>[ 15n ]
```

#### add.assign( ah, al, bh, bl, out, so, oo )

Adds two unsigned 64-bit integers and assigns results to a provided output array.

```javascript
var Uint32Array = require( '@stdlib/array/uint32' );

var out = new Uint32Array( 2 );
var v = add.assign( 0, 5, 0, 10, out, 1, 0 );
// returns <Uint32Array>[ 0, 15 ]

var bool = ( out === v );
// returns true
```

The function supports the following parameters:

- **ah**: high 32-bit word of the first unsigned 64-bit integer.
- **al**: low 32-bit word of the first unsigned 64-bit integer.
- **bh**: high 32-bit word of the second unsigned 64-bit integer.
- **bl**: low 32-bit word of the second unsigned 64-bit integer.
- **out**: output array.
- **so**: stride length for `out`.
- **oo**: starting index for `out`.

#### add.strided( a, sa, oa, b, sb, ob, out, so, oo )

Adds two unsigned 64-bit integers stored in integer-valued strided array views and assigns results to a provided strided output array.

```javascript
var Uint32Array = require( '@stdlib/array/uint32' );

var a = new Uint32Array( [ 0, 5 ] );
var b = new Uint32Array( [ 0, 10 ] );
var out = new Uint32Array( 2 );

var v = add.strided( a, 1, 0, b, 1, 0, out, 1, 0 );
// returns <Uint32Array>[ 0, 15 ]

var bool = ( out === v );
// returns true
```

The function supports the following parameters:

- **a**: first unsigned 64-bit integer strided array view.
- **sa**: stride length for `a`.
- **oa**: starting index for `a`.
- **b**: second unsigned 64-bit integer strided array view.
- **sb**: stride length for `b`.
- **ob**: starting index for `b`.
- **out**: output array.
- **so**: stride length for `out`.
- **oo**: starting index for `out`.

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Uint64 = require( '@stdlib/number/uint64/ctor' );
var add = require( '@stdlib/number/uint64/base/add' );

var a = new Uint64( 5 );
var b = new Uint64( 10 );
var v = add( a, b );
// returns <Uint64>[ 15n ]

a = new Uint64( 1234567890 );
b = new Uint64( 8765432109 );
v = add( a, b );
// returns <Uint64>[ 9999999999n ]
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

<!-- <related-links> -->

<!-- </related-links> -->

</section>

<!-- /.links -->
128 changes: 128 additions & 0 deletions lib/node_modules/@stdlib/number/uint64/base/add/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var Uint32Array = require( '@stdlib/array/uint32' );
var bench = require( '@stdlib/bench' );
var UINT32_MAX = require( '@stdlib/constants/uint32/max' );
var Uint64 = require( '@stdlib/number/uint64/ctor' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var add = require( './../lib' );


// VARIABLES //

var options = {
'dtype': 'uint32'
};


// MAIN //

bench( pkg, function benchmark( b ) {
var values;
var out;
var x;
var y;
var z;
var i;

x = discreteUniform( 100, 0, UINT32_MAX, options);
values = [];
for ( i = 0; i < x.length; i++ ) {
values.push( Uint64.of( x[i], x[(i+1)%x.length] ) );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = values[i%values.length];
z = values[(i+1)%values.length];
out = add( y, z );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !( out instanceof Uint64 ) ) {
b.fail( 'should return a Uint64 instance' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s:assign', pkg ), function benchmark( b ) {
var out;
var N;
var x;
var i;

N = 100;
x = discreteUniform( N, 0, UINT32_MAX, options);

out = new Uint32Array( 2 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
// eslint-disable-next-line max-len
out = add.assign( x[i%N], x[(i+1)%N], x[(i+2)%N], x[(i+3)%N], out, 1, 0 );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !( out instanceof Uint32Array ) ) {
b.fail( 'should return a Uint32Array' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s:strided', pkg ), function benchmark( b ) {
var out;
var N;
var x;
var y;
var i;
var j;

N = 50;
x = discreteUniform( N*2, 0, UINT32_MAX, options);
y = discreteUniform( N*2, 0, UINT32_MAX, options);

out = new Uint32Array( 2 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
j = ( i % N ) * 2;
out = add.strided( x, 1, j, y, 1, j, out, 1, 0 );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !( out instanceof Uint32Array ) ) {
b.fail( 'should return a Uint32Array' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading
Loading