Skip to content

Commit 454b103

Browse files
committed
Add package to test whether number is negative finite
1 parent 3416e4d commit 454b103

File tree

10 files changed

+551
-0
lines changed

10 files changed

+551
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2022 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+
# isNegativeFinite
22+
23+
> Test if a numeric value is a negative finite number.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var isNegativeFinite = require( '@stdlib/math/base/assert/is-negative-finite' );
31+
```
32+
33+
#### isNegativeFinite( x )
34+
35+
Tests if a `numeric` value is a negative finite number.
36+
37+
```javascript
38+
var bool = isNegativeFinite( -3.14 );
39+
// returns true
40+
41+
bool = isNegativeFinite( 2.0 );
42+
// returns false
43+
```
44+
45+
</section>
46+
47+
<!-- /.usage -->
48+
49+
<section class="notes">
50+
51+
</section>
52+
53+
<!-- /.notes -->
54+
55+
<section class="examples">
56+
57+
## Examples
58+
59+
<!-- eslint no-undef: "error" -->
60+
61+
```javascript
62+
var isNegativeFinite = require( '@stdlib/math/base/assert/is-negative-finite' );
63+
64+
var bool = isNegativeFinite( -3.14 );
65+
// returns true
66+
67+
bool = isNegativeFinite( 3.14 );
68+
// returns false
69+
70+
bool = isNegativeFinite( 0.0 );
71+
// returns false
72+
73+
bool = isNegativeFinite( -0.0 );
74+
// returns false
75+
76+
bool = isNegativeFinite( NaN );
77+
// returns false
78+
```
79+
80+
</section>
81+
82+
<!-- /.examples -->
83+
84+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
85+
86+
<section class="related">
87+
88+
</section>
89+
90+
<!-- /.related -->
91+
92+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
93+
94+
<section class="links">
95+
96+
<!-- <related-links> -->
97+
98+
<!-- </related-links> -->
99+
100+
</section>
101+
102+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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 randu = require( '@stdlib/random/base/randu' );
25+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
26+
var pkg = require( './../package.json' ).name;
27+
var isNegativeFinite = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var x;
34+
var y;
35+
var i;
36+
37+
b.tic();
38+
for ( i = 0; i < b.iterations; i++ ) {
39+
x = (randu()*200.0) - 100.0;
40+
y = isNegativeFinite( x );
41+
if ( !isBoolean( y ) ) {
42+
b.fail( 'should return a boolean' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isBoolean( y ) ) {
47+
b.fail( 'should return a boolean' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{{alias}}( x )
2+
Tests if a double-precision floating-point numeric value is a negative
3+
finite number.
4+
5+
Parameters
6+
----------
7+
x: number
8+
Value to test.
9+
10+
Returns
11+
-------
12+
out: boolean
13+
Boolean indicating whether the value is a negative finite number.
14+
15+
Examples
16+
--------
17+
> var bool = {{alias}}( -3.14 )
18+
true
19+
> bool = {{alias}}( -Infinity )
20+
false
21+
> bool = {{alias}}( 2.0 )
22+
false
23+
> bool = {{alias}}( NaN )
24+
false
25+
> bool = {{alias}}( -0.0 )
26+
false
27+
28+
See Also
29+
--------
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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 if a double-precision floating-point numeric value is a negative finite number.
23+
*
24+
* @param x - value to test
25+
* @returns boolean indicating whether the value is a negative finite number
26+
*
27+
* @example
28+
* var bool = isNegativeFinite( -3.14 );
29+
* // returns true
30+
*
31+
* @example
32+
* var bool = isNegativeFinite( -Infinity );
33+
* // returns false
34+
*
35+
* @example
36+
* var bool = isNegativeFinite( 2.0 );
37+
* // returns false
38+
*
39+
* @example
40+
* var bool = isNegativeFinite( NaN );
41+
* // returns false
42+
*
43+
* @example
44+
* var bool = isNegativeFinite( -0.0 );
45+
* // returns false
46+
*/
47+
declare function isNegativeFinite( x: number ): boolean;
48+
49+
50+
// EXPORTS //
51+
52+
export = isNegativeFinite;
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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 isNegativeFinite = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isNegativeFinite( -4.0 ); // $ExpectType boolean
27+
isNegativeFinite( 3.0 ); // $ExpectType boolean
28+
}
29+
30+
// The function does not compile if provided a value other than a number...
31+
{
32+
isNegativeFinite( true ); // $ExpectError
33+
isNegativeFinite( false ); // $ExpectError
34+
isNegativeFinite( null ); // $ExpectError
35+
isNegativeFinite( undefined ); // $ExpectError
36+
isNegativeFinite( [] ); // $ExpectError
37+
isNegativeFinite( {} ); // $ExpectError
38+
isNegativeFinite( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The function does not compile if provided insufficient arguments...
42+
{
43+
isNegativeFinite(); // $ExpectError
44+
}
45+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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 isNegativeFinite = require( './../lib' );
22+
23+
console.log( isNegativeFinite( -3.14 ) );
24+
// => true
25+
26+
console.log( isNegativeFinite( -Infinity ) );
27+
// => false
28+
29+
console.log( isNegativeFinite( 2.0 ) );
30+
// => false
31+
32+
console.log( isNegativeFinite( NaN ) );
33+
// => false
34+
35+
console.log( isNegativeFinite( -0.0 ) );
36+
// => false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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+
/**
22+
* Tests if a double-precision floating-point numeric value is a negative finite number.
23+
*
24+
* @module @stdlib/math/base/assert/is-negative-finite
25+
*
26+
* @example
27+
* var isNegativeFinite = require( '@stdlib/math/base/assert/is-negative-finite' );
28+
*
29+
* var bool = isNegativeFinite( -3.14 );
30+
* // returns true
31+
*
32+
* bool = isNegativeFinite( -Infinity );
33+
* // returns false
34+
*/
35+
36+
// MODULES //
37+
38+
var isNegativeFinite = require( './main.js' );
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = isNegativeFinite;

0 commit comments

Comments
 (0)