Skip to content

Commit ed63505

Browse files
aayush0325kgryte
andauthored
feat: add constants/float32/max-safe-nth-lucas
PR-URL: #3337 Closes: #3336 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Signed-off-by: Athan Reines <[email protected]>
1 parent 5a4f6ed commit ed63505

File tree

10 files changed

+523
-0
lines changed

10 files changed

+523
-0
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# FLOAT32_MAX_SAFE_NTH_LUCAS
22+
23+
> Maximum safe nth [Lucas number][lucas-number] when stored in [single-precision floating-point][ieee754] format.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
<!-- eslint-disable id-length -->
30+
31+
```javascript
32+
var FLOAT32_MAX_SAFE_NTH_LUCAS = require( '@stdlib/constants/float32/max-safe-nth-lucas' );
33+
```
34+
35+
#### FLOAT32_MAX_SAFE_NTH_LUCAS
36+
37+
The maximum [safe][safe-integers] nth [Lucas number][lucas-number] when stored in [single-precision floating-point][ieee754] format.
38+
39+
<!-- eslint-disable id-length -->
40+
41+
```javascript
42+
var bool = ( FLOAT32_MAX_SAFE_NTH_LUCAS === 34 );
43+
// returns true
44+
```
45+
46+
</section>
47+
48+
<!-- /.usage -->
49+
50+
<section class="examples">
51+
52+
## Examples
53+
54+
<!-- eslint-disable id-length -->
55+
56+
<!-- eslint no-undef: "error" -->
57+
58+
```javascript
59+
var FLOAT32_MAX_SAFE_NTH_LUCAS = require( '@stdlib/constants/float32/max-safe-nth-lucas' );
60+
61+
function lucas( n ) {
62+
var a;
63+
var b;
64+
var c;
65+
var i;
66+
67+
a = 2;
68+
if ( n === 0 ) {
69+
return a;
70+
}
71+
b = 1;
72+
for ( i = 2; i <= n; i++ ) {
73+
c = a + b;
74+
a = b;
75+
b = c;
76+
}
77+
return b;
78+
}
79+
80+
var v;
81+
var i;
82+
for ( i = 0; i < 100; i++ ) {
83+
v = lucas( i );
84+
if ( i > FLOAT32_MAX_SAFE_NTH_LUCAS ) {
85+
console.log( 'Unsafe: %d', v );
86+
} else {
87+
console.log( 'Safe: %d', v );
88+
}
89+
}
90+
```
91+
92+
</section>
93+
94+
<!-- /.examples -->
95+
96+
<!-- C interface documentation. -->
97+
98+
* * *
99+
100+
<section class="c">
101+
102+
## C APIs
103+
104+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
105+
106+
<section class="intro">
107+
108+
</section>
109+
110+
<!-- /.intro -->
111+
112+
<!-- C usage documentation. -->
113+
114+
<section class="usage">
115+
116+
### Usage
117+
118+
```c
119+
#include "stdlib/constants/float32/max_safe_nth_lucas.h"
120+
```
121+
122+
#### STDLIB_CONSTANT_FLOAT32_MAX_SAFE_NTH_LUCAS
123+
124+
Macro for the maximum [safe][safe-integers] nth [Lucas number][lucas-number] when stored in [single-precision floating-point][ieee754] format.
125+
126+
</section>
127+
128+
<!-- /.usage -->
129+
130+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
131+
132+
<section class="notes">
133+
134+
</section>
135+
136+
<!-- /.notes -->
137+
138+
<!-- C API usage examples. -->
139+
140+
<section class="examples">
141+
142+
</section>
143+
144+
<!-- /.examples -->
145+
146+
</section>
147+
148+
<!-- /.c -->
149+
150+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
151+
152+
<section class="related">
153+
154+
</section>
155+
156+
<!-- /.related -->
157+
158+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
159+
160+
<section class="links">
161+
162+
[safe-integers]: http://www.2ality.com/2013/10/safe-integers.html
163+
164+
[lucas-number]: https://en.wikipedia.org/wiki/Lucas_number
165+
166+
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
167+
168+
<!-- <related-links> -->
169+
170+
<!-- </related-links> -->
171+
172+
</section>
173+
174+
<!-- /.links -->
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
{{alias}}
3+
Maximum safe nth Lucas number when stored in single-precision floating-point
4+
format.
5+
6+
Examples
7+
--------
8+
> {{alias}}
9+
34
10+
11+
See Also
12+
--------
13+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Maximum safe nth Lucas number when stored in single-precision floating-point format.
23+
*
24+
* @example
25+
* var max = FLOAT32_MAX_SAFE_NTH_LUCAS;
26+
* // returns 34
27+
*/
28+
declare const FLOAT32_MAX_SAFE_NTH_LUCAS: number;
29+
30+
31+
// EXPORTS //
32+
33+
export = FLOAT32_MAX_SAFE_NTH_LUCAS;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import FLOAT32_MAX_SAFE_NTH_LUCAS = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The export is a number...
25+
{
26+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
27+
FLOAT32_MAX_SAFE_NTH_LUCAS; // $ExpectType number
28+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var FLOAT32_MAX_SAFE_NTH_LUCAS = require( './../lib' ); // eslint-disable-line id-length
22+
23+
function lucas( n ) {
24+
var a;
25+
var b;
26+
var c;
27+
var i;
28+
29+
a = 2;
30+
if ( n === 0 ) {
31+
return a;
32+
}
33+
b = 1;
34+
for ( i = 2; i <= n; i++ ) {
35+
c = a + b;
36+
a = b;
37+
b = c;
38+
}
39+
return b;
40+
}
41+
42+
var v;
43+
var i;
44+
for ( i = 0; i < 100; i++ ) {
45+
v = lucas( i );
46+
if ( i > FLOAT32_MAX_SAFE_NTH_LUCAS ) {
47+
console.log( 'Unsafe: %d', v );
48+
} else {
49+
console.log( 'Safe: %d', v );
50+
}
51+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#ifndef STDLIB_CONSTANTS_FLOAT32_MAX_SAFE_NTH_LUCAS_H
20+
#define STDLIB_CONSTANTS_FLOAT32_MAX_SAFE_NTH_LUCAS_H
21+
22+
/**
23+
* Macro for the maximum safe nth Lucas number when stored in single-precision floating-point format.
24+
*/
25+
#define STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_LUCAS 34
26+
27+
#endif // !STDLIB_CONSTANTS_FLOAT32_MAX_SAFE_NTH_LUCAS_H
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable id-length */
20+
21+
'use strict';
22+
23+
/**
24+
* Maximum safe nth Lucas number when stored in single-precision floating-point format.
25+
*
26+
* @module @stdlib/constants/float32/max-safe-nth-lucas
27+
* @type {integer}
28+
*
29+
* @example
30+
* var FLOAT32_MAX_SAFE_NTH_LUCAS = require( '@stdlib/constants/float32/max-safe-nth-lucas' );
31+
* // returns 34
32+
*/
33+
34+
35+
// MAIN //
36+
37+
/**
38+
* The maximum safe nth Lucas number when stored in single-precision floating-point format.
39+
*
40+
* @constant
41+
* @type {integer}
42+
* @default 34
43+
* @see [Lucas number]{@link https://en.wikipedia.org/wiki/Lucas_number}
44+
* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}
45+
*/
46+
var FLOAT32_MAX_SAFE_NTH_LUCAS = 34|0; // asm type annotation
47+
48+
49+
// EXPORTS //
50+
51+
module.exports = FLOAT32_MAX_SAFE_NTH_LUCAS;

0 commit comments

Comments
 (0)