Skip to content

Commit 425037b

Browse files
feat: adding the value of half-ln-two for float16
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 4304bee commit 425037b

File tree

8 files changed

+367
-0
lines changed

8 files changed

+367
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
# FLOAT16_HALF_LN2
22+
23+
> One half times the [natural logarithm][@stdlib/math/base/special/ln] of `2` as a half-precision floating-point number.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var FLOAT16_HALF_LN2 = require( '@stdlib/constants/float16/half-ln-two' );
31+
```
32+
33+
#### FLOAT16_HALF_LN2
34+
35+
One half times the [natural logarithm][@stdlib/math/base/special/ln] of `2` as a half-precision floating-point number.
36+
37+
```javascript
38+
var bool = ( FLOAT16_HALF_LN2 === 0.3466796875 );
39+
// returns true
40+
```
41+
42+
</section>
43+
44+
<!-- /.usage -->
45+
46+
<section class="examples">
47+
48+
## Examples
49+
50+
<!-- TODO: better example -->
51+
52+
<!-- eslint no-undef: "error" -->
53+
54+
```javascript
55+
var FLOAT16_HALF_LN2 = require( '@stdlib/constants/float16/half-ln-two' );
56+
57+
console.log( FLOAT16_HALF_LN2 );
58+
// => 0.3466796875
59+
```
60+
61+
</section>
62+
63+
<!-- /.examples -->
64+
65+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
66+
67+
<section class="related">
68+
69+
* * *
70+
71+
## See Also
72+
73+
- <span class="package-name">[`@stdlib/constants/float32/half-ln-two`][@stdlib/constants/float32/half-ln-two]</span><span class="delimiter">: </span><span class="description">one half times the natural logarithm of 2.</span>
74+
75+
</section>
76+
77+
<!-- /.related -->
78+
79+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
80+
81+
<section class="links">
82+
83+
[@stdlib/math/base/special/ln]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/ln
84+
85+
<!-- <related-links> -->
86+
87+
[@stdlib/constants/float32/half-ln-two]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float32/half-ln-two
88+
89+
<!-- </related-links> -->
90+
91+
</section>
92+
93+
<!-- /.links -->
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
{{alias}}
3+
One half times the natural logarithm of 2 as a half-precision
4+
floating-point number.
5+
6+
Examples
7+
--------
8+
> {{alias}}
9+
0.3466796875
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) 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+
* One half times the natural logarithm of 2 as a half-precision floating-point number.
23+
*
24+
* @example
25+
* var val = FLOAT16_HALF_LN2;
26+
* // returns 0.3466796875
27+
*/
28+
declare const FLOAT16_HALF_LN2: number;
29+
30+
31+
// EXPORTS //
32+
33+
export = FLOAT16_HALF_LN2;
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 FLOAT16_HALF_LN2 = 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+
FLOAT16_HALF_LN2; // $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 FLOAT16_HALF_LN2 = require( './../lib' );
22+
23+
console.log( FLOAT16_HALF_LN2 );
24+
// => 0.3466796875
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
* One half times the natural logarithm of 2 as a half-precision floating-point number.
23+
*
24+
* @module @stdlib/constants/float16/half-ln-two
25+
* @type {number}
26+
*
27+
* @example
28+
* var FLOAT16_HALF_LN2 = require( '@stdlib/constants/float16/half-ln-two' );
29+
* // returns 0.3466796875
30+
*/
31+
32+
// MAIN //
33+
34+
/**
35+
* One half times the natural logarithm of 2 as a half-precision floating-point number.
36+
*
37+
* ```tex
38+
* \frac{\ln 2}{2}
39+
* ```
40+
*
41+
* @constant
42+
* @type {number}
43+
* @default 0.3466796875
44+
*/
45+
var FLOAT16_HALF_LN2 = 0.3466796875; // 0x3EB17218
46+
47+
48+
// EXPORTS //
49+
50+
module.exports = FLOAT16_HALF_LN2;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "@stdlib/constants/float16/half-ln-two",
3+
"version": "0.0.0",
4+
"description": "One half times the natural logarithm of 2 as a half-precision floating-point number.",
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+
"ln",
58+
"ln2",
59+
"half",
60+
"natural",
61+
"logarithm",
62+
"log",
63+
"ieee754",
64+
"float",
65+
"flt",
66+
"precision",
67+
"floating-point",
68+
"float16"
69+
]
70+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 lnf = require( '@stdlib/math/base/special/lnf' );
25+
var absf = require( '@stdlib/math/base/special/absf' );
26+
var EPS = require( '@stdlib/constants/float16/eps' );
27+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float16' );
28+
var FLOAT16_HALF_LN2 = require( './../lib' );
29+
30+
31+
// TESTS //
32+
33+
tape( 'main export is a number', function test( t ) {
34+
t.ok( true, __filename );
35+
t.strictEqual( typeof FLOAT16_HALF_LN2, 'number', 'main export is a number' );
36+
t.end();
37+
});
38+
39+
tape( 'export is a half-precision floating-point number equal to `0.3466796875`', function test( t ) {
40+
t.strictEqual( FLOAT16_HALF_LN2, float64ToFloat32( 3.46573590279972654709e-01 ), 'returns expected value' );
41+
t.end();
42+
});
43+
44+
tape( 'export equals `0.5*lnf(2)`', function test( t ) {
45+
var delta;
46+
var tol;
47+
var v;
48+
49+
v = float64ToFloat32( 0.5 * lnf( 2.0 ) );
50+
delta = absf( float64ToFloat32( v - FLOAT16_HALF_LN2 ) );
51+
tol = EPS * FLOAT16_HALF_LN2;
52+
53+
t.ok( delta <= tol, 'equals 0.5*lnf(2) within tolerance '+tol );
54+
55+
t.end();
56+
});

0 commit comments

Comments
 (0)