Skip to content

Commit 9482391

Browse files
committed
feat: add number/float64/base/add5
Ref: #2261 --- 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: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 9d447dc commit 9482391

File tree

26 files changed

+2205
-0
lines changed

26 files changed

+2205
-0
lines changed
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2023 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+
# add5
22+
23+
> Compute the sum of five double-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 add5 = require( '@stdlib/number/float64/base/add5' );
41+
```
42+
43+
#### add5( x, y, z, w, u )
44+
45+
Computes the sum of five double-precision floating-point numbers.
46+
47+
```javascript
48+
var v = add5( -1.0, 5.0, 2.0, -3.0, 4.0 );
49+
// returns 7.0
50+
51+
v = add5( 2.0, 5.0, 2.0, -3.0, 4.0 );
52+
// returns 10.0
53+
54+
v = add5( 0.0, 5.0, 2.0, -3.0, 4.0 );
55+
// returns 8.0
56+
57+
v = add5( -0.0, 0.0, -0.0, -0.0, -0.0 );
58+
// returns 0.0
59+
60+
v = add5( NaN, NaN, NaN, NaN, NaN );
61+
// returns NaN
62+
```
63+
64+
</section>
65+
66+
<!-- /.usage -->
67+
68+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
69+
70+
<section class="notes">
71+
72+
</section>
73+
74+
<!-- /.notes -->
75+
76+
<!-- Package usage examples. -->
77+
78+
<section class="examples">
79+
80+
## Examples
81+
82+
<!-- eslint no-undef: "error" -->
83+
84+
```javascript
85+
var rand = require( '@stdlib/random/base/discrete-uniform' ).factory;
86+
var filledBy = require( '@stdlib/array/base/filled-by' );
87+
var add5 = require( '@stdlib/number/float64/base/add5' );
88+
89+
var x = filledBy( 100, rand( -50, 50 ) );
90+
var y = filledBy( x.length, rand( -50, 50 ) );
91+
var z = filledBy( x.length, rand( -50, 50 ) );
92+
var w = filledBy( x.length, rand( -50, 50 ) );
93+
var u = filledBy( x.length, rand( -50, 50 ) );
94+
95+
var i;
96+
for ( i = 0; i < x.length; i++ ) {
97+
console.log( '%d + %d + %d + %d + %d = %d', x[i], y[i], z[i], w[i], u[i], add5( x[i], y[i], z[i], w[i], u[i] ) );
98+
}
99+
```
100+
101+
</section>
102+
103+
<!-- /.examples -->
104+
105+
<!-- C interface documentation. -->
106+
107+
* * *
108+
109+
<section class="c">
110+
111+
## C APIs
112+
113+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
114+
115+
<section class="intro">
116+
117+
</section>
118+
119+
<!-- /.intro -->
120+
121+
<!-- C usage documentation. -->
122+
123+
<section class="usage">
124+
125+
### Usage
126+
127+
```c
128+
#include "stdlib/number/float64/base/add5.h"
129+
```
130+
131+
#### stdlib_base_float64_add5( x, y, z, w, u )
132+
133+
Computes the sum of five double-precision floating-point numbers.
134+
135+
```c
136+
double out = stdlib_base_float64_add5( -5.0, 2.0, 4.0, 3.0, 1.0 );
137+
// returns 5.0
138+
```
139+
140+
The function accepts the following arguments:
141+
142+
- **x**: `[in] double` first input value.
143+
- **y**: `[in] double` second input value.
144+
- **z**: `[in] double` third input value.
145+
- **w**: `[in] double` fourth input value.
146+
- **u**: `[in] double` fifth input value.
147+
148+
```c
149+
double stdlib_base_float64_add5( const double x, const double y, const double z, const double w, const double u );
150+
```
151+
152+
</section>
153+
154+
<!-- /.usage -->
155+
156+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
157+
158+
<section class="notes">
159+
160+
</section>
161+
162+
<!-- /.notes -->
163+
164+
<!-- C API usage examples. -->
165+
166+
<section class="examples">
167+
168+
### Examples
169+
170+
```c
171+
#include "stdlib/number/float64/base/add5.h"
172+
#include <stdio.h>
173+
174+
int main( void ) {
175+
const double x[] = { 3.14, -3.14, 0.0, 0.0/0.0 };
176+
const double y[] = { 3.14, -3.14, -0.0, 0.0/0.0 };
177+
const double z[] = { 2.0, -3.0, -0.0, 0.0/0.0 };
178+
const double w[] = { 2.0, -3.0, -0.0, 0.0/0.0 };
179+
const double u[] = { -1.0, 4.0, 0.0, 0.0/0.0 };
180+
181+
double out;
182+
int i;
183+
for ( i = 0; i < 4; i++ ) {
184+
out = stdlib_base_float64_add5( x[ i ], y[ i ], z[ i ], w[ i ], u[ i ] );
185+
printf( "%lf + %lf + %lf + %lf + %lf = %lf\n", x[ i ], y[ i ], z[ i ], w[ i ], u[ i ], out );
186+
}
187+
}
188+
```
189+
190+
</section>
191+
192+
<!-- /.examples -->
193+
194+
</section>
195+
196+
<!-- /.c -->
197+
198+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
199+
200+
<section class="related">
201+
202+
* * *
203+
204+
## See Also
205+
206+
- <span class="package-name">[`@stdlib/number/float64/base/add`][@stdlib/number/float64/base/add]</span><span class="delimiter">: </span><span class="description">compute the sum of two double-precision floating-point numbers.</span>
207+
208+
</section>
209+
210+
<!-- /.related -->
211+
212+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
213+
214+
<section class="links">
215+
216+
<!-- <related-links> -->
217+
218+
[@stdlib/number/float64/base/add]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/number/float64/base/add
219+
220+
<!-- </related-links> -->
221+
222+
</section>
223+
224+
<!-- /.links -->
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 bench = require( '@stdlib/bench' );
24+
var randu = require( '@stdlib/random/base/randu' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pkg = require( './../package.json' ).name;
27+
var add5 = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var x;
34+
var y;
35+
var i;
36+
37+
b.tic();
38+
for ( i = 0; i < b.iterations; i++ ) {
39+
x = ( randu()*1000.0 ) - 500.0;
40+
y = add5( x, 5.0, i, x, x+1.0 );
41+
if ( isnan( y ) ) {
42+
b.fail( 'should not return NaN' );
43+
}
44+
}
45+
b.toc();
46+
if ( isnan( y ) ) {
47+
b.fail( 'should not return NaN' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});
52+
53+
bench( pkg+'::inline', function benchmark( b ) {
54+
var x;
55+
var y;
56+
var i;
57+
58+
b.tic();
59+
for ( i = 0; i < b.iterations; i++ ) {
60+
x = ( randu()*1000.0 ) - 500.0;
61+
y = x + 5.0 + i + x + (x+1.0);
62+
if ( isnan( y ) ) {
63+
b.fail( 'should not return NaN' );
64+
}
65+
}
66+
b.toc();
67+
if ( isnan( y ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
b.pass( 'benchmark finished' );
71+
b.end();
72+
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var randu = require( '@stdlib/random/base/randu' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var tryRequire = require( '@stdlib/utils/try-require' );
28+
var pkg = require( './../package.json' ).name;
29+
30+
31+
// VARIABLES //
32+
33+
var add5 = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var opts = {
35+
'skip': ( add5 instanceof Error )
36+
};
37+
38+
39+
// MAIN //
40+
41+
bench( pkg+'::native', opts, function benchmark( b ) {
42+
var x;
43+
var y;
44+
var i;
45+
46+
b.tic();
47+
for ( i = 0; i < b.iterations; i++ ) {
48+
x = ( randu()*1000.0 ) - 500.0;
49+
y = add5( x, 5.0, i, x, x+1.0 );
50+
if ( isnan( y ) ) {
51+
b.fail( 'should not return NaN' );
52+
}
53+
}
54+
b.toc();
55+
if ( isnan( y ) ) {
56+
b.fail( 'should not return NaN' );
57+
}
58+
b.pass( 'benchmark finished' );
59+
b.end();
60+
});

0 commit comments

Comments
 (0)