Skip to content

Commit

Permalink
feat: add C implementation for math/base/special/nonfibonacci
Browse files Browse the repository at this point in the history
PR-URL: stdlib-js#1964
Closes: stdlib-js#1660

---------

Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
Co-authored-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
  • Loading branch information
3 people authored Mar 22, 2024
1 parent 5de3b76 commit c39cc72
Show file tree
Hide file tree
Showing 16 changed files with 1,162 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@license Apache-2.0
Copyright (c) 2018 The Stdlib Authors.
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.
Expand Down Expand Up @@ -123,6 +123,91 @@ for ( i = 1; i < 100; i++ ) {

<!-- /.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/nonfibonacci.h"
```

#### stdlib_base_nonfibonacci( x )

Computes the nth non-Fibonacci number.

```c
double out = stdlib_base_nonfibonacci( 1 );
// returns 4

out = stdlib_base_nonfibonacci( 2 );
// returns 6
```

The function accepts the following arguments:

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

```c
double stdlib_base_nonfibonacci( const int32_t 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/nonfibonacci.h"
#include <stdio.h>
#include <stdlib.h>
int main( void ) {
int i;
for ( i = 1; i < 12; i++ ) {
double result = stdlib_base_nonfibonacci( i );
printf( "x: %i => result: %lf", i , result );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

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

* * *
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 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 floor = require( '@stdlib/math/base/special/floor' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( '@stdlib/math/base/special/nonfibonacci/package.json' ).name;
var randu = require( '@stdlib/random/base/randu' );
var tryRequire = require( '@stdlib/utils/try-require' );
var bench = require( '@stdlib/bench' );


// VARIABLES //

var nonfibonacci = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( nonfibonacci 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 = floor( (randu()*100.0) + 1.0 );
y = nonfibonacci( x );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});

This file was deleted.

Loading

0 comments on commit c39cc72

Please sign in to comment.