Skip to content

Commit f6f2823

Browse files
committed
Auto-generated commit
1 parent d5390f5 commit f6f2823

File tree

9 files changed

+36
-30
lines changed

9 files changed

+36
-30
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@
220220

221221
### BREAKING CHANGES
222222

223+
- [`3d340e2`](https://github.com/stdlib-js/stdlib/commit/3d340e2d72c1601c2286210f89d182e4132befed): update signature to accept doubles
224+
225+
- User code should behave similarly in the primary case of providing integer-valued input values. However, no longer will real-values truncate. Now, real-valued inputs will result in `NaN`, which is, arguably, better behavior, as real-to-integer truncation can be a source of silent bugs.
226+
223227
- [`709c1ab`](https://github.com/stdlib-js/stdlib/commit/709c1abf833a21997dd32edb395649e0a9e925df): update signature to accept floats
224228

225229
- User code should behave similarly in the primary case of providing integer-valued input values. However, no longer will real-values truncate. Now, real-valued inputs will result in `NaN`, which is, arguably, better behavior, as real-to-integer truncation can be a source of silent bugs.
@@ -573,6 +577,7 @@ A total of 62 issues were closed in this release:
573577

574578
<details>
575579

580+
- [`3d340e2`](https://github.com/stdlib-js/stdlib/commit/3d340e2d72c1601c2286210f89d182e4132befed) - **refactor:** modify C implementation to accept `double` instead of `int32` in `math/base/special/lucas` [(#7936)](https://github.com/stdlib-js/stdlib/pull/7936) _(by Gunj Joshi)_
576581
- [`709c1ab`](https://github.com/stdlib-js/stdlib/commit/709c1abf833a21997dd32edb395649e0a9e925df) - **refactor:** modify C implementation to accept `float` instead of `int32` in `math/base/special/fibonaccif` [(#7938)](https://github.com/stdlib-js/stdlib/pull/7938) _(by Gunj Joshi)_
577582
- [`c5b3e0a`](https://github.com/stdlib-js/stdlib/commit/c5b3e0a0dab79dd39984f0a6bf45cd1a80f1f865) - **docs:** replace integers with doubles in `math/base/special/fibonacci` [(#7937)](https://github.com/stdlib-js/stdlib/pull/7937) _(by Gunj Joshi)_
578583
- [`0283804`](https://github.com/stdlib-js/stdlib/commit/02838049b98a8ae3c595714e397364aace06f7b9) - **chore:** add structured package data for `math/base/special/absgammalnf` [(#7925)](https://github.com/stdlib-js/stdlib/pull/7925) _(by Gunj Joshi, Athan Reines)_

base/special/lucas/README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,19 @@ for ( i = 0; i < 77; i++ ) {
174174
Computes the nth [Lucas number][lucas-number].
175175

176176
```c
177-
double out = stdlib_base_lucas( 0 );
178-
// returns 2
177+
double out = stdlib_base_lucas( 0.0 );
178+
// returns 2.0
179179

180-
out = stdlib_base_lucas( 1 );
181-
// returns 1
180+
out = stdlib_base_lucas( 1.0 );
181+
// returns 1.0
182182
```
183183

184184
The function accepts the following arguments:
185185

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

188188
```c
189-
double stdlib_base_lucas( const int32_t n );
189+
double stdlib_base_lucas( const double n );
190190
```
191191
192192
</section>
@@ -210,15 +210,14 @@ double stdlib_base_lucas( const int32_t n );
210210
```c
211211
#include "stdlib/math/base/special/lucas.h"
212212
#include <stdio.h>
213-
#include <stdint.h>
214213
215214
int main( void ) {
216-
int32_t i;
215+
double i;
217216
double v;
218217
219-
for ( i = 0; i < 77; i++ ) {
218+
for ( i = 0.0; i < 77.0; i++ ) {
220219
v = stdlib_base_lucas( i );
221-
printf( "lucas(%d) = %lf\n", i, v );
220+
printf( "lucas(%lf) = %lf\n", i, v );
222221
}
223222
}
224223
```

base/special/lucas/benchmark/c/native/benchmark.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
* Prints the TAP version.
3232
*/
33-
void print_version() {
33+
static void print_version( void ) {
3434
printf( "TAP version 13\n" );
3535
}
3636

@@ -91,14 +91,14 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
int32_t x;
94+
double x;
9595
double t;
9696
double y;
9797
int i;
9898

9999
t = tic();
100100
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = (int32_t)( 76.0*rand_double() );
101+
x = ( 76.0*rand_double() );
102102
y = stdlib_base_lucas( x );
103103
if ( y != y ) {
104104
printf( "should not return NaN\n" );

base/special/lucas/examples/c/example.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818

1919
#include "stdlib/math/base/special/lucas.h"
2020
#include <stdio.h>
21-
#include <stdint.h>
2221

2322
int main( void ) {
24-
int32_t i;
23+
double i;
2524
double v;
2625

27-
for ( i = 0; i < 77; i++ ) {
26+
for ( i = 0.0; i < 77.0; i++ ) {
2827
v = stdlib_base_lucas( i );
29-
printf( "lucas(%d) = %lf\n", i, v );
28+
printf( "lucas(%lf) = %lf\n", i, v );
3029
}
3130
}

base/special/lucas/include/stdlib/math/base/special/lucas.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#ifndef STDLIB_MATH_BASE_SPECIAL_LUCAS_H
2020
#define STDLIB_MATH_BASE_SPECIAL_LUCAS_H
2121

22-
#include <stdint.h>
23-
2422
/*
2523
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
2624
*/
@@ -31,7 +29,7 @@ extern "C" {
3129
/**
3230
* Computes the nth Lucas number.
3331
*/
34-
double stdlib_base_lucas( const int32_t n );
32+
double stdlib_base_lucas( const double n );
3533

3634
#ifdef __cplusplus
3735
}

base/special/lucas/lib/main.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

2323
var isnan = require( './../../../../base/assert/is-nan' );
24-
var isInteger = require( './../../../../base/assert/is-integer' );
24+
var isNonNegativeInteger = require( './../../../../base/assert/is-nonnegative-integer' );
2525
var MAX_LUCAS = require( '@stdlib/constants/float64/max-safe-nth-lucas' );
2626
var LUCAS = require( './lucas.json' );
2727

@@ -77,8 +77,7 @@ var LUCAS = require( './lucas.json' );
7777
function lucas( n ) {
7878
if (
7979
isnan( n ) ||
80-
isInteger( n ) === false ||
81-
n < 0 ||
80+
!isNonNegativeInteger( n ) ||
8281
n > MAX_LUCAS
8382
) {
8483
return NaN;

base/special/lucas/manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"libpath": [],
3838
"dependencies": [
3939
"@stdlib/math/base/napi/unary",
40+
"@stdlib/math/base/assert/is-nonnegative-integer",
4041
"@stdlib/constants/float64/max-safe-nth-lucas"
4142
]
4243
},
@@ -51,6 +52,7 @@
5152
"libraries": [],
5253
"libpath": [],
5354
"dependencies": [
55+
"@stdlib/math/base/assert/is-nonnegative-integer",
5456
"@stdlib/constants/float64/max-safe-nth-lucas"
5557
]
5658
},
@@ -65,6 +67,7 @@
6567
"libraries": [],
6668
"libpath": [],
6769
"dependencies": [
70+
"@stdlib/math/base/assert/is-nonnegative-integer",
6871
"@stdlib/constants/float64/max-safe-nth-lucas"
6972
]
7073
}

base/special/lucas/src/addon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
#include "stdlib/math/base/special/lucas.h"
2020
#include "stdlib/math/base/napi/unary.h"
2121

22-
STDLIB_MATH_BASE_NAPI_MODULE_I_D( stdlib_base_lucas )
22+
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_lucas )

base/special/lucas/src/main.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
*/
1818

1919
#include "stdlib/math/base/special/lucas.h"
20+
#include "stdlib/math/base/assert/is_nonnegative_integer.h"
2021
#include "stdlib/constants/float64/max_safe_nth_lucas.h"
22+
#include <stdint.h>
23+
#include <stdlib.h>
2124

2225
static const int64_t lucas_value[ 77 ] = {
2326
2,
@@ -106,16 +109,16 @@ static const int64_t lucas_value[ 77 ] = {
106109
* @return output value
107110
*
108111
* @example
109-
* double out = stdlib_base_lucas( 1 );
110-
* // returns 1
112+
* double out = stdlib_base_lucas( 1.0 );
113+
* // returns 1.0
111114
*
112115
* @example
113-
* double out = stdlib_base_lucas( -1 );
116+
* double out = stdlib_base_lucas( -1.0 );
114117
* // returns NaN
115118
*/
116-
double stdlib_base_lucas( const int32_t n ) {
117-
if ( n < 0 || n > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_LUCAS ) {
119+
double stdlib_base_lucas( const double n ) {
120+
if ( !stdlib_base_is_nonnegative_integer( n ) || n > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_LUCAS ) {
118121
return 0.0 / 0.0; // NaN
119122
}
120-
return lucas_value[ n ];
123+
return lucas_value[ (size_t)n ];
121124
}

0 commit comments

Comments
 (0)