Skip to content

Commit 536f5db

Browse files
Pranavchikukgryte
andauthored
feat: add lapack/base/dlamch
PR-URL: #2568 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Signed-off-by: Pranav Goswami <goswami.4@iitj.ac.in>
1 parent b877636 commit 536f5db

File tree

10 files changed

+805
-0
lines changed

10 files changed

+805
-0
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
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+
# dlamch
22+
23+
> Determine double-precision floating-point machine parameters.
24+
25+
<section class = "usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var dlamch = require( '@stdlib/lapack/base/dlamch' );
31+
```
32+
33+
#### dlamch( cmach )
34+
35+
Determines double-precision floating-point machine parameters.
36+
37+
```javascript
38+
var out = dlamch( 'E' );
39+
// returns 1.1102230246251565e-16
40+
```
41+
42+
The function has the following parameters:
43+
44+
- **cmach**: specifies the value to be returned. The following characters are supported:
45+
46+
- `'E'`/`'e'`: (eps) relative machine precision.
47+
- `'S'`/`'s'`: (sfmin) safe minimum such that `1/sfmin` does not overflow.
48+
- `'B'`/`'b'`: (base) base of the machine (also known as the floating-point radix).
49+
- `'P'`/`'p'`: (prec) `eps*base`.
50+
- `'N'`/`'n'`: (t) number of (base) digits in the mantissa.
51+
- `'R'`/`'r'`: (rnd) `1.0` when rounding occurs in addition and `0.0` otherwise.
52+
- `'M'`/`'m'`: (emin) minimum exponent before (gradual) underflow.
53+
- `'U'`/`'u'`: (rmin) underflow threshold.
54+
- `'L'`/`'l'`: (emax) largest exponent before overflow.
55+
- `'O'`/`'o'`: (rmax) overflow threshold.
56+
57+
</section>
58+
59+
<!-- /.usage -->
60+
61+
<section class="notes">
62+
63+
## Notes
64+
65+
- `dlamch()` corresponds to the [LAPACK][lapack] function [`dlamch`][lapack-dlamch].
66+
67+
</section>
68+
69+
<!-- /.notes -->
70+
71+
<section class="examples">
72+
73+
## Examples
74+
75+
<!-- eslint no-undef: "error" -->
76+
77+
```javascript
78+
var dlamch = require( '@stdlib/lapack/base/dlamch' );
79+
80+
var out = dlamch( 'E' );
81+
console.log( 'Precision: %d', out );
82+
83+
out = dlamch( 'S' );
84+
console.log( 'Safe minimum: %d', out );
85+
86+
out = dlamch( 'B' );
87+
console.log( 'Base: %d', out );
88+
89+
out = dlamch( 'P' );
90+
console.log( 'Precision*base: %d', out );
91+
92+
out = dlamch( 'N' );
93+
console.log( 'Number of digits in mantissa: %d', out );
94+
95+
out = dlamch( 'R' );
96+
console.log( 'Rounding: %d', out );
97+
98+
out = dlamch( 'M' );
99+
console.log( 'Minimum exponent before underflow: %d', out );
100+
101+
out = dlamch( 'U' );
102+
console.log( 'Underflow threshold: %d', out );
103+
104+
out = dlamch( 'L' );
105+
console.log( 'Maximum exponent before overflow: %d', out );
106+
107+
out = dlamch( 'O' );
108+
console.log( 'Overflow threshold: %d', out );
109+
```
110+
111+
</section>
112+
113+
<!-- /.examples -->
114+
115+
<!-- C interface documentation. -->
116+
117+
* * *
118+
119+
<section class="c">
120+
121+
## C APIs
122+
123+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
124+
125+
<section class="intro">
126+
127+
</section>
128+
129+
<!-- /.intro -->
130+
131+
<!-- C usage documentation. -->
132+
133+
<section class="usage">
134+
135+
### Usage
136+
137+
```c
138+
TODO
139+
```
140+
141+
#### TODO
142+
143+
TODO.
144+
145+
```c
146+
TODO
147+
```
148+
149+
TODO
150+
151+
```c
152+
TODO
153+
```
154+
155+
</section>
156+
157+
<!-- /.usage -->
158+
159+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
160+
161+
<section class="notes">
162+
163+
</section>
164+
165+
<!-- /.notes -->
166+
167+
<!-- C API usage examples. -->
168+
169+
<section class="examples">
170+
171+
### Examples
172+
173+
```c
174+
TODO
175+
```
176+
177+
</section>
178+
179+
<!-- /.examples -->
180+
181+
</section>
182+
183+
<!-- /.c -->
184+
185+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
186+
187+
<section class="related">
188+
189+
</section>
190+
191+
<!-- /.related -->
192+
193+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
194+
195+
<section class="links">
196+
197+
[lapack]: https://www.netlib.org/lapack/explore-html/
198+
199+
[lapack-dlamch]: https://www.netlib.org/lapack/explore-html/d4/d86/group__lamch_gaeab255e77cbd3b0f31aea74ed0ce099e.html#gaeab255e77cbd3b0f31aea74ed0ce099e
200+
201+
</section>
202+
203+
<!-- /.links -->
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pkg = require( './../package.json' ).name;
25+
var dlamch = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg, function benchmark( b ) {
31+
var values;
32+
var out;
33+
var i;
34+
35+
values = [
36+
'E',
37+
'S',
38+
'B',
39+
'P',
40+
'N',
41+
'R',
42+
'M',
43+
'U',
44+
'L',
45+
'O',
46+
'e',
47+
's',
48+
'b',
49+
'p',
50+
'n',
51+
'r',
52+
'm',
53+
'u',
54+
'l',
55+
'o'
56+
];
57+
58+
b.tic();
59+
for ( i = 0; i < b.iterations; i++ ) {
60+
out = dlamch( values[ i%values.length ] );
61+
if ( typeof out !== 'number' ) {
62+
b.fail( 'should return a number' );
63+
}
64+
}
65+
b.toc();
66+
if ( typeof out !== 'number' ) {
67+
b.fail( 'should return a number' );
68+
}
69+
b.pass( 'benchmark finished' );
70+
b.end();
71+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
{{alias}}( cmach )
3+
Determines double-precision floating-point machine parameters.
4+
5+
The `cmach` parameter is a string which specifies the double-precision
6+
machine parameter to be returned. The function recognizes the following
7+
characters:
8+
9+
- 'E'/'e': (eps) relative machine precision.
10+
- 'S'/'s': (sfmin) safe minimum such that `1/sfmin` does not overflow.
11+
- 'B'/'b': (base) base of the machine (also known as the radix).
12+
- 'P'/'p': (prec) `eps*base`.
13+
- 'N'/'n': (t) number of (base) digits in the mantissa.
14+
- 'R'/'r': (rnd) `1.0` when rounding occurs in addition and `0.0` otherwise.
15+
- 'M'/'m': (emin) minimum exponent before (gradual) underflow.
16+
- 'U'/'u': (rmin) underflow threshold.
17+
- 'L'/'l': (emax) largest exponent before overflow.
18+
- 'O'/'o': (rmax) overflow threshold.
19+
20+
Parameters
21+
----------
22+
cmach: string
23+
Specifies the value to be returned.
24+
25+
Returns
26+
-------
27+
out: number
28+
Machine parameter.
29+
30+
Examples
31+
--------
32+
> var y = {{alias}}( 'E' )
33+
1.1102230246251565e-16
34+
> y = {{alias}}( 'S' )
35+
2.2250738585072014e-308
36+
> y = {{alias}}( 'B' )
37+
2.0
38+
> y = {{alias}}( 'P' )
39+
2.2204460492503131e-16
40+
41+
See Also
42+
--------
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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+
* Parameter type.
23+
*/
24+
type CMACH = 'E' | 'e' | 'S' | 's' | 'B' | 'b' | 'P' | 'p' | 'N' | 'n' | 'R' | 'r' | 'M' | 'm' | 'U' | 'u' | 'L' | 'l' | 'O' | 'o';
25+
26+
/**
27+
* Determines double-precision floating-point machine parameters.
28+
*
29+
* ## Notes
30+
*
31+
* - The `cmach` parameter is a string which specifies the double-precision machine parameter to be returned. The function recognizes the following characters:
32+
*
33+
* - `'E'`/`'e'`: (eps) relative machine precision.
34+
* - `'S'`/`'s'`: (sfmin) safe minimum such that `1/sfmin` does not overflow.
35+
* - `'B'`/`'b'`: (base) base of the machine (also known as the floating-point radix).
36+
* - `'P'`/`'p'`: (prec) `eps*base`.
37+
* - `'N'`/`'n'`: (t) number of (base) digits in the mantissa.
38+
* - `'R'`/`'r'`: (rnd) `1.0` when rounding occurs in addition and `0.0` otherwise.
39+
* - `'M'`/`'m'`: (emin) minimum exponent before (gradual) underflow.
40+
* - `'U'`/`'u'`: (rmin) underflow threshold.
41+
* - `'L'`/`'l'`: (emax) largest exponent before overflow.
42+
* - `'O'`/`'o'`: (rmax) overflow threshold.
43+
*
44+
* @param cmach - specifies the value to be returned
45+
* @returns machine parameter
46+
*
47+
* @example
48+
* var out = dlamch( 'E' );
49+
* // returns ~1.1102230246251565E-016
50+
*
51+
* out = dlamch( 'S' );
52+
* // returns ~2.2250738585072014E-308
53+
*
54+
* out = dlamch( 'B' );
55+
* // returns 2.0
56+
*/
57+
declare function dlamch( x: CMACH | string ): number;
58+
59+
60+
// EXPORTS //
61+
62+
export = dlamch;

0 commit comments

Comments
 (0)