Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Aug 8, 2024
1 parent 58c3e36 commit 8a557bc
Show file tree
Hide file tree
Showing 25 changed files with 1,997 additions and 1 deletion.
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<section class="release" id="unreleased">

## Unreleased (2024-08-07)
## Unreleased (2024-08-08)

<section class="packages">

Expand Down Expand Up @@ -4930,6 +4930,28 @@ This release closes the following issue:

<!-- /.package -->

<section class="package" id="math-base-special-roundf-unreleased">

#### [@stdlib/math/base/special/roundf](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/roundf)

<details>

<section class="features">

##### Features

- [`fabbf5a`](https://github.com/stdlib-js/stdlib/commit/fabbf5abfb781849d460e93dd498cd7d99505678) - add `math/base/special/roundf`

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="math-base-special-roundn-unreleased">

#### [@stdlib/math/base/special/roundn](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/roundn)
Expand Down Expand Up @@ -5841,6 +5863,7 @@ A total of 30 people contributed to this release. Thank you to the following con

<details>

- [`fabbf5a`](https://github.com/stdlib-js/stdlib/commit/fabbf5abfb781849d460e93dd498cd7d99505678) - **feat:** add `math/base/special/roundf` _(by Gunj Joshi, Philipp Burckhardt)_
- [`f966721`](https://github.com/stdlib-js/stdlib/commit/f966721cd336b1ef47199adc316f6e5779aeff06) - **chore:** update URLs _(by Philipp Burckhardt)_
- [`458697c`](https://github.com/stdlib-js/stdlib/commit/458697cf4aae5b6bcd2e0d9e19181d2ac3b70fe1) - **feat:** add C implementation for `math/base/special/gamma1pm1` _(by Gunj Joshi)_
- [`7502603`](https://github.com/stdlib-js/stdlib/commit/75026039180c76cf376d7550d7470c57a11780cd) - **feat:** add C implementation for `math/base/special/betaln` _(by Gunj Joshi, Philipp Burckhardt)_
Expand Down
212 changes: 212 additions & 0 deletions base/special/roundf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<!--
@license Apache-2.0
Copyright (c) 2024 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.
-->

# Round

> Round a single-precision floating-point number to the nearest integer.
<section class="usage">

## Usage

```javascript
var roundf = require( '@stdlib/math/base/special/roundf' );
```

#### roundf( x )

Rounds a single-precision floating-point number to the nearest `integer`.

```javascript
var v = roundf( -4.2 );
// returns -4.0

v = roundf( -4.5 );
// returns -4.0

v = roundf( -4.6 );
// returns -5.0

v = roundf( 9.99999 );
// returns 10.0

v = roundf( 9.5 );
// returns 10.0

v = roundf( 9.2 );
// returns 9.0

v = roundf( 0.0 );
// returns 0.0

v = roundf( -0.0 );
// returns -0.0

v = roundf( Infinity );
// returns Infinity

v = roundf( -Infinity );
// returns -Infinity

v = roundf( NaN );
// returns NaN
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Ties are rounded toward positive infinity.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var randu = require( '@stdlib/random/base/randu' );
var roundf = require( '@stdlib/math/base/special/roundf' );

var x;
var i;

for ( i = 0; i < 100; i++ ) {
x = ( randu() * 100.0 ) - 50.0;
console.log( 'Value: %d. Rounded: %d.', x, roundf( x ) );
}
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

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

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/math/base/special/roundf.h"
```

#### stdlib_base_roundf( x )

Rounds a single-precision floating-point number to the nearest `integer`.

```c
float out = stdlib_base_roundf( -4.2f );
// returns -4.0f
```

The function accepts the following arguments:

- **x**: `[in] float` input value.

```c
float stdlib_base_roundf( const float x );
```
</section>
<!-- /.usage -->
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
<section class="notes">
</section>
<!-- /.notes -->
<!-- C API usage examples. -->
<section class="examples">
### Examples
```c
#include "stdlib/math/base/special/roundf.h"
#include <stdio.h>
int main( void ) {
const float x[] = { -5.0f, -3.89f, -2.78f, -1.67f, -0.56f, 0.56f, 1.67f, 2.78f, 3.89f, 5.0f };
float v;
int i;
for ( i = 0; i < 10; i++ ) {
v = stdlib_base_roundf( x[ i ] );
printf( "roundf(%f) = %f\n", x[ i ], v );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

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

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

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

</section>

<!-- /.links -->
51 changes: 51 additions & 0 deletions base/special/roundf/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 randu = require( '@stdlib/random/base/randu' );
var isnanf = require( './../../../../base/assert/is-nanf' );
var pkg = require( './../package.json' ).name;
var roundf = require( './../lib' );


// MAIN //

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 1000.0 ) - 500.0;
y = roundf( x );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
60 changes: 60 additions & 0 deletions base/special/roundf/benchmark/benchmark.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnanf = require( './../../../../base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var roundf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( roundf instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 1000.0 ) - 500.0;
y = roundf( x );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading

0 comments on commit 8a557bc

Please sign in to comment.