Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/node_modules/@stdlib/math/base/special/negalucas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,19 @@ for ( i = 0; i > -77; i-- ) {
Computes the nth [negaLucas number][lucas-number].

```c
double out = stdlib_base_negalucas( 0 );
// returns 0
double out = stdlib_base_negalucas( 0.0 );
// returns 0.0

out = stdlib_base_negalucas( -1 );
// returns -1
out = stdlib_base_negalucas( -1.0 );
// returns -1.0
```

The function accepts the following arguments:

- **n**: `[in] int32_t` input value.
- **n**: `[in] double` input value.

```c
double stdlib_base_negalucas( const int32_t n );
double stdlib_base_negalucas( const double n );
```

</section>
Expand All @@ -227,15 +227,14 @@ double stdlib_base_negalucas( const int32_t n );
```c
#include "stdlib/math/base/special/negalucas.h"
#include <stdio.h>
#include <stdint.h>

int main( void ) {
int32_t i;
double i;
double v;

for ( i = 0; i > -77; i-- ) {
for ( i = 0.0; i > -77.0; i-- ) {
v = stdlib_base_negalucas( i );
printf( "negalucas(%d) = %lf\n", i, v );
printf( "negalucas(%lf) = %lf\n", i, v );
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* Prints the TAP version.
*/
void print_version() {
static void print_version( void ) {
printf( "TAP version 13\n" );
}

Expand Down Expand Up @@ -91,13 +91,13 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
int32_t x[ 100 ];
double x[ 100 ];
double t;
double y;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = (int32_t)( 77.0*rand_double() );
x[ i ] = ( 77.0*rand_double() );
}

t = tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

#include "stdlib/math/base/special/negalucas.h"
#include <stdio.h>
#include <stdint.h>

int main( void ) {
int32_t i;
double i;
double v;

for ( i = 0; i > -77; i-- ) {
for ( i = 0.0; i > -77.0; i-- ) {
v = stdlib_base_negalucas( i );
printf( "negalucas(%d) = %lf\n", i, v );
printf( "negalucas(%lf) = %lf\n", i, v );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#ifndef STDLIB_MATH_BASE_SPECIAL_NEGALUCAS_H
#define STDLIB_MATH_BASE_SPECIAL_NEGALUCAS_H

#include <stdint.h>

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
Expand All @@ -31,7 +29,7 @@ extern "C" {
/**
* Computes the nth negaLucas number.
*/
double stdlib_base_negalucas( const int32_t n );
double stdlib_base_negalucas( const double n );

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/math/base/special/labs",
"@stdlib/constants/float64/max-safe-nth-lucas"
"@stdlib/math/base/special/abs",
"@stdlib/constants/float64/max-safe-nth-lucas",
"@stdlib/math/base/assert/is-integer"
]
},
{
Expand All @@ -52,8 +53,9 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/labs",
"@stdlib/constants/float64/max-safe-nth-lucas"
"@stdlib/math/base/special/abs",
"@stdlib/constants/float64/max-safe-nth-lucas",
"@stdlib/math/base/assert/is-integer"
]
},
{
Expand All @@ -67,8 +69,9 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/labs",
"@stdlib/constants/float64/max-safe-nth-lucas"
"@stdlib/math/base/special/abs",
"@stdlib/constants/float64/max-safe-nth-lucas",
"@stdlib/math/base/assert/is-integer"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#include "stdlib/math/base/special/negalucas.h"
#include "stdlib/math/base/napi/unary.h"

STDLIB_MATH_BASE_NAPI_MODULE_I_D( stdlib_base_negalucas )
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_negalucas )
19 changes: 11 additions & 8 deletions lib/node_modules/@stdlib/math/base/special/negalucas/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
*/

#include "stdlib/math/base/special/negalucas.h"
#include "stdlib/math/base/special/labs.h"
#include "stdlib/math/base/assert/is_integer.h"
#include "stdlib/math/base/special/abs.h"
#include "stdlib/constants/float64/max_safe_nth_lucas.h"
#include <stdint.h>
#include <stdlib.h>

static const int64_t negalucas_value[ 77 ] = {
2,
Expand Down Expand Up @@ -107,17 +110,17 @@ static const int64_t negalucas_value[ 77 ] = {
* @return output value
*
* @example
* double out = stdlib_base_negalucas( -1 );
* // returns -1
* double out = stdlib_base_negalucas( -1.0 );
* // returns -1.0
*
* @example
* double out = stdlib_base_negalucas( 1 );
* double out = stdlib_base_negalucas( 1.0 );
* // returns NaN
*/
double stdlib_base_negalucas( const int32_t n ) {
int32_t an = stdlib_base_labs( n );
if ( n > 0 || an > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_LUCAS ) {
double stdlib_base_negalucas( const double n ) {
double an = stdlib_base_abs( n );
if ( !stdlib_base_is_integer( n ) || n > 0.0 || an > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_LUCAS ) {
return 0.0 / 0.0; // NaN
}
return negalucas_value[ an ];
return negalucas_value[ (size_t)an ];
}