Skip to content

Commit f5a2531

Browse files
committed
feat: add constants/float32/max-safe-lucas
1 parent bb0671b commit f5a2531

File tree

10 files changed

+513
-0
lines changed

10 files changed

+513
-0
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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_LUCAS
22+
23+
> Maximum safe [Lucas number][lucas-number] when stored in [single-precision floating-point][ieee754] format.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var FLOAT32_MAX_SAFE_LUCAS = require( '@stdlib/constants/float32/max-safe-lucas' );
31+
```
32+
33+
#### FLOAT32_MAX_SAFE_LUCAS
34+
35+
The maximum [safe][safe-integers] [Lucas number][lucas-number] when stored in [single-precision floating-point][ieee754] format.
36+
37+
```javascript
38+
var bool = ( FLOAT32_MAX_SAFE_LUCAS === 1197222447 );
39+
// returns true
40+
```
41+
42+
</section>
43+
44+
<!-- /.usage -->
45+
46+
<section class="examples">
47+
48+
## Examples
49+
50+
<!-- eslint no-undef: "error" -->
51+
52+
```javascript
53+
var FLOAT32_MAX_SAFE_LUCAS = require( '@stdlib/constants/float32/max-safe-lucas' );
54+
55+
var v;
56+
var i;
57+
58+
function lucas( n ) {
59+
var a;
60+
var b;
61+
var c;
62+
var i;
63+
64+
a = 2;
65+
if ( n === 0 ) {
66+
return a;
67+
}
68+
b = 1;
69+
for ( i = 2; i <= n; i++ ) {
70+
c = a + b;
71+
a = b;
72+
b = c;
73+
}
74+
return b;
75+
}
76+
77+
for ( i = 0; i < 100; i++ ) {
78+
v = lucas( i );
79+
if ( v > FLOAT32_MAX_SAFE_LUCAS ) {
80+
console.log( 'Unsafe: %d', v );
81+
} else {
82+
console.log( 'Safe: %d', v );
83+
}
84+
}
85+
```
86+
87+
</section>
88+
89+
<!-- /.examples -->
90+
91+
<!-- C interface documentation. -->
92+
93+
* * *
94+
95+
<section class="c">
96+
97+
## C APIs
98+
99+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
100+
101+
<section class="intro">
102+
103+
</section>
104+
105+
<!-- /.intro -->
106+
107+
<!-- C usage documentation. -->
108+
109+
<section class="usage">
110+
111+
### Usage
112+
113+
```c
114+
#include "stdlib/constants/float32/max_safe_lucas.h"
115+
```
116+
117+
#### STDLIB_CONSTANT_FLOAT32_MAX_SAFE_LUCAS
118+
119+
Macro for the maximum [safe][safe-integers] [Lucas number][lucas-number] when stored in [single-precision floating-point][ieee754] format.
120+
121+
</section>
122+
123+
<!-- /.usage -->
124+
125+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
126+
127+
<section class="notes">
128+
129+
</section>
130+
131+
<!-- /.notes -->
132+
133+
<!-- C API usage examples. -->
134+
135+
<section class="examples">
136+
137+
</section>
138+
139+
<!-- /.examples -->
140+
141+
</section>
142+
143+
<!-- /.c -->
144+
145+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
146+
147+
<section class="related">
148+
149+
</section>
150+
151+
<!-- /.related -->
152+
153+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
154+
155+
<section class="links">
156+
157+
[safe-integers]: http://www.2ality.com/2013/10/safe-integers.html
158+
159+
[lucas-number]: https://en.wikipedia.org/wiki/Lucas_number
160+
161+
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
162+
163+
</section>
164+
165+
<!-- /.links -->
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
{{alias}}
3+
Maximum safe Lucas number when stored in single-precision floating-point
4+
format.
5+
6+
Examples
7+
--------
8+
> {{alias}}
9+
1197222447
10+
11+
See Also
12+
--------
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) 2025 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 Lucas number when stored in single-precision floating-point format.
23+
*
24+
* @example
25+
* var max = FLOAT32_MAX_SAFE_LUCAS;
26+
* // returns 1197222447
27+
*/
28+
declare const FLOAT32_MAX_SAFE_LUCAS: number;
29+
30+
31+
// EXPORTS //
32+
33+
export = FLOAT32_MAX_SAFE_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) 2025 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_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_LUCAS; // $ExpectType number
28+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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_LUCAS = require( './../lib' );
22+
23+
var v;
24+
var i;
25+
26+
function lucas( n ) {
27+
var a;
28+
var b;
29+
var c;
30+
var i;
31+
32+
a = 2;
33+
if ( n === 0 ) {
34+
return a;
35+
}
36+
b = 1;
37+
for ( i = 2; i <= n; i++ ) {
38+
c = a + b;
39+
a = b;
40+
b = c;
41+
}
42+
return b;
43+
}
44+
45+
for ( i = 0; i < 100; i++ ) {
46+
v = lucas( i );
47+
if ( v > FLOAT32_MAX_SAFE_LUCAS ) {
48+
console.log( 'Unsafe: %d', v );
49+
} else {
50+
console.log( 'Safe: %d', v );
51+
}
52+
}
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) 2025 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_LUCAS_H
20+
#define STDLIB_CONSTANTS_FLOAT32_MAX_SAFE_LUCAS_H
21+
22+
/**
23+
* Macro for the maximum safe Lucas number when stored in single-precision floating-point format.
24+
*/
25+
#define STDLIB_CONSTANT_FLOAT32_MAX_SAFE_LUCAS 1197222447f
26+
27+
#endif // !STDLIB_CONSTANTS_FLOAT32_MAX_SAFE_LUCAS_H
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
/**
22+
* Maximum safe Lucas number when stored in single-precision floating-point format.
23+
*
24+
* @module @stdlib/constants/float32/max-safe-lucas
25+
* @type {integer}
26+
*
27+
* @example
28+
* var FLOAT32_MAX_SAFE_LUCAS = require( '@stdlib/constants/float32/max-safe-lucas' );
29+
* // returns 1197222447
30+
*/
31+
32+
33+
// MAIN //
34+
35+
/**
36+
* The maximum safe Lucas number when stored in single-precision floating-point format.
37+
*
38+
* @constant
39+
* @type {integer}
40+
* @default 1197222447
41+
* @see [Lucas number]{@link https://en.wikipedia.org/wiki/Lucas_number}
42+
* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}
43+
*/
44+
var FLOAT32_MAX_SAFE_LUCAS = 1197222447;
45+
46+
47+
// EXPORTS //
48+
49+
module.exports = FLOAT32_MAX_SAFE_LUCAS;

0 commit comments

Comments
 (0)