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 Nov 15, 2024
1 parent ee89ae2 commit 704c1ce
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 70 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ A total of 5 people contributed to this release. Thank you to the following cont

<details>

- [`15dff30`](https://github.com/stdlib-js/stdlib/commit/15dff30135c09d5afa4b81c0ef662c68b65b6013) - **refactor:** use macros in addon and update examples in `math/base/assert/is-evenf` [(#3115)](https://github.com/stdlib-js/stdlib/pull/3115) _(by Gunj Joshi, Athan Reines)_
- [`e5bfdff`](https://github.com/stdlib-js/stdlib/commit/e5bfdff2d2c137f84eb5f925f8d63a3729d05eb2) - **docs:** update functions descriptions in `math/base/special/cceil` [(#3114)](https://github.com/stdlib-js/stdlib/pull/3114) _(by Gunj Joshi)_
- [`79dc5cf`](https://github.com/stdlib-js/stdlib/commit/79dc5cf4044f4f90a7005389e4740f14a820a967) - **bench:** generate numbers outside loops in `math/base/special/cfloorf` [(#3113)](https://github.com/stdlib-js/stdlib/pull/3113) _(by Gunj Joshi)_
- [`47cfa90`](https://github.com/stdlib-js/stdlib/commit/47cfa907d643a00ac5b3fce9967e655401e110f8) - **feat:** update the return value for `n=1` in `math/base/special/bernoulli` [(#3108)](https://github.com/stdlib-js/stdlib/pull/3108) _(by Gunj Joshi, Athan Reines)_
Expand Down
13 changes: 6 additions & 7 deletions base/assert/is-evenf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,11 @@ bool = isEvenf( NaN );
var randu = require( '@stdlib/random/array/discrete-uniform' );
var isEvenf = require( '@stdlib/math/base/assert/is-evenf' );
var bool;
var x;
var i;
x = randu( 100, 0, 100 );
var x = randu( 100, 0, 100 );
var i;
for ( i = 0; i < 100; i++ ) {
bool = isEvenf( x[ i ] );
console.log( '%d is %s', x[ i ], ( bool ) ? 'even' : 'not even' );
console.log( '%d is %s', x[ i ], ( isEvenf( x[ i ] ) ) ? 'even' : 'not even' );
}
```

Expand Down Expand Up @@ -135,6 +131,8 @@ for ( i = 0; i < 100; i++ ) {
Tests if a finite single-precision floating-point number is an even number.

```c
#include <stdbool.h>
bool out = stdlib_base_is_evenf( 1.0f );
// returns false
Expand Down Expand Up @@ -169,6 +167,7 @@ bool stdlib_base_is_evenf( const float x );
### Examples
```c
#include "stdlib/math/base/assert/is_evenf.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
Expand Down
10 changes: 3 additions & 7 deletions base/assert/is-evenf/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@
var randu = require( '@stdlib/random/array/discrete-uniform' );
var isEvenf = require( './../lib' );

var bool;
var x;
var i;

x = randu( 100, 0, 100 );
var x = randu( 100, 0, 100 );

var i;
for ( i = 0; i < 100; i++ ) {
bool = isEvenf( x[ i ] );
console.log( '%d is %s', x[ i ], ( bool ) ? 'even' : 'not even' );
console.log( '%d is %s', x[ i ], ( isEvenf( x[ i ] ) ) ? 'even' : 'not even' );
}
4 changes: 4 additions & 0 deletions base/assert/is-evenf/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/napi/argv",
"@stdlib/napi/argv-float",
"@stdlib/napi/create-int32",
"@stdlib/napi/export",
"@stdlib/math/base/assert/is-integerf"
]
},
Expand Down
65 changes: 9 additions & 56 deletions base/assert/is-evenf/src/addon.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
*/

#include "stdlib/math/base/assert/is_evenf.h"
#include "stdlib/napi/argv.h"
#include "stdlib/napi/argv_float.h"
#include "stdlib/napi/create_int32.h"
#include "stdlib/napi/export.h"
#include <node_api.h>
#include <stdint.h>
#include <assert.h>

/**
* Receives JavaScript callback invocation data.
Expand All @@ -29,60 +32,10 @@
* @return Node-API value
*/
static napi_value addon( napi_env env, napi_callback_info info ) {
napi_status status;

// Get callback arguments:
size_t argc = 1;
napi_value argv[ 1 ];
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
assert( status == napi_ok );

// Check whether we were provided the correct number of arguments:
if ( argc < 1 ) {
status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." );
assert( status == napi_ok );
return NULL;
}
if ( argc > 1 ) {
status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." );
assert( status == napi_ok );
return NULL;
}

napi_valuetype vtype0;
status = napi_typeof( env, argv[ 0 ], &vtype0 );
assert( status == napi_ok );
if ( vtype0 != napi_number ) {
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
assert( status == napi_ok );
return NULL;
}

double x;
status = napi_get_value_double( env, argv[ 0 ], &x );
assert( status == napi_ok );

bool result = stdlib_base_is_evenf( (float)x );

napi_value v;
status = napi_create_int32( env, (int32_t)result, &v );
assert( status == napi_ok );

return v;
}

/**
* Initializes a Node-API module.
*
* @param env environment under which the function is invoked
* @param exports exports object
* @return main export
*/
static napi_value init( napi_env env, napi_value exports ) {
napi_value fcn;
napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn );
assert( status == napi_ok );
return fcn;
STDLIB_NAPI_ARGV( env, info, argv, argc, 1 );
STDLIB_NAPI_ARGV_FLOAT( env, x, argv, 0 );
STDLIB_NAPI_CREATE_INT32( env, (int32_t)stdlib_base_is_evenf( x ), out );
return out;
}

NAPI_MODULE( NODE_GYP_MODULE_NAME, init )
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

0 comments on commit 704c1ce

Please sign in to comment.