Skip to content

Commit 41d3972

Browse files
committed
feat: add ndarray/base/assert/is-real-floating-point-data-type
1 parent b4e24c3 commit 41d3972

File tree

10 files changed

+761
-0
lines changed

10 files changed

+761
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2023 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+
# isRealFloatingPointDataType
22+
23+
> Test if an input value is a supported ndarray real-valued floating-point data type.
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+
<!-- eslint-disable id-length -->
40+
41+
```javascript
42+
var isRealFloatingPointDataType = require( '@stdlib/ndarray/base/assert/is-real-floating-point-data-type' );
43+
```
44+
45+
#### isRealFloatingPointDataType( value )
46+
47+
Tests if an input `value` is a supported ndarray real-valued floating-point data type.
48+
49+
<!-- eslint-disable id-length -->
50+
51+
```javascript
52+
var bool = isRealFloatingPointDataType( 'float32' );
53+
// returns true
54+
55+
bool = isRealFloatingPointDataType( 'uint32' );
56+
// returns false
57+
```
58+
59+
</section>
60+
61+
<!-- /.usage -->
62+
63+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
64+
65+
<section class="notes">
66+
67+
</section>
68+
69+
<!-- /.notes -->
70+
71+
<!-- Package usage examples. -->
72+
73+
<section class="examples">
74+
75+
## Examples
76+
77+
<!-- eslint-disable id-length -->
78+
79+
<!-- eslint no-undef: "error" -->
80+
81+
```javascript
82+
var isRealFloatingPointDataType = require( '@stdlib/ndarray/base/assert/is-real-floating-point-data-type' );
83+
84+
var bool = isRealFloatingPointDataType( 'binary' );
85+
// returns false
86+
87+
bool = isRealFloatingPointDataType( 'float32' );
88+
// returns true
89+
90+
bool = isRealFloatingPointDataType( 'float64' );
91+
// returns true
92+
93+
bool = isRealFloatingPointDataType( 'generic' );
94+
// returns false
95+
96+
bool = isRealFloatingPointDataType( 'int16' );
97+
// returns false
98+
99+
bool = isRealFloatingPointDataType( 'int32' );
100+
// returns false
101+
102+
bool = isRealFloatingPointDataType( 'int8' );
103+
// returns false
104+
105+
bool = isRealFloatingPointDataType( 'uint16' );
106+
// returns false
107+
108+
bool = isRealFloatingPointDataType( 'uint32' );
109+
// returns false
110+
111+
bool = isRealFloatingPointDataType( 'uint8' );
112+
// returns false
113+
114+
bool = isRealFloatingPointDataType( 'uint8c' );
115+
// returns false
116+
117+
bool = isRealFloatingPointDataType( '' );
118+
// returns false
119+
120+
bool = isRealFloatingPointDataType( 'foo' );
121+
// returns false
122+
```
123+
124+
</section>
125+
126+
<!-- /.examples -->
127+
128+
<!-- 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. -->
129+
130+
<section class="references">
131+
132+
</section>
133+
134+
<!-- /.references -->
135+
136+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
137+
138+
<section class="related">
139+
140+
</section>
141+
142+
<!-- /.related -->
143+
144+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
145+
146+
<section class="links">
147+
148+
</section>
149+
150+
<!-- /.links -->
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var isRealFloatingPointDataType = require( './../lib' ); // eslint-disable-line id-length
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var values;
33+
var out;
34+
var v;
35+
var i;
36+
37+
values = [
38+
'binary',
39+
'float32',
40+
'float64',
41+
'generic',
42+
'int16',
43+
'int32',
44+
'int8',
45+
'uint16',
46+
'uint32',
47+
'uint8',
48+
'uint8c',
49+
'foo',
50+
'bar',
51+
'',
52+
'beep',
53+
'boop'
54+
];
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
v = values[ i%values.length ];
59+
out = isRealFloatingPointDataType( v );
60+
if ( typeof out !== 'boolean' ) {
61+
b.fail( 'should return a boolean' );
62+
}
63+
}
64+
b.toc();
65+
if ( !isBoolean( out ) ) {
66+
b.fail( 'should return a boolean' );
67+
}
68+
b.pass( 'benchmark finished' );
69+
b.end();
70+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
{{alias}}( value )
3+
Tests if an input value is a supported ndarray real-valued floating-point
4+
data type.
5+
6+
Parameters
7+
----------
8+
value: any
9+
Value to test.
10+
11+
Returns
12+
-------
13+
bool: boolean
14+
Boolean indicating if an input value is a supported ndarray real-valued
15+
floating-point data type.
16+
17+
Examples
18+
--------
19+
> var bool = {{alias}}( 'binary' )
20+
false
21+
> bool = {{alias}}( 'float32' )
22+
true
23+
> bool = {{alias}}( 'float64' )
24+
true
25+
> bool = {{alias}}( 'int16' )
26+
false
27+
> bool = {{alias}}( 'int32' )
28+
false
29+
> bool = {{alias}}( 'int8' )
30+
false
31+
> bool = {{alias}}( 'uint16' )
32+
false
33+
> bool = {{alias}}( 'uint32' )
34+
false
35+
> bool = {{alias}}( 'uint8' )
36+
false
37+
> bool = {{alias}}( 'uint8c' )
38+
false
39+
> bool = {{alias}}( '' )
40+
false
41+
> bool = {{alias}}( 'beep' )
42+
false
43+
44+
See Also
45+
--------
46+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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: 2.0
20+
21+
/**
22+
* Tests whether an input value is a supported ndarray real-valued floating-point data type.
23+
*
24+
* @param v - value to test
25+
* @returns boolean indicating whether an input value is a supported ndarray real-valued floating-point data type
26+
*
27+
* @example
28+
* var bool = isRealFloatingPointDataType( 'binary' );
29+
* // returns false
30+
*
31+
* bool = isRealFloatingPointDataType( 'float32' );
32+
* // returns true
33+
*
34+
* bool = isRealFloatingPointDataType( 'float64' );
35+
* // returns true
36+
*
37+
* bool = isRealFloatingPointDataType( 'generic' );
38+
* // returns false
39+
*
40+
* bool = isRealFloatingPointDataType( 'int16' );
41+
* // returns false
42+
*
43+
* bool = isRealFloatingPointDataType( 'int32' );
44+
* // returns false
45+
*
46+
* bool = isRealFloatingPointDataType( 'int8' );
47+
* // returns false
48+
*
49+
* bool = isRealFloatingPointDataType( 'uint16' );
50+
* // returns false
51+
*
52+
* bool = isRealFloatingPointDataType( 'uint32' );
53+
* // returns false
54+
*
55+
* bool = isRealFloatingPointDataType( 'uint8' );
56+
* // returns false
57+
*
58+
* bool = isRealFloatingPointDataType( 'uint8c' );
59+
* // returns false
60+
*
61+
* bool = isRealFloatingPointDataType( 'foo' );
62+
* // returns false
63+
*/
64+
declare function isRealFloatingPointDataType( v: any ): boolean;
65+
66+
67+
// EXPORTS //
68+
69+
export = isRealFloatingPointDataType;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 isRealFloatingPointDataType = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isRealFloatingPointDataType( 'binary' ); // $ExpectType boolean
27+
isRealFloatingPointDataType( 'foo' ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isRealFloatingPointDataType(); // $ExpectError
33+
isRealFloatingPointDataType( undefined, 123 ); // $ExpectError
34+
}

0 commit comments

Comments
 (0)