Skip to content
115 changes: 100 additions & 15 deletions lib/node_modules/@stdlib/math/base/special/minmax/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

# minmax

> Return the minimum and maximum values.
> Returns the minimum and maximum values.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> Returns the minimum and maximum values.
> Return the minimum and maximum values.

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

Expand Down Expand Up @@ -119,6 +119,105 @@ for ( i = 0; i < 100; i++ ) {

<!-- /.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
#include "stdlib/math/base/special/minmax.h"
```

#### stdlib_base_minmax( x, y, &min, &max )

Returns the minimum and maximum value.

```c
double min;
double max;
stdlib_base_minmax( 4.2, 3.14, &min, &max );

stdlib_base_minmax( 0.0, -0.0, &min, &max );
```

The function accepts the following arguments:

- **x**: `[in] double` input value.
- **y**: `[in] double` input value.
- **min**: `[out] double` destination for minimum value.
- **max**: `[out] double` destination for maximum value.

```c
void stdlib_base_minmax( const double x, const double y, double* min, double* max );
```

</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
#include "stdlib/math/base/special/minmax.h"
#include <stdlib.h>
#include <stdio.h>

int main( void ) {
double min;
double max;
double x;
double y;
int i;

for ( i = 0; i < 100; i++ ) {
x = ( ( (double)rand() / (double)RAND_MAX ) * 200.0 ) - 100.0;
y = ( ( (double)rand() / (double)RAND_MAX ) * 200.0 ) - 100.0;
stdlib_base_minmax( x, y, &min, &max );
printf( "x: %lf, y: %lf, minmax(x, y): [ %lf, %lf ]\n", x, y, min, max );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->



<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">
Expand All @@ -131,14 +230,6 @@ for ( i = 0; i < 100; i++ ) {

<section class="related">

* * *

## See Also

- <span class="package-name">[`@stdlib/math/base/special/max`][@stdlib/math/base/special/max]</span><span class="delimiter">: </span><span class="description">return the maximum value.</span>
- <span class="package-name">[`@stdlib/math/base/special/min`][@stdlib/math/base/special/min]</span><span class="delimiter">: </span><span class="description">return the minimum value.</span>
- <span class="package-name">[`@stdlib/math/base/special/minmaxabs`][@stdlib/math/base/special/minmaxabs]</span><span class="delimiter">: </span><span class="description">return the minimum and maximum absolute values.</span>

Comment on lines -134 to -141
Copy link
Member

Choose a reason for hiding this comment

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

@AbhijitRaut04 We should not remove these, as the JS implementation of this package already exists. "related" sections are kept empty only when a new package is added.

</section>

<!-- /.related -->
Expand All @@ -149,12 +240,6 @@ for ( i = 0; i < 100; i++ ) {

<!-- <related-links> -->

[@stdlib/math/base/special/max]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/max

[@stdlib/math/base/special/min]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/min

[@stdlib/math/base/special/minmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/minmaxabs

Comment on lines -152 to -157
Copy link
Member

Choose a reason for hiding this comment

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

Same comment here, we should keep these as well.

<!-- </related-links> -->

</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ bench( pkg, function benchmark( b ) {
var z;
var i;

x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;
z = minmax( x, y );
if ( z.length !== 2 ) {
b.fail( 'should have expected length' );
Expand All @@ -63,10 +64,11 @@ bench( pkg+':assign', function benchmark( b ) {

out = [ 0.0, 0.0 ];

x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;
z = minmax.assign( x, y, out, 1, 0 );
if ( z.length !== 2 ) {
b.fail( 'should have expected length' );
Expand All @@ -86,10 +88,11 @@ bench( pkg+'::min,max', function benchmark( b ) {
var z;
var i;

x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;
z = [ min( x, y ), max( x, y ) ];
if ( z.length !== 2 ) {
b.fail( 'should have expected length' );
Expand All @@ -111,10 +114,11 @@ bench( pkg+'::min,max,memory_reuse', function benchmark( b ) {

z = [ 0.0, 0.0 ];

x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = ( randu()*1000.0 ) - 500.0;
z[ 0 ] = min( x, y );
z[ 1 ] = max( x, y );
if ( z.length !== 2 ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/uniform' );
Copy link
Member

Choose a reason for hiding this comment

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

@AbhijitRaut04 We should use @stdlib/random/array/uniform here, and declare x and y below as arrays. Then, we can can initialize them with values using randu.

Copy link
Member

Choose a reason for hiding this comment

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

Same goes for benchmark.js as well.

var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var minmax = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( minmax instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var x;
var y;
var v;
var i;

x = ( randu() * 20.0 ) - 10.0;
y = ( randu() * 20.0 ) - 10.0;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = minmax( x, y );
if ( v.length !== 2 ) {
b.fail( 'should have expected length' );
}
}
b.toc();
if ( v.length !== 2 ) {
b.fail( 'should have expected length' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading
Loading