Skip to content

Commit 0d59526

Browse files
hrshyakgrytegunjjoshi
authored
feat: add constants/float32/max-safe-lucas
PR-URL: #6374 Ref: #649 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Reviewed-by: Gunj Joshi <[email protected]> Signed-off-by: Gunj Joshi <[email protected]> Signed-off-by: Athan Reines <[email protected]> Co-authored-by: Gunj Joshi <[email protected]>
1 parent e1cc668 commit 0d59526

File tree

10 files changed

+513
-0
lines changed

10 files changed

+513
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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 === 12752043 );
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+
function lucas( n ) {
56+
var a;
57+
var b;
58+
var c;
59+
var i;
60+
61+
a = 2;
62+
if ( n === 0 ) {
63+
return a;
64+
}
65+
b = 1;
66+
for ( i = 2; i <= n; i++ ) {
67+
c = a + b;
68+
a = b;
69+
b = c;
70+
}
71+
return b;
72+
}
73+
74+
var v;
75+
var i;
76+
for ( i = 0; i < 100; i++ ) {
77+
v = lucas( i );
78+
if ( v > FLOAT32_MAX_SAFE_LUCAS ) {
79+
console.log( 'Unsafe: %d', v );
80+
} else {
81+
console.log( 'Safe: %d', v );
82+
}
83+
}
84+
```
85+
86+
</section>
87+
88+
<!-- /.examples -->
89+
90+
<!-- C interface documentation. -->
91+
92+
* * *
93+
94+
<section class="c">
95+
96+
## C APIs
97+
98+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
99+
100+
<section class="intro">
101+
102+
</section>
103+
104+
<!-- /.intro -->
105+
106+
<!-- C usage documentation. -->
107+
108+
<section class="usage">
109+
110+
### Usage
111+
112+
```c
113+
#include "stdlib/constants/float32/max_safe_lucas.h"
114+
```
115+
116+
#### STDLIB_CONSTANT_FLOAT32_MAX_SAFE_LUCAS
117+
118+
Macro for the maximum [safe][safe-integers] [Lucas number][lucas-number] when stored in [single-precision floating-point][ieee754] format.
119+
120+
</section>
121+
122+
<!-- /.usage -->
123+
124+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
125+
126+
<section class="notes">
127+
128+
</section>
129+
130+
<!-- /.notes -->
131+
132+
<!-- C API usage examples. -->
133+
134+
<section class="examples">
135+
136+
</section>
137+
138+
<!-- /.examples -->
139+
140+
</section>
141+
142+
<!-- /.c -->
143+
144+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
145+
146+
<section class="related">
147+
148+
</section>
149+
150+
<!-- /.related -->
151+
152+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
153+
154+
<section class="links">
155+
156+
[safe-integers]: http://www.2ality.com/2013/10/safe-integers.html
157+
158+
[lucas-number]: https://en.wikipedia.org/wiki/Lucas_number
159+
160+
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
161+
162+
<!-- <related-links> -->
163+
164+
<!-- </related-links> -->
165+
166+
</section>
167+
168+
<!-- /.links -->
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+
12752043
10+
11+
See Also
12+
--------
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 12752043
27+
*/
28+
declare const FLOAT32_MAX_SAFE_LUCAS: number;
29+
30+
31+
// EXPORTS //
32+
33+
export = FLOAT32_MAX_SAFE_LUCAS;
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
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 ( v > FLOAT32_MAX_SAFE_LUCAS ) {
47+
console.log( 'Unsafe: %d', v );
48+
} else {
49+
console.log( 'Safe: %d', v );
50+
}
51+
}
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 12752043
26+
27+
#endif // !STDLIB_CONSTANTS_FLOAT32_MAX_SAFE_LUCAS_H
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 12752043
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 12752043
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 = 12752043;
45+
46+
47+
// EXPORTS //
48+
49+
module.exports = FLOAT32_MAX_SAFE_LUCAS;

0 commit comments

Comments
 (0)