Skip to content

Commit 24835b6

Browse files
committed
feat: add constants/float32/max-safe-nth-tribonacci
1 parent a0ba090 commit 24835b6

File tree

10 files changed

+542
-0
lines changed

10 files changed

+542
-0
lines changed
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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+
# FLOAT64_MAX_SAFE_NTH_TRIBONACCI
22+
23+
> Maximum safe nth [Tribonacci number][tribonacci-number] when stored in [double-precision floating-point][ieee754] format.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
<!-- eslint-disable id-length -->
30+
31+
```javascript
32+
var FLOAT64_MAX_SAFE_NTH_TRIBONACCI = require( '@stdlib/constants/float64/max-safe-nth-tribonacci' );
33+
```
34+
35+
#### FLOAT64_MAX_SAFE_NTH_TRIBONACCI
36+
37+
Maximum [safe][safe-integers] nth [Tribonacci number][tribonacci-number] when stored in [double-precision floating-point][ieee754] format.
38+
39+
<!-- eslint-disable id-length -->
40+
41+
```javascript
42+
var bool = ( FLOAT64_MAX_SAFE_NTH_TRIBONACCI === 63 );
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 FLOAT64_MAX_SAFE_NTH_TRIBONACCI = require( '@stdlib/constants/float64/max-safe-nth-tribonacci' );
60+
61+
var v;
62+
var i;
63+
64+
function tribonacci( n ) {
65+
var a;
66+
var b;
67+
var c;
68+
var d;
69+
var i;
70+
71+
a = 0;
72+
b = 0;
73+
c = 1;
74+
if ( n === 0 ) {
75+
return a;
76+
}
77+
if ( n === 1 ) {
78+
return b;
79+
}
80+
if ( n === 2 ) {
81+
return c;
82+
}
83+
for ( i = 3; i <= n; i++ ) {
84+
d = a + b + c;
85+
a = b;
86+
b = c;
87+
c = d;
88+
}
89+
return c;
90+
}
91+
92+
for ( i = 0; i < 100; i++ ) {
93+
v = tribonacci( i );
94+
if ( i > FLOAT64_MAX_SAFE_NTH_TRIBONACCI ) {
95+
console.log( 'Unsafe: %d', v );
96+
} else {
97+
console.log( 'Safe: %d', v );
98+
}
99+
}
100+
```
101+
102+
</section>
103+
104+
<!-- /.examples -->
105+
106+
<!-- C interface documentation. -->
107+
108+
* * *
109+
110+
<section class="c">
111+
112+
## C APIs
113+
114+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
115+
116+
<section class="intro">
117+
118+
</section>
119+
120+
<!-- /.intro -->
121+
122+
<!-- C usage documentation. -->
123+
124+
<section class="usage">
125+
126+
### Usage
127+
128+
```c
129+
#include "stdlib/constants/float64/max_safe_nth_tribonacci.h"
130+
```
131+
132+
#### STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_TRIBONACCI
133+
134+
Maximum [safe][safe-integers] nth [Tribonacci number][tribonacci-number] when stored in [double-precision floating-point][ieee754] format.
135+
136+
</section>
137+
138+
<!-- /.usage -->
139+
140+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
141+
142+
<section class="notes">
143+
144+
</section>
145+
146+
<!-- /.notes -->
147+
148+
<!-- C API usage examples. -->
149+
150+
<section class="examples">
151+
152+
</section>
153+
154+
<!-- /.examples -->
155+
156+
</section>
157+
158+
<!-- /.c -->
159+
160+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
161+
162+
<section class="related">
163+
164+
</section>
165+
166+
<!-- /.related -->
167+
168+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
169+
170+
<section class="links">
171+
172+
[safe-integers]: http://www.2ality.com/2013/10/safe-integers.html
173+
174+
[tribonacci-number]: https://en.wikipedia.org/wiki/Tribonacci_number
175+
176+
[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
177+
178+
<!-- <related-links> -->
179+
180+
<!-- </related-links> -->
181+
182+
</section>
183+
184+
<!-- /.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 Tribonacci number when stored in double-precision
4+
floating-point format.
5+
6+
Examples
7+
--------
8+
> {{alias}}
9+
63
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 Tribonacci number when stored in double-precision floating-point format.
23+
*
24+
* @example
25+
* var max = FLOAT64_MAX_SAFE_NTH_TRIBONACCI;
26+
* // returns 63
27+
*/
28+
declare const FLOAT64_MAX_SAFE_NTH_TRIBONACCI: number;
29+
30+
31+
// EXPORTS //
32+
33+
export = FLOAT64_MAX_SAFE_NTH_TRIBONACCI;
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 FLOAT64_MAX_SAFE_NTH_TRIBONACCI = 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+
FLOAT64_MAX_SAFE_NTH_TRIBONACCI; // $ExpectType number
28+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 FLOAT64_MAX_SAFE_NTH_TRIBONACCI = require( './../lib' );
22+
23+
var v;
24+
var i;
25+
26+
function tribonacci( n ) {
27+
var a;
28+
var b;
29+
var c;
30+
var d;
31+
var i;
32+
33+
a = 0;
34+
b = 0;
35+
c = 1;
36+
if ( n === 0 ) {
37+
return a;
38+
}
39+
if ( n === 1 ) {
40+
return b;
41+
}
42+
if ( n === 2 ) {
43+
return c;
44+
}
45+
for ( i = 3; i <= n; i++ ) {
46+
d = a + b + c;
47+
a = b;
48+
b = c;
49+
c = d;
50+
}
51+
return c;
52+
}
53+
54+
for ( i = 0; i < 100; i++ ) {
55+
v = tribonacci( i );
56+
if ( i > FLOAT64_MAX_SAFE_NTH_TRIBONACCI ) {
57+
console.log( 'Unsafe: %d', v );
58+
} else {
59+
console.log( 'Safe: %d', v );
60+
}
61+
}
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_FLOAT64_MAX_SAFE_NTH_TRIBONACCI_H
20+
#define STDLIB_CONSTANTS_FLOAT64_MAX_SAFE_NTH_TRIBONACCI_H
21+
22+
/**
23+
* Maximum safe nth Tribonacci number when stored in single-precision floating-point format.
24+
*/
25+
#define STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_TRIBONACCI 63
26+
27+
#endif // !STDLIB_CONSTANTS_FLOAT64_MAX_SAFE_NTH_TRIBONACCI_H

0 commit comments

Comments
 (0)