Skip to content
Open
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
188 changes: 188 additions & 0 deletions lib/node_modules/@stdlib/number/int64/base/add/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<!--

@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 64-bit signed integers.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### add( a, b )

Adds two 64-bit signed integers.

```javascript
var Int64 = require( '@stdlib/number/int64/ctor' );

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you are going to document parameters below, you should document parameters here.

@impawstarlight impawstarlight Dec 4, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Artifact from Complex128 reference. This has been going unnoticed for quite a while. Need to update all the previously merged Uint64 base packages as well as the Complex number packages I guess?

The function supports the following parameters:

- **a**: first 64-bit signed integer.
- **b**: second 64-bit signed integer.

#### add.assign( ah, al, bh, bl, out, stride, offset )

Adds two 64-bit signed 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( 1, 2, 3, 4, out, 1, 0 );
// returns <Uint32Array>[ 4, 6 ]

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

The function supports the following parameters:

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

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

Adds two 64-bit signed 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( [ 1, 2 ] );
var b = new Uint32Array( [ 3, 4 ] );
var out = new Uint32Array( 2 );

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

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

The function supports the following parameters:

- **a**: first 64-bit signed integer strided array view containing interleaved 32-bit unsigned integer high and low order words.
- **sa**: stride length for `a`.
- **oa**: starting index for `a`.
- **b**: second 64-bit signed integer strided array view containing interleaved 32-bit unsigned integer high and low order words.
- **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 -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- Unlike signed integer overflow in C, overflow behavior is well-defined and follows two's complement wraparound semantics.
Comment thread
impawstarlight marked this conversation as resolved.
Resolved

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

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

// Addition beyond JavaScript's safe integer limit (10^18 > 2^53 - 1):
var a = new Int64( 1e18 );
var b = new Int64( 1 );
var v = add( a, b );
console.log( '%s + %s = %s', a, b, v );
// => '1000000000000000000 + 1 = 1000000000000000001'

a = new Int64( -1e18 );
b = new Int64( -1 );
v = add( a, b );
console.log( '%s + %s = %s', a, b, v );
// => '-1000000000000000000 + -1 = -1000000000000000001'

a = new Int64( 1e18 );
b = new Int64( -1 );
v = add( a, b );
console.log( '%s + %s = %s', a, b, v );
// => '1000000000000000000 + -1 = 999999999999999999'

// Signed two's complement overflow wrap-around (INT64_MAX + 1 = INT64_MIN):
a = Int64.of( 0x7fffffff, 0xffffffff );
b = new Int64( 1 );
v = add( a, b );
console.log( '%s + %s = %s', a, b, v );
// => '9223372036854775807 + 1 = -9223372036854775808'
```

</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 -->
130 changes: 130 additions & 0 deletions lib/node_modules/@stdlib/number/int64/base/add/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/**
* @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 Int64 = require( '@stdlib/number/int64/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 N;
var x;
var y;
var z;
var i;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = values[ i%N ];
z = values[ (i+1)%N ];
out = add( y, z );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !( out instanceof Int64 ) ) {
b.fail( 'should return an Int64 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