Skip to content

Commit 8dc9043

Browse files
committed
feat!: add implementation of stdlib/math/base/special/minmaxabsf
This commit adds the implementation of stdlib/math/base/special/minmaxabsf function. It includes a README.md file, benchmarks, tests, examples. The minmaxabsf function returns the minimum and maximum single-precision floating-point values for any two numbers. Closes: #6163
1 parent 8a07256 commit 8dc9043

File tree

28 files changed

+655
-0
lines changed

28 files changed

+655
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 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+
# minmaxabsf
22+
23+
> Return the minimum and maximum absolute single-precision floating-point numbers.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var minmaxabsf = require( '@stdlib/math/base/special/minmaxabsf' );
41+
```
42+
43+
#### minmaxabsf( x,y )
44+
45+
Returns the minimum and maximum absolute single-precision floating-point values in a single pass.
46+
47+
```javascript
48+
var v = minmaxabsf( 4.2, 3.14 );
49+
// returns [ 3.14, 4.2 ]
50+
51+
v = minmaxabsf( +0.0, -0.0 );
52+
// returns [ 0.0, 0.0 ]
53+
```
54+
55+
If any argument is `NaN`, the function returns `Nan` for both the minimum value and the maximum value.
56+
57+
```javascript
58+
var v = minmaxabs( 4.2, NaN );
59+
// returns [ NaN, NaN ]
60+
61+
v = minmaxabs( NaN, 3.14 );
62+
// returns [ NaN, NaN ]
63+
```
64+
65+
#### minmaxabsf.assign( x, y, out, stride, offset )
66+
67+
Returns the minimum and maximum absolute single-precision values in a single pass and assigns the results to a provided output array.
68+
69+
```javascript
70+
var Float64Array = require( '@stdlib/array/float32' );
71+
72+
var out = new Float32Array( 2 );
73+
74+
var v = minmaxabsf.assign( 5.0, -1.0, out, 1, 0 );
75+
// returns <Float32Array>[ 1.0, 5.0 ]
76+
77+
var bool = ( v === out );
78+
// returns true
79+
```
80+
81+
</section>
82+
83+
<!-- /.usage -->
84+
85+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
86+
87+
<section class="notes">
88+
89+
</section>
90+
91+
<!-- /.notes -->
92+
93+
<!-- Package usage examples. -->
94+
95+
<section class="examples">
96+
97+
## Examples
98+
99+
<!-- eslint no-undef: "error" -->
100+
101+
```javascript
102+
var randu = require( '@stdlib/random/base/randu' );
103+
var minmaxabs = require( '@stdlib/math/base/special/minmaxabsf' );
104+
105+
var x;
106+
var y;
107+
var v;
108+
var i;
109+
110+
for ( i = 0; i < 100; i++ ) {
111+
x = ( randu()*100.0 ) - 50.0;
112+
y = ( randu()*100.0 ) - 50.0;
113+
v = minmaxabsf( x, y );
114+
console.log( 'minmaxabsf(%d,%d) = [%d, %d]', x, y, v[0], v[1] );
115+
}
116+
```
117+
118+
</section>
119+
120+
<!-- /.examples -->
121+
122+
<!-- C interface documentation. -->
123+
124+
* * *
125+
126+
<section class="c">
127+
128+
## C APIs
129+
130+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
131+
132+
<section class="intro">
133+
134+
</section>
135+
136+
<!-- /.intro -->
137+
138+
<!-- C usage documentation. -->
139+
140+
<section class="usage">
141+
142+
### Usage
143+
144+
```c
145+
#include "stdlib/math/base/special/minmaxabsf.h"
146+
```
147+
148+
#### stdlib_base_minmaxabsf( x, y, min, max )
149+
150+
Returns the minimum and maximum absolute single-precision floating-point values in a single pass.
151+
152+
```c
153+
float min;
154+
float max;
155+
float out = stdlib_base_minmaxabsf( -4.2f, 3.14f, &min, &max );
156+
// returns [ 3.14, 4.2 ]
157+
158+
out = stdlib_base_minmaxabsf( 0.0f, -0.0f, &min, &max );
159+
// returns [ 0.0, 0.0 ]
160+
```
161+
162+
The function accepts the following arguments:
163+
- **x**: `[in] float` input value.
164+
- **y**: `[in] float` input value.
165+
- **min**: `[in] *float` output min.
166+
- **max**: `[in] *float` output max.
167+
168+
```c
169+
void stdlib_base_minmaxabsf( const float x, const float y, float* min, float* max );
170+
```
171+
172+
</section>
173+
174+
<!-- /.usage -->
175+
176+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
177+
178+
<section class="notes">
179+
180+
</section>
181+
182+
<!-- /.notes -->
183+
184+
<!-- C API usage examples. -->
185+
186+
<section class="examples">
187+
188+
### Examples
189+
190+
```c
191+
#include "stdlib/math/base/special/minmaxabsf.h"
192+
#include <stdlib.h>
193+
#include <stdio.h>
194+
195+
int main(void) {
196+
srand(time(NULL)); // Seed random number generator
197+
198+
float x1[10], x2[10];
199+
float min, max;
200+
int i;
201+
202+
// Generate random floating-point values between -1.0 and 1.0
203+
for (i = 0; i < 10; i++) {
204+
x1[i] = ((float)rand() / RAND_MAX) * 2.0f - 1.0f; // Random float in [-1,1]
205+
x2[i] = ((float)rand() / RAND_MAX) * 2.0f - 1.0f; // Random float in [-1,1]
206+
207+
// Introduce NaN values randomly
208+
if (rand() % 10 == 0) x1[i] = NAN;
209+
if (rand() % 10 == 0) x2[i] = NAN;
210+
}
211+
212+
// Compute min and max values
213+
for (i = 0; i < 10; i++) {
214+
stdlib_base_minmaxf(x1[i], x2[i], &min, &max);
215+
printf("x1[%d]: %f, x2[%d]: %f, minmaxf(x1[%d], x2[%d]): (%f, %f)\n",
216+
i, x1[i], i, x2[i], i, i, min, max);
217+
}
218+
219+
return 0;
220+
}
221+
```
222+
223+
</section>
224+
225+
<!-- /.examples -->
226+
227+
</section>
228+
229+
<!-- /.c -->
230+
231+
<!-- 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. -->
232+
233+
<section class="references">
234+
235+
</section>
236+
237+
<!-- /.references -->
238+
239+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
240+
241+
<section class="related">
242+
243+
* * *
244+
245+
## See Also
246+
247+
- <span class="package-name">[`@stdlib/math/base/special/maxabsf`][@stdlib/math/base/special/maxabsf]</span><span class="delimiter">: </span><span class="description">return the maximum absolute single-precision floating-point number.</span>
248+
- <span class="package-name">[`@stdlib/math/base/special/minabsf`][@stdlib/math/base/special/minabsf]</span><span class="delimiter">: </span><span class="description">return the minimum absolute single-precision floating-point number.</span>
249+
- <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>
250+
251+
</section>
252+
253+
<!-- /.related -->
254+
255+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
256+
257+
<section class="links">
258+
259+
<!-- <related-links> -->
260+
261+
[@stdlib/math/base/special/maxabsf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/maxabsf
262+
263+
[@stdlib/math/base/special/minabsf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/minabsf
264+
265+
[@stdlib/math/base/special/minmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/minmaxabs
266+
267+
<!-- </related-links> -->
268+
269+
</section>
270+
271+
<!-- /.links -->

lib/node_modules/@stdlib/math/base/special/minmaxabsf/benchmark/benchmark.js

Whitespace-only changes.

lib/node_modules/@stdlib/math/base/special/minmaxabsf/benchmark/c/native/Makefile

Whitespace-only changes.

lib/node_modules/@stdlib/math/base/special/minmaxabsf/benchmark/c/native/benchmark.c

Whitespace-only changes.

lib/node_modules/@stdlib/math/base/special/minmaxabsf/benchmark/julia/REQUIRE

Whitespace-only changes.

lib/node_modules/@stdlib/math/base/special/minmaxabsf/benchmark/julia/benchmark.jl

Whitespace-only changes.

0 commit comments

Comments
 (0)