Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 216 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlabad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# dlabad

> Adjust the underflow and overflow thresholds if the exponent range is very large.

<section class="usage">

## Usage

```javascript
var dlabad = require( '@stdlib/lapack/base/dlabad' );
```

#### dlabad( SMALL, LARGE )

Adjusts the underflow and overflow thresholds if the exponent range is very large.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var SMALL = new Float64Array( [ 2.2250738585072014e-308 ] );
var LARGE = new Float64Array( [ 1.7976931348623157e+308 ] );

dlabad( SMALL, LARGE );
// SMALL => <Float64Array>[ 2.2250738585072014e-308 ]
// LARGE => <Float64Array>[ 1.7976931348623157e+308 ]
```

The function has the following parameters:

- **SMALL**: [`Float64Array`][mdn-float64array] containing a single element equal to the underflow threshold.
- **LARGE**: [`Float64Array`][mdn-float64array] containing a single element equal to the overflow threshold.

#### dlabad.ndarray( SMALL, offsetSMALL, LARGE, offsetLARGE )

Adjusts the underflow and overflow thresholds if the exponent range is very large using alternative indexing semantics.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var SMALL = new Float64Array( [ 2.2250738585072014e-308 ] );
var LARGE = new Float64Array( [ 1.7976931348623157e+308 ] );

dlabad.ndarray( SMALL, 0, LARGE, 0 );
// SMALL => <Float64Array>[ 2.2250738585072014e-308 ]
// LARGE => <Float64Array>[ 1.7976931348623157e+308 ]
```

The function has the following parameters:

- **SMALL**: [`Float64Array`][mdn-float64array] containing an element equal to the underflow threshold.
- **offsetSMALL**: index of the element in `SMALL`.
- **LARGE**: [`Float64Array`][mdn-float64array] containing an element equal to the overflow threshold.
- **offsetLARGE**: index of the element in `LARGE`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example,

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var SMALL = new Float64Array( [ 0.0, 2.2250738585072014e-308, 0.0 ] );
var LARGE = new Float64Array( [ 0.0, 0.0, 1.7976931348623157e+308 ] );

dlabad.ndarray( SMALL, 1, LARGE, 2 );
// SMALL => <Float64Array>[ 0.0, 2.2250738585072014e-308, 0.0 ]
// LARGE => <Float64Array>[ 0.0, 0.0, 1.7976931348623157e+308 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- `dlabad()` corresponds to the [LAPACK][LAPACK] function [`dlabad`][lapack-dlabad].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var dlabad = require( '@stdlib/lapack/base/dlabad' );

var SMALL = new Float64Array( [ 2.2250738585072014e-308 ] );
var LARGE = new Float64Array( [ 1.7976931348623157e+308 ] );

dlabad( SMALL, LARGE );
console.log( 'SMALL:', SMALL[ 0 ] );
console.log( 'LARGE:', LARGE[ 0 ] );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
TODO
```

#### TODO

TODO.

```c
TODO
```

TODO

```c
TODO
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
TODO
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

[lapack-dlabad]: https://www.netlib.org/lapack/explore-html/db/d91/group__labad_ga469557789831c29949bf455ca3b1dda5.html

[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array

[lapack]: https://www.netlib.org/lapack/explore-html/

</section>

<!-- /.links -->
46 changes: 46 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlabad/benchmark/benchmark.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Float64Array = require( '@stdlib/array/float64' );
var FLOAT64_MAX = require( '@stdlib/constants/float64/max' );
var FLOAT64_SMALLEST_NORMAL = require( '@stdlib/constants/float64/smallest-normal' );
var pkg = require( './../package.json' ).name;
var dlabad = require( './../lib' );


// VARIABLES //

var options = {
	'dtype': 'float64'
};


// MAIN //

bench( pkg, function benchmark( b ) {
	var LARGE;
	var SMALL;
	var large;
	var small;
	var N;
	var i;
	var j;
	var k;

	N = 100;
	small = uniform( N, FLOAT64_SMALLEST_NORMAL, 1.0e-200, options );
	large = uniform( N, 1.0e+200, FLOAT64_MAX, options );

	SMALL = new Float64Array( 1 );
	LARGE = new Float64Array( 1 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		j = i % N;
		k = ( i+1 ) % N;
		SMALL[ 0 ] = small[ j ];
		LARGE[ 0 ] = large[ k ];
		dlabad( SMALL, LARGE );
		if ( isnan( SMALL[ 0 ] ) || isnan( LARGE[ 0 ] ) ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( isnan( SMALL[ 0 ] ) || isnan( LARGE[ 0 ] ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

I think this approach seems more consistent. Reference: stdlib/lapack/base/dladiv

Copy link
Copy Markdown
Contributor

@anandkaranubc anandkaranubc May 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts, @iampratik13?

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var dlabad = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var SMALL;
var LARGE;
var i;

SMALL = new Float64Array( [ 2.2250738585072014e-308 ] );
LARGE = new Float64Array( [ 1.7976931348623157e+308 ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
dlabad( SMALL, LARGE );
}
b.toc();
b.pass( 'benchmark finished' );
b.end();
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var FLOAT64_MAX = require( '@stdlib/constants/float64/max' );
var FLOAT64_SMALLEST_NORMAL = require( '@stdlib/constants/float64/smallest-normal' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dlabad = require( './../lib/ndarray.js' );


// VARIABLES //

var options = {
	'dtype': 'float64'
};


// MAIN //

bench( format( '%s:ndarray', pkg ), function benchmark( b ) {
	var SMALL;
	var LARGE;
	var N;
	var i;
	var j;
	var k;

	N = 100;
	SMALL = uniform( N, FLOAT64_SMALLEST_NORMAL, 1.0e-200, options );
	LARGE = uniform( N, 1.0e+200, FLOAT64_MAX, options );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		j = i % N;
		k = ( i+1 ) % N;
		dlabad( SMALL, j, LARGE, k );
		if ( isnan( SMALL[ j ] ) || isnan( LARGE[ k ] ) ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( isnan( SMALL[ j ] ) || isnan( LARGE[ k ] ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

Similar version.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dlabad = require( './../lib' );


// MAIN //

bench( format( '%s:ndarray', pkg ), function benchmark( b ) {
var SMALL;
var LARGE;
var i;

SMALL = new Float64Array( [ 2.2250738585072014e-308 ] );
LARGE = new Float64Array( [ 1.7976931348623157e+308 ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
dlabad.ndarray( SMALL, 0, LARGE, 0 );
}
b.toc();
b.pass( 'benchmark finished' );
b.end();
});
61 changes: 61 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlabad/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

{{alias}}( SMALL, LARGE )
Adjust the underflow and overflow thresholds if the exponent range is
very large.

Indexing is relative to the first index. To introduce an offset, use typed
array views.

Parameters
----------
SMALL: Float64Array
Array containing a single element equal to the underflow threshold.

LARGE: Float64Array
Array containing a single element equal to the overflow threshold.

Examples
--------
> var SMALL = new {{alias:@stdlib/array/float64}}( [ 2.2250738585072014e-308 ] );
> var LARGE = new {{alias:@stdlib/array/float64}}( [ 1.7976931348623157e+308 ] );
> {{alias}}( SMALL, LARGE );
> SMALL
<Float64Array>[ 2.2250738585072014e-308 ]
> LARGE
<Float64Array>[ 1.7976931348623157e+308 ]


{{alias}}.ndarray( SMALL, offsetSMALL, LARGE, offsetLARGE )
Adjust the underflow and overflow thresholds if the exponent range is
very large using alternative indexing semantics.

While typed array views mandate a view offset based on the underlying
buffer, the offset parameters support indexing semantics based on starting
indices.

Parameters
----------
SMALL: Float64Array
Array containing an element equal to the underflow threshold.

offsetSMALL: integer
Index of the element in `SMALL`.

LARGE: Float64Array
Array containing an element equal to the overflow threshold.

offsetLARGE: integer
Index of the element in `LARGE`.

Examples
--------
> var SMALL = new {{alias:@stdlib/array/float64}}( [ 0.0, 2.2250738585072014e-308, 0.0 ] );
> var LARGE = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 1.7976931348623157e+308 ] );
> {{alias}}.ndarray( SMALL, 1, LARGE, 2 );
> SMALL
<Float64Array>[ 0.0, 2.2250738585072014e-308, 0.0 ]
> LARGE
<Float64Array>[ 0.0, 0.0, 1.7976931348623157e+308 ]

See Also
--------
Loading