Skip to content

Commit 3a9e328

Browse files
committed
feat: add constants/float32/inv-two-pi
1 parent 4304bee commit 3a9e328

File tree

8 files changed

+343
-0
lines changed

8 files changed

+343
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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_INV_TWO_PI
22+
23+
> Inverse of twice the mathematical constant [π][pi] (1/(2π)).
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var FLOAT32_INV_TWO_PI = require( '@stdlib/constants/float32/inv-two-pi' );
31+
```
32+
33+
#### FLOAT32_INV_TWO_PI
34+
35+
Inverse of twice the mathematical constant [π][pi] (1/(2π)).
36+
37+
```javascript
38+
var bool = ( FLOAT32_INV_TWO_PI === 0.15915493667125702 );
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_INV_TWO_PI = require( '@stdlib/constants/float32/inv-two-pi' );
54+
55+
console.log( FLOAT32_INV_TWO_PI );
56+
// => 0.15915493667125702
57+
```
58+
59+
</section>
60+
61+
<!-- /.examples -->
62+
63+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
64+
65+
<section class="related">
66+
67+
</section>
68+
69+
<!-- /.related -->
70+
71+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
72+
73+
<section class="links">
74+
75+
[pi]: https://en.wikipedia.org/wiki/Pi
76+
77+
</section>
78+
79+
<!-- /.links -->
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
{{alias}}
3+
Inverse of twice the mathematical constant `π` (1/(2π)).
4+
5+
Examples
6+
--------
7+
> {{alias}}
8+
0.15915493667125702
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) 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+
* Inverse of twice the mathematical constant `π` (1/(2π)).
23+
*
24+
* @example
25+
* var val = FLOAT32_INV_TWO_PI;
26+
* // returns 0.15915493667125702
27+
*/
28+
declare const FLOAT32_INV_TWO_PI: number;
29+
30+
31+
// EXPORTS //
32+
33+
export = FLOAT32_INV_TWO_PI;
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_INV_TWO_PI = 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_INV_TWO_PI; // $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) 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_INV_TWO_PI = require( './../lib' );
22+
23+
console.log( FLOAT32_INV_TWO_PI );
24+
// => 0.15915493667125702
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+
/**
22+
* Inverse of twice the mathematical constant `π` (1/(2π)).
23+
*
24+
* @module @stdlib/constants/float32/inv-two-pi
25+
* @type {number}
26+
*
27+
* @example
28+
* var FLOAT32_INV_TWO_PI = require( '@stdlib/constants/float32/inv-two-pi' );
29+
* // returns 0.15915493667125702
30+
*/
31+
32+
// MODULES //
33+
34+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
35+
36+
37+
// MAIN //
38+
39+
/**
40+
* Inverse of twice the mathematical constant `π` (1/(2π)).
41+
*
42+
* @constant
43+
* @type {number}
44+
* @default 0.15915493667125702
45+
* @see [Wikipedia]{@link https://en.wikipedia.org/wiki/Pi}
46+
*/
47+
var FLOAT32_INV_TWO_PI = float64ToFloat32( 0.15915494309189535 );
48+
49+
50+
// EXPORTS //
51+
52+
module.exports = FLOAT32_INV_TWO_PI;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"name": "@stdlib/constants/float32/inv-two-pi",
3+
"version": "0.0.0",
4+
"description": "Inverse of 2π (1/(2π)).",
5+
"license": "Apache-2.0",
6+
"author": {
7+
"name": "The Stdlib Authors",
8+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9+
},
10+
"contributors": [
11+
{
12+
"name": "The Stdlib Authors",
13+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14+
}
15+
],
16+
"main": "./lib",
17+
"directories": {
18+
"doc": "./docs",
19+
"example": "./examples",
20+
"lib": "./lib",
21+
"test": "./test"
22+
},
23+
"types": "./docs/types",
24+
"scripts": {},
25+
"homepage": "https://github.com/stdlib-js/stdlib",
26+
"repository": {
27+
"type": "git",
28+
"url": "git://github.com/stdlib-js/stdlib.git"
29+
},
30+
"bugs": {
31+
"url": "https://github.com/stdlib-js/stdlib/issues"
32+
},
33+
"dependencies": {},
34+
"devDependencies": {},
35+
"engines": {
36+
"node": ">=0.10.0",
37+
"npm": ">2.7.0"
38+
},
39+
"os": [
40+
"aix",
41+
"darwin",
42+
"freebsd",
43+
"linux",
44+
"macos",
45+
"openbsd",
46+
"sunos",
47+
"win32",
48+
"windows"
49+
],
50+
"keywords": [
51+
"stdlib",
52+
"stdmath",
53+
"constant",
54+
"const",
55+
"mathematics",
56+
"math",
57+
"inverse",
58+
"inv",
59+
"pi",
60+
"two-pi",
61+
"2pi",
62+
"ieee754",
63+
"float",
64+
"precision",
65+
"floating-point",
66+
"float32"
67+
]
68+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var abs = require( '@stdlib/math/base/special/abs' );
25+
var FLOAT32_INV_TWO_PI = require( './../lib' );
26+
27+
28+
// TESTS //
29+
30+
tape( 'main export is a number', function test( t ) {
31+
t.ok( true, __filename );
32+
t.strictEqual( typeof FLOAT32_INV_TWO_PI, 'number', 'main export is a number' );
33+
t.end();
34+
});
35+
36+
tape( 'the exported value is a single-precision floating-point number equal to 0.15915493667125702', function test( t ) {
37+
t.strictEqual( FLOAT32_INV_TWO_PI, 0.15915493667125702, 'returns expected value' );
38+
t.end();
39+
});
40+
41+
tape( 'the exported value is close to 1/(2*PI) within single-precision tolerance', function test( t ) {
42+
var expected = 1.0 / ( 2.0 * 3.141592653589793 );
43+
var delta = abs( FLOAT32_INV_TWO_PI - expected );
44+
var tol = 1.0e-7; // single-precision tolerance
45+
t.ok( delta <= tol, 'within tolerance. expected: '+expected+'. actual: '+FLOAT32_INV_TWO_PI+'. delta: '+delta+'. tol: '+tol+'.' );
46+
t.end();
47+
});

0 commit comments

Comments
 (0)