Skip to content

Commit 1a9d64c

Browse files
committed
Auto-generated commit
1 parent 360df10 commit 1a9d64c

File tree

21 files changed

+1201
-0
lines changed

21 files changed

+1201
-0
lines changed

base/lib/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,24 @@ setReadOnly( ns, 'map4d', require( './../../base/map4d' ) );
927927
*/
928928
setReadOnly( ns, 'map5d', require( './../../base/map5d' ) );
929929

930+
/**
931+
* @name minSignedIntegerDataType
932+
* @memberof ns
933+
* @readonly
934+
* @type {Function}
935+
* @see {@link module:@stdlib/array/base/min-signed-integer-dtype}
936+
*/
937+
setReadOnly( ns, 'minSignedIntegerDataType', require( './../../base/min-signed-integer-dtype' ) );
938+
939+
/**
940+
* @name minUnsignedIntegerDataType
941+
* @memberof ns
942+
* @readonly
943+
* @type {Function}
944+
* @see {@link module:@stdlib/array/base/min-unsigned-integer-dtype}
945+
*/
946+
setReadOnly( ns, 'minUnsignedIntegerDataType', require( './../../base/min-unsigned-integer-dtype' ) );
947+
930948
/**
931949
* @name mskbinary2d
932950
* @memberof ns
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# Minimum Data Type
22+
23+
> Determine the minimum array [data type][@stdlib/array/dtypes] for storing a provided signed integer value.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var minSignedIntegerDataType = require( '@stdlib/array/base/min-signed-integer-dtype' );
41+
```
42+
43+
#### minSignedIntegerDataType( value )
44+
45+
Returns the minimum array [data type][@stdlib/array/dtypes] for storing a provided signed integer value.
46+
47+
```javascript
48+
var dt = minSignedIntegerDataType( 9999 );
49+
// returns 'int16'
50+
51+
dt = minSignedIntegerDataType( -3 );
52+
// returns 'int8'
53+
54+
dt = minSignedIntegerDataType( 3 );
55+
// returns 'int8'
56+
57+
dt = minSignedIntegerDataType( 1e100 );
58+
// returns 'float64'
59+
```
60+
61+
</section>
62+
63+
<!-- /.usage -->
64+
65+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
66+
67+
<section class="notes">
68+
69+
## Notes
70+
71+
- Once a provided integer value exceeds the maximum values of all supported signed integer [data types][@stdlib/array/dtypes], the function defaults to returning `'float64'`.
72+
73+
</section>
74+
75+
<!-- /.notes -->
76+
77+
<!-- Package usage examples. -->
78+
79+
<section class="examples">
80+
81+
## Examples
82+
83+
<!-- eslint no-undef: "error" -->
84+
85+
```javascript
86+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
87+
var exp2 = require( '@stdlib/math/base/special/exp2' );
88+
var minSignedIntegerDataType = require( '@stdlib/array/base/min-signed-integer-dtype' );
89+
90+
// Generate random powers:
91+
var exp = discreteUniform( 100, 0, 40, {
92+
'dtype': 'generic'
93+
});
94+
95+
// Determine the minimum data type for each generated value...
96+
var v;
97+
var i;
98+
for ( i = 0; i < exp.length; i++ ) {
99+
v = exp2( exp[ i ] );
100+
console.log( 'min(%d) => %s', v, minSignedIntegerDataType( v ) );
101+
}
102+
```
103+
104+
</section>
105+
106+
<!-- /.examples -->
107+
108+
<!-- 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. -->
109+
110+
<section class="references">
111+
112+
</section>
113+
114+
<!-- /.references -->
115+
116+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
117+
118+
<section class="related">
119+
120+
</section>
121+
122+
<!-- /.related -->
123+
124+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
125+
126+
<section class="links">
127+
128+
[@stdlib/array/dtypes]: https://github.com/stdlib-js/array/tree/main/dtypes
129+
130+
</section>
131+
132+
<!-- /.links -->
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var minSignedIntegerDataType = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var values;
33+
var out;
34+
var N;
35+
var i;
36+
37+
values = [
38+
0,
39+
1,
40+
-128,
41+
128,
42+
99999,
43+
-99999,
44+
1.0e100,
45+
-1.0e100,
46+
-1234567890,
47+
1234567890
48+
];
49+
N = values.length;
50+
51+
b.tic();
52+
for ( i = 0; i < b.iterations; i++ ) {
53+
out = minSignedIntegerDataType( values[ i%N ] );
54+
if ( typeof out !== 'string' ) {
55+
b.fail( 'should return a string' );
56+
}
57+
}
58+
b.toc();
59+
if ( !isString( out ) ) {
60+
b.fail( 'should return a string' );
61+
}
62+
b.pass( 'benchmark finished' );
63+
b.end();
64+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
{{alias}}( value )
3+
Returns the minimum array data type for storing a provided signed integer
4+
value.
5+
6+
Parameters
7+
----------
8+
value: number
9+
Signed integer value.
10+
11+
Returns
12+
-------
13+
dt: string
14+
Array data type.
15+
16+
Examples
17+
--------
18+
> var dt = {{alias}}( 3 )
19+
'int8'
20+
> dt = {{alias}}( -3 )
21+
'int8'
22+
> dt = {{alias}}( 1280 )
23+
'int16'
24+
25+
See Also
26+
--------
27+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { SignedIntegerDataType } from '@stdlib/types/array';
24+
25+
/**
26+
* Output data type.
27+
*/
28+
type DataType = SignedIntegerDataType | 'float64';
29+
30+
/**
31+
* Returns the minimum array data type for storing a provided signed integer value.
32+
*
33+
* @param value - scalar value
34+
* @returns array data type
35+
*
36+
* @example
37+
* var dt = minSignedIntegerDataType( 1280 );
38+
* // returns 'int16'
39+
*
40+
* @example
41+
* var dt = minSignedIntegerDataType( 3 );
42+
* // returns 'int8'
43+
*/
44+
declare function minSignedIntegerDataType( value: number ): DataType;
45+
46+
47+
// EXPORTS //
48+
49+
export = minSignedIntegerDataType;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import minSignedIntegerDataType = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a data type..
25+
{
26+
minSignedIntegerDataType( 2 ); // $ExpectType DataType
27+
}
28+
29+
// The compiler throws an error if the function is provided an unsupported number of arguments...
30+
{
31+
minSignedIntegerDataType(); // $ExpectError
32+
minSignedIntegerDataType( 3, 3 ); // $ExpectError
33+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
22+
var exp2 = require( '@stdlib/math/base/special/exp2' );
23+
var minSignedIntegerDataType = require( './../lib' );
24+
25+
// Generate random powers:
26+
var exp = discreteUniform( 100, 0, 40, {
27+
'dtype': 'generic'
28+
});
29+
30+
// Determine the minimum data type for each generated value...
31+
var v;
32+
var i;
33+
for ( i = 0; i < exp.length; i++ ) {
34+
v = exp2( exp[ i ] );
35+
console.log( 'min(%d) => %s', v, minSignedIntegerDataType( v ) );
36+
}

0 commit comments

Comments
 (0)