Skip to content

Commit e511134

Browse files
Aadish JainAadish Jain
authored andcommitted
feat(special-wrapf): adding readme
1 parent 17eec08 commit e511134

File tree

1 file changed

+255
-0
lines changed
  • lib/node_modules/@stdlib/math/base/special/wrapf

1 file changed

+255
-0
lines changed
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2022 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+
# wrapf
22+
23+
> Wrap a value on the half-open interval `[min,max)`.
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 wrapf = require( '@stdlib/math/base/special/wrapf' );
41+
```
42+
43+
#### wrapf( v, min, max )
44+
45+
Wraps a value on the half-open interval `[min,max)`.
46+
47+
```javascript
48+
var v = wrapf( 3.14, 0.0, 5.0 );
49+
// returns ~3.14
50+
51+
v = wrapf( -3.14, 0.0, 5.0 );
52+
// returns ~1.86
53+
54+
v = wrapf( 10.0, 0.0, 5.0 );
55+
// returns 0.0
56+
57+
v = wrapf( -0.0, 0.0, 5.0 );
58+
// returns 0.0
59+
60+
v = wrapf( 0.0, -3.14, -0.0 );
61+
// returns ~-3.14
62+
```
63+
64+
If provided `NaN` for any argument, the function returns `NaN`.
65+
66+
```javascript
67+
var v = wrapf( NaN, 0.0, 5.0 );
68+
// returns NaN
69+
70+
v = wrapf( 0.0, NaN, 5.0 );
71+
// returns NaN
72+
73+
v = wrapf( 3.14, 0.0, NaN );
74+
// returns NaN
75+
```
76+
77+
If provided `min == max`, the function returns `NaN`.
78+
79+
```javascript
80+
var v = wrapf( 3.14, 3.0, 3.0 );
81+
// returns NaN
82+
```
83+
84+
</section>
85+
86+
<!-- /.usage -->
87+
88+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
89+
90+
<section class="notes">
91+
92+
## Notes
93+
94+
- The function does **not** distinguish between positive and negative zero. Where appropriate, the function returns positive zero.
95+
96+
</section>
97+
98+
<!-- /.notes -->
99+
100+
<!-- Package usage examples. -->
101+
102+
<section class="examples">
103+
104+
## Examples
105+
106+
<!-- eslint no-undef: "error" -->
107+
108+
```javascript
109+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
110+
var wrapf = require( '@stdlib/math/base/special/wrapf' );
111+
112+
var min;
113+
var max;
114+
var v;
115+
var i;
116+
117+
for ( i = 0; i < 100; i++ ) {
118+
min = discreteUniform( 0.0, 10.0 );
119+
max = discreteUniform( 5.0, 15.0 );
120+
v = discreteUniform( -20.0, 20.0 );
121+
console.log( 'wrapf(%d,%d,%d) => %d', v, min, max, wrapf( v, min, max ) );
122+
}
123+
```
124+
125+
</section>
126+
127+
<!-- /.examples -->
128+
129+
<!-- C interface documentation. -->
130+
131+
* * *
132+
133+
<section class="c">
134+
135+
## C APIs
136+
137+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
138+
139+
<section class="intro">
140+
141+
</section>
142+
143+
<!-- /.intro -->
144+
145+
<!-- C usage documentation. -->
146+
147+
<section class="usage">
148+
149+
### Usage
150+
151+
```c
152+
#include "stdlib/math/base/special/wrapf.h"
153+
```
154+
155+
#### stdlib_base_wrapf( v, min, max )
156+
157+
Wraps a value on the half-open interval `[min,max)`.
158+
159+
```c
160+
float v = stdlib_base_wrapf( 3.14, 0.0, 5.0 );
161+
// returns ~3.14
162+
163+
v = stdlib_base_wrapf( -3.14, 0.0, 5.0 );
164+
// returns ~1.86
165+
```
166+
167+
The function accepts the following arguments:
168+
169+
- **v**: `[in] float` input value to wrap.
170+
- **min**: `[in] float` minimum value.
171+
- **max**: `[in] float` maximum value.
172+
173+
```c
174+
float stdlib_base_wrapf( const float v, const float min, const float max )
175+
```
176+
177+
</section>
178+
179+
<!-- /.usage -->
180+
181+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
182+
183+
<section class="notes">
184+
185+
</section>
186+
187+
<!-- /.notes -->
188+
189+
<!-- C API usage examples. -->
190+
191+
<section class="examples">
192+
193+
### Examples
194+
195+
```c
196+
#include "stdlib/math/base/special/wrapf.h"
197+
#include <stdio.h>
198+
199+
int main( void ) {
200+
const float min[] = { 0.0, 0.0, 0.0, 0.0, -3.14 };
201+
const float max[] = { 5.0, 5.0, 5.0, 5.0, -0.0 };
202+
const float v[] = { 3.14, -3.14, 10.0, -0.0, 0.0 };
203+
204+
float out;
205+
int i;
206+
for ( i = 0; i < 5; i++ ) {
207+
out = stdlib_base_wrap( v[i], min[i], max[i] );
208+
printf( "wrap(%f,%f,%f) => %f\n", v[i], min[i], max[i], out );
209+
}
210+
}
211+
```
212+
213+
</section>
214+
215+
<!-- /.examples -->
216+
217+
</section>
218+
219+
<!-- /.c -->
220+
221+
<!-- 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. -->
222+
223+
<section class="references">
224+
225+
</section>
226+
227+
<!-- /.references -->
228+
229+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
230+
231+
<section class="related">
232+
233+
* * *
234+
235+
## See Also
236+
237+
- <span class="package-name">[`@stdlib/math/base/special/clamp`][@stdlib/math/base/special/clamp]</span><span class="delimiter">: </span><span class="description">restrict a double-precision floating-point number to a specified range.</span>
238+
239+
</section>
240+
241+
<!-- /.related -->
242+
243+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
244+
245+
<section class="links">
246+
247+
<!-- <related-links> -->
248+
249+
[@stdlib/math/base/special/clamp]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/clamp
250+
251+
<!-- </related-links> -->
252+
253+
</section>
254+
255+
<!-- /.links -->

0 commit comments

Comments
 (0)