Skip to content

Commit 6853d27

Browse files
authored
feat: add constants/float32/phi
PR-URL: #2249 Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 9761cac commit 6853d27

File tree

10 files changed

+492
-0
lines changed

10 files changed

+492
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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_PHI
22+
23+
> [Golden ratio][phi].
24+
25+
<section class="intro">
26+
27+
The [golden ratio][phi] can be defined algebraically as
28+
29+
<!-- <equation class="equation" label="eq:golden_ratio" align="center" raw="\phi = \frac{1 + \sqrt{5}}{2}" alt="Golden ratio"> -->
30+
31+
```math
32+
\phi = \frac{1 + \sqrt{5}}{2}
33+
```
34+
35+
<!-- <div class="equation" align="center" data-raw-text="\phi = \frac{1 + \sqrt{5}}{2}" data-equation="eq:golden_ratio">
36+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@5d87cc7cb2c58aeb732872f89562d2c89571cc8a/lib/node_modules/@stdlib/constants/float64/phi/docs/img/equation_golden_ratio.svg" alt="Golden ratio">
37+
<br>
38+
</div> -->
39+
40+
<!-- </equation> -->
41+
42+
</section>
43+
44+
<!-- /.intro -->
45+
46+
<section class="usage">
47+
48+
## Usage
49+
50+
```javascript
51+
var FLOAT32_PHI = require( '@stdlib/constants/float32/phi' );
52+
```
53+
54+
#### FLOAT32_PHI
55+
56+
The [golden ratio][phi-value].
57+
58+
```javascript
59+
var bool = ( FLOAT32_PHI === 1.6180340051651 );
60+
// returns true
61+
```
62+
63+
</section>
64+
65+
<!-- /.usage -->
66+
67+
<section class="examples">
68+
69+
## Examples
70+
71+
<!-- TODO: better example using Fibonacci(?) -->
72+
73+
<!-- eslint no-undef: "error" -->
74+
75+
```javascript
76+
var FLOAT32_PHI = require( '@stdlib/constants/float32/phi' );
77+
78+
console.log( FLOAT32_PHI );
79+
// => 1.6180340051651
80+
```
81+
82+
</section>
83+
84+
<!-- /.examples -->
85+
86+
<!-- C interface documentation. -->
87+
88+
* * *
89+
90+
<section class="c">
91+
92+
## C APIs
93+
94+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
95+
96+
<section class="intro">
97+
98+
</section>
99+
100+
<!-- /.intro -->
101+
102+
<!-- C usage documentation. -->
103+
104+
<section class="usage">
105+
106+
### Usage
107+
108+
```c
109+
#include "stdlib/constants/float32/phi.h"
110+
```
111+
112+
#### STDLIB_CONSTANT_FLOAT32_PHI
113+
114+
Macro for the [golden ratio][phi-value].
115+
116+
</section>
117+
118+
<!-- /.usage -->
119+
120+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
121+
122+
<section class="notes">
123+
124+
</section>
125+
126+
<!-- /.notes -->
127+
128+
<!-- C API usage examples. -->
129+
130+
<section class="examples">
131+
132+
</section>
133+
134+
<!-- /.examples -->
135+
136+
</section>
137+
138+
<!-- /.c -->
139+
140+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
141+
142+
<section class="related">
143+
144+
</section>
145+
146+
<!-- /.related -->
147+
148+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
149+
150+
<section class="links">
151+
152+
[phi]: https://en.wikipedia.org/wiki/Golden_ratio
153+
154+
[phi-value]: http://oeis.org/A001622
155+
156+
</section>
157+
158+
<!-- /.links -->
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
{{alias}}
3+
Golden ratio.
4+
5+
Examples
6+
--------
7+
> {{alias}}
8+
1.6180340051651
9+
10+
See Also
11+
--------
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) 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+
* Golden ratio.
23+
*
24+
* @example
25+
* var val = FLOAT32_PHI;
26+
* // returns 1.6180340051651
27+
*/
28+
declare const FLOAT32_PHI: number;
29+
30+
31+
// EXPORTS //
32+
33+
export = FLOAT32_PHI;
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_PHI = 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_PHI; // $ExpectType number
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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_PHI = require( './../lib' );
22+
23+
console.log( FLOAT32_PHI );
24+
// => 1.6180340051651
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_PHI_H
20+
#define STDLIB_CONSTANTS_FLOAT32_PHI_H
21+
22+
/**
23+
* Macro for the golden ratio.
24+
*/
25+
#define STDLIB_CONSTANT_FLOAT32_PHI 1.618033988749894848f
26+
27+
#endif // !STDLIB_CONSTANTS_FLOAT32_PHI_H
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
/**
22+
* Golden ratio.
23+
*
24+
* @module @stdlib/constants/float32/phi
25+
* @type {number}
26+
*
27+
* @example
28+
* var FLOAT32_PHI = require( '@stdlib/constants/float32/phi' );
29+
* // returns 1.6180340051651
30+
*/
31+
32+
// MODULES //
33+
34+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
35+
36+
37+
// MAIN //
38+
39+
/**
40+
* Golden ratio.
41+
*
42+
* @constant
43+
* @type {number}
44+
* @default 1.6180340051651
45+
* @see [OEIS]{@link http://oeis.org/A001622}
46+
* @see [Wikipedia]{@link https://en.wikipedia.org/wiki/Golden_ratio}
47+
*/
48+
var FLOAT32_PHI = float64ToFloat32( 1.61803398874989484820458683436563811772030917980576286213544862 ); // eslint-disable-line max-len
49+
50+
51+
// EXPORTS //
52+
53+
module.exports = FLOAT32_PHI;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"options": {},
3+
"fields": [
4+
{
5+
"field": "src",
6+
"resolve": true,
7+
"relative": true
8+
},
9+
{
10+
"field": "include",
11+
"resolve": true,
12+
"relative": true
13+
},
14+
{
15+
"field": "libraries",
16+
"resolve": false,
17+
"relative": false
18+
},
19+
{
20+
"field": "libpath",
21+
"resolve": true,
22+
"relative": false
23+
}
24+
],
25+
"confs": [
26+
{
27+
"src": [],
28+
"include": [
29+
"./include"
30+
],
31+
"libraries": [],
32+
"libpath": [],
33+
"dependencies": []
34+
}
35+
]
36+
}

0 commit comments

Comments
 (0)