Skip to content

Commit 924df55

Browse files
committed
feat: add lapack/base/dlapy2
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent d7ff4d9 commit 924df55

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
* LAPACK routine to calculate sqrt( x^2 + y^2 ) in a manner which doesn't cause unnecessary overflow.
23+
*
24+
* @module @stdlib/lapack/base/dlapy2
25+
*
26+
* @example
27+
* var dlapy2 = require( '@stdlib/lapack/base/dlapy2' );
28+
*
29+
* var out = dlapy2( 3.0, 4.0 );
30+
* // returns 5
31+
*/
32+
33+
// MODULES //
34+
35+
var main = require( './main.js' );
36+
37+
38+
// EXPORTS //
39+
40+
module.exports = main;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 abs = require( '@stdlib/math/base/special/abs' );
24+
var min = require( '@stdlib/math/base/special/min' );
25+
var max = require( '@stdlib/math/base/special/max' );
26+
var sqrt = require( '@stdlib/math/base/special/sqrt' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
29+
30+
// MAIN //
31+
32+
/**
33+
* Returns sqrt( x^2 + y^2 ) in a manner which doesn't cause unnecessary overflow.
34+
*
35+
* @private
36+
* @param {number} x - number of rows/columns of the elementary reflector `H`
37+
* @param {number} y - number of rows/columns of the elementary reflector `H`
38+
* @returns {integer} status code
39+
*
40+
* @example
41+
* var out = dlapy2( 3.0, 4.0, );
42+
* // returns 5
43+
*/
44+
function dlapy2( x, y ) {
45+
var xabs;
46+
var yabs;
47+
var w;
48+
var z;
49+
50+
xabs = abs( x );
51+
yabs = abs( y );
52+
53+
w = max( xabs, yabs );
54+
z = min( xabs, yabs );
55+
56+
if ( z === 0.0 ) {
57+
return w;
58+
}
59+
60+
return w * ( sqrt( 1.0 + pow( z / w, 2.0 ) ) );
61+
}
62+
63+
64+
// EXPORTS //
65+
66+
module.exports = dlapy2;

0 commit comments

Comments
 (0)