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

@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.

-->

# Identity Function

> Evaluate the [identity function][identity-function] for a 64-bit signed integer.

<section class="intro">

The [identity function][identity-function] is defined as

<!-- <equation class="equation" label="eq:identity_function" align="center" raw="f(x) = x" alt="Identity function"> -->

```math
f(x) = x
```

<!-- </equation> -->

for all `x`.

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### identity( x )

Evaluates the [identity function][identity-function] for a 64-bit signed integer.

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

var x = new Int64( 1 );
var v = identity( x );
// returns <Int64>[ 1n ]

x = new Int64( 0 );
v = identity( x );
// returns <Int64>[ 0n ]

x = new Int64( 4294967296 );
v = identity( x );
// returns <Int64>[ 4294967296n ]

x = new Int64( -1000000000000 );
v = identity( x );
// returns <Int64>[ -1000000000000n ]
```

The function accepts the following arguments:

- **x**: `Int64` input value.

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

```javascript
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var Int64 = require( '@stdlib/number/int64/ctor' );
var identity = require( '@stdlib/number/int64/base/identity' );

// Create an array of random 64-bit signed integers:
var x = [];
var i;
for ( i = 0; i < 10; i++ ) {
x.push( new Int64( discreteUniform( -500, 500 ) ) );
}

// Perform element-wise operation:
logEachMap( 'identity(%s) = %s', x, identity );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/number/int64/base/identity.h"
```

#### stdlib_base_int64_identity( x )

Evaluates the identity function for a 64-bit signed integer.

```c
#include <stdint.h>

int64_t y = stdlib_base_int64_identity( 2 );
// returns 2
```

The function accepts the following arguments:

- **x**: `[in] int64_t` input value.

```c
int64_t stdlib_base_int64_identity( const int64_t x );
```

</section>

<!-- /.usage -->

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

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/number/int64/base/identity.h"
#include <stdio.h>
#include <stdint.h>

int main( void ) {
const int64_t x[] = { 3, 5, 10, 4294967296 };

int64_t y;
int i;
for ( i = 0; i < 4; i++ ) {
y = stdlib_base_int64_identity( x[ i ] );
printf( "f(%ld) = %ld\n", x[ i ], y );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- 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">

[identity-function]: https://en.wikipedia.org/wiki/Identity_function

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

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

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @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 bench = require( '@stdlib/bench' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var getHighWord = require( '@stdlib/number/int64/base/get-high-word' );
var Int64 = require( '@stdlib/number/int64/ctor' );
var pkg = require( './../package.json' ).name;
var identity = require( './../lib' );


// MAIN //

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

x = [];
for ( i = 0; i < 100; i++ ) {
x.push( new Int64( discreteUniform( -500, 500 ) ) );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = identity( x[ i%x.length ] );
if ( typeof y !== 'object' ) {
b.fail( 'should return an Int64 instance' );
}
}
b.toc();
if ( isnan( getHighWord( y ) ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Int64 = require( '@stdlib/number/int64/ctor' );
var getHighWord = require( '@stdlib/number/int64/base/get-high-word' );
var tryRequire = require( '@stdlib/utils/try-require' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var identity = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( identity instanceof Error )
};


// MAIN //

bench( format( '%s::native', pkg ), opts, function benchmark( b ) {
var x;
var y;
var i;

x = [];
for ( i = 0; i < 100; i++ ) {
x.push( new Int64( discreteUniform( -500, 500 ) ) );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = identity( x[ i%x.length ] );
if ( typeof y !== 'object' ) {
b.fail( 'should return an Int64 instance' );
}
}
b.toc();
if ( isnan( getHighWord( y ) ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading