Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
26f9a3f
chore: copy main.js from `number/float16/ctor`
impawstarlight Mar 12, 2026
c9b0b08
chore: rename float16 stuff to uint64
impawstarlight Mar 12, 2026
dd5a4d6
feat: add asBigUint64 function to truncate BigInt to unsigned 64-bit …
impawstarlight Mar 13, 2026
03e0b6a
feat: add toString, toJSON, and valueOf
impawstarlight Mar 13, 2026
b27d0e1
feat: implement Uint64 constructor with support for BigInt, Uint32Arr…
impawstarlight Mar 13, 2026
7c40edd
feat: add README and package.json
impawstarlight Mar 13, 2026
8ecf428
feat: add index.js
impawstarlight Mar 13, 2026
64e4a30
docs: remove `value` property from README since it should be private …
impawstarlight Mar 13, 2026
b438d53
test: implement initial tests
impawstarlight Mar 13, 2026
77609f7
docs: update todo comment
impawstarlight Mar 13, 2026
e367b17
bench: add initial benchmarks
impawstarlight Mar 13, 2026
aa937a4
docs: add types
impawstarlight Mar 13, 2026
de8ca59
docs: add javascript example
impawstarlight Mar 13, 2026
3420ebf
fix: resovle lint errors
impawstarlight Mar 13, 2026
fc00588
fix: resolve lint errors
impawstarlight Mar 13, 2026
afbeaa2
feat: implement toString with high low words
impawstarlight Mar 13, 2026
9d932db
feat: update Uint64 constructor to support setting preferred represen…
impawstarlight Mar 13, 2026
3926d9a
chore: remove unused paths from package.json
impawstarlight Mar 13, 2026
f1ab12d
bench: fix benchmark error
impawstarlight Mar 13, 2026
b2fd1f6
chore: update copyright years
impawstarlight Mar 13, 2026
b6e19aa
test: add more tests
impawstarlight Mar 14, 2026
8097552
fix: fix unnecessary leading zeros in toString()
impawstarlight Mar 14, 2026
cef9e28
feat: implement string parsing in Uint64 constructor
impawstarlight Mar 14, 2026
85a9378
test: add tests for parsing prefixed and whitespace-padded strings in…
impawstarlight Mar 14, 2026
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
216 changes: 216 additions & 0 deletions lib/node_modules/@stdlib/number/uint64/ctor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<!--

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

-->

# Uint64

> Unsigned 64-bit integer.

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

<!-- Package usage documentation. -->

<section class="usage">

## Usage

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

#### Uint64( value )

Unsigned 64-bit integer constructor.

```javascript
var x = new Uint64( 5 );
// returns <Uint64>
```

* * *

## Properties

#### Uint64.name

Static property returning the constructor name.

```javascript
var str = Uint64.name;
// returns 'Uint64'
```

#### Uint64.BYTES_PER_ELEMENT

Size (in bytes) of the underlying value.

```javascript
var nbytes = Uint64.BYTES_PER_ELEMENT;
// returns 8
```

#### Uint64.prototype.BYTES_PER_ELEMENT

Size (in bytes) of the underlying value.

```javascript
var x = new Uint64( 5 );

var nbytes = x.BYTES_PER_ELEMENT;
// returns 8
```

### Instance

A `Uint64` instance has the following methods...

## Methods

### Accessor Methods

These methods do **not** mutate a `Uint64` instance and, instead return an unsigned 64-bit integer representation.

#### Uint64.prototype.toString()

Returns a string representation of a `Uint64` instance.

```javascript
var x = new Uint64( 5 );
var str = x.toString();
// returns '5'
```

#### Uint64.prototype.toJSON()

Returns a [JSON][json] representation of a `Uint64` instance. [`JSON.stringify()`][mdn-json-stringify] implicitly calls this method when stringifying a `Uint64` instance.

```javascript
var x = new Uint64( 5 );

var o = x.toJSON();
/*
{
"type": "Uint64",
"value": '5'
}
*/
```

To [revive][mdn-json-parse] a `Uint64` number from a [JSON][json] `string`, see [@stdlib/number/uint64/reviver][@stdlib/number/uint64/reviver].

#### Uint64.prototype.valueOf()

Converts a `Uint64` instance to a primitive value.

```javascript
var x = new Uint64( 5 );
var v = x.valueOf();
// returns 5.0
```

</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

- The underlying value is stored as an unsigned 64-bit integer.
- An unsigned 64-bit integer has a range of \[`0`, `2^64-1`\].

</section>

<!-- /.notes -->

* * *

<!-- Package usage examples. -->

<section class="examples">

## Examples

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

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

var x = new Uint64( 1234 );

console.log( 'type: %s', typeof x );
// => 'type: object'

console.log( 'str: %s', x );
// => 'str: 1234'

console.log( 'JSON: %s', JSON.stringify( x ) );
// => 'JSON: {"type":"Uint64","value":"1234"}'
```

</section>

<!-- /.examples -->


<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

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

[json]: http://www.json.org/

[mdn-json-stringify]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

[mdn-json-parse]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

[@stdlib/number/uint64/reviver]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/number/uint64/reviver

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

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

</section>

<!-- /.links -->
120 changes: 120 additions & 0 deletions lib/node_modules/@stdlib/number/uint64/ctor/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* @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 randi = require( '@stdlib/random/base/randi' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Uint64 = require( './../lib' );


// MAIN //

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = new Uint64( i );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( !( z instanceof Uint64 ) ) {
b.fail( 'should return a Uint64 instance' );
}
b.pass( 'benchmark finished' );
b.end();
});

// TODO: because `value` should be private?

/*
bench( format( '%s::get:value', pkg ), function benchmark( b ) {
var v;
var z;
var i;

z = new Uint64( randu() );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = z.value;
if ( isnan( v ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( v ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
*/

bench( format( '%s:toString', pkg ), function benchmark( b ) {
var o;
var z;
var i;

z = new Uint64( randi() );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
o = z.toString();
if ( typeof o !== 'string' ) {
b.fail( 'should return a string' );
}
}
b.toc();
if ( typeof o !== 'string' ) {
b.fail( 'should return a string' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s:toJSON', pkg ), function benchmark( b ) {
var o;
var z;
var i;

z = new Uint64( randi() );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
o = z.toJSON();
if ( typeof o !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( typeof o !== 'object' ) {
b.fail( 'should return an object' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading