Skip to content

Commit ca13482

Browse files
committed
feat: add math/base/assert/is-negative-integerf
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 324d15c commit ca13482

File tree

23 files changed

+1817
-0
lines changed

23 files changed

+1817
-0
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# isNegativeIntegerf
22+
23+
> Test if a finite single-precision floating-point number is a negative integer.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var isNegativeIntegerf = require( '@stdlib/math/base/assert/is-negative-integerf' );
31+
```
32+
33+
#### isNegativeIntegerf( x )
34+
35+
Tests if a finite single-precision floating-point number is a negative integer.
36+
37+
```javascript
38+
var bool = isNegativeIntegerf( -1.0 );
39+
// returns true
40+
41+
bool = isNegativeIntegerf( 0.0 );
42+
// returns false
43+
44+
bool = isNegativeIntegerf( 10.0 );
45+
// returns false
46+
```
47+
48+
</section>
49+
50+
<!-- /.usage -->
51+
52+
<section class="notes">
53+
54+
## Notes
55+
56+
- The function assumes a **finite** `number`. If provided negative `infinity`, the function will return `true`, when, in fact, the result is undefined. If `x` can be `infinite`, wrap the implementation as follows:
57+
58+
```javascript
59+
function check( x ) {
60+
return (
61+
x > -Infinity &&
62+
isNegativeIntegerf( x )
63+
);
64+
}
65+
66+
var bool = check( -Infinity );
67+
// returns false
68+
```
69+
70+
</section>
71+
72+
<!-- /.notes -->
73+
74+
<section class="examples">
75+
76+
## Examples
77+
78+
<!-- eslint no-undef: "error" -->
79+
80+
```javascript
81+
var isNegativeIntegerf = require( '@stdlib/math/base/assert/is-negative-integerf' );
82+
83+
var bool = isNegativeIntegerf( -5.0 );
84+
// returns true
85+
86+
bool = isNegativeIntegerf( 5.0 );
87+
// returns false
88+
89+
bool = isNegativeIntegerf( -3.14 );
90+
// returns false
91+
92+
bool = isNegativeIntegerf( 0.0 );
93+
// returns false
94+
95+
bool = isNegativeIntegerf( NaN );
96+
// returns false
97+
```
98+
99+
</section>
100+
101+
<!-- /.examples -->
102+
103+
<!-- C interface documentation. -->
104+
105+
* * *
106+
107+
<section class="c">
108+
109+
## C APIs
110+
111+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
112+
113+
<section class="intro">
114+
115+
</section>
116+
117+
<!-- /.intro -->
118+
119+
<!-- C usage documentation. -->
120+
121+
<section class="usage">
122+
123+
### Usage
124+
125+
```c
126+
#include "stdlib/math/base/assert/is_negative_integerf.h"
127+
```
128+
129+
#### stdlib_base_is_negative_integerf( x )
130+
131+
Tests if a finite single-precision floating-point number is a negative integer.
132+
133+
```c
134+
bool out = stdlib_base_is_negative_integerf( -1.0f );
135+
// returns true
136+
137+
out = stdlib_base_is_negative_integerf( 0.0f );
138+
// returns false
139+
```
140+
141+
The function accepts the following arguments:
142+
143+
- **x**: `[in] float` input value.
144+
145+
```c
146+
bool stdlib_base_is_negative_integerf( const float x );
147+
```
148+
149+
</section>
150+
151+
<!-- /.usage -->
152+
153+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
154+
155+
<section class="notes">
156+
157+
</section>
158+
159+
<!-- /.notes -->
160+
161+
<!-- C API usage examples. -->
162+
163+
<section class="examples">
164+
165+
### Examples
166+
167+
```c
168+
#include "stdlib/math/base/assert/is_negative_integerf.h"
169+
#include <stdio.h>
170+
171+
int main( void ) {
172+
const float x[] = { 5.0f, -5.0f, 3.14f, -3.14f, 0.0f, 0.0f/0.0f };
173+
174+
bool b;
175+
int i;
176+
for ( i = 0; i < 6; i++ ) {
177+
b = stdlib_base_is_negative_integerf( x[i] );
178+
printf( "Value: %f. Is negative integer? %s.\n", x[i], ( b ) ? "True" : "False" );
179+
}
180+
}
181+
```
182+
183+
</section>
184+
185+
<!-- /.examples -->
186+
187+
</section>
188+
189+
<!-- /.c -->
190+
191+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
192+
193+
<section class="related">
194+
195+
</section>
196+
197+
<!-- /.related -->
198+
199+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
200+
201+
<section class="links">
202+
203+
</section>
204+
205+
<!-- /.links -->
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
26+
var pkg = require( './../package.json' ).name;
27+
var isNegativeIntegerf = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var values;
34+
var out;
35+
var i;
36+
37+
values = uniform( 500, -50.0, 50.0, {
38+
'dtype': 'float32'
39+
});
40+
41+
b.tic();
42+
for ( i = 0; i < b.iterations; i++ ) {
43+
out = isNegativeIntegerf( values[ i%values.length ] );
44+
if ( typeof out !== 'boolean' ) {
45+
b.fail( 'should return a boolean' );
46+
}
47+
}
48+
b.toc();
49+
if ( !isBoolean( out ) ) {
50+
b.fail( 'should return a boolean' );
51+
}
52+
b.pass( 'benchmark finished' );
53+
b.end();
54+
});
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
26+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
27+
var tryRequire = require( '@stdlib/utils/try-require' );
28+
var pkg = require( './../package.json' ).name;
29+
30+
31+
// VARIABLES //
32+
33+
var isNegativeIntegerf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var opts = {
35+
'skip': ( isNegativeIntegerf instanceof Error )
36+
};
37+
38+
39+
// MAIN //
40+
41+
bench( pkg+'::native', opts, function benchmark( b ) {
42+
var opts;
43+
var x;
44+
var y;
45+
var i;
46+
47+
opts = {
48+
'dtype': 'float32'
49+
};
50+
x = discreteUniform( 100, -5.0e6, 5.0e6, opts );
51+
52+
b.tic();
53+
for ( i = 0; i < b.iterations; i++ ) {
54+
y = isNegativeIntegerf( x[ i % x.length ] );
55+
if ( typeof y !== 'boolean' ) {
56+
b.fail( 'should return a boolean' );
57+
}
58+
}
59+
b.toc();
60+
if ( !isBoolean( y ) ) {
61+
b.fail( 'should return a boolean' );
62+
}
63+
b.pass( 'benchmark finished' );
64+
b.end();
65+
});

0 commit comments

Comments
 (0)