Skip to content

Commit 8237449

Browse files
committed
feat: add number/float64/base/add3
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 8ad374c commit 8237449

File tree

26 files changed

+2155
-0
lines changed

26 files changed

+2155
-0
lines changed
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
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+
# add3
22+
23+
> Compute the sum of three 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 add3 = require( '@stdlib/number/float64/base/add3' );
41+
```
42+
43+
#### add3( x, y, z )
44+
45+
Computes the sum of three double-precision floating-point numbers.
46+
47+
```javascript
48+
var v = add3( -1.0, 5.0, 2.0 );
49+
// returns 6.0
50+
51+
v = add3( 2.0, 5.0, 2.0 );
52+
// returns 9.0
53+
54+
v = add3( 0.0, 5.0, 2.0 );
55+
// returns 7.0
56+
57+
v = add3( -0.0, 0.0, 0.0 );
58+
// returns 0.0
59+
60+
v = add3( 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 add3 = require( '@stdlib/number/float64/base/add3' );
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+
93+
var i;
94+
for ( i = 0; i < x.length; i++ ) {
95+
console.log( '%d + %d + %d = %d', x[i], y[i], z[i], add3( x[i], y[i], z[i] ) );
96+
}
97+
```
98+
99+
</section>
100+
101+
<!-- /.examples -->
102+
103+
<!-- C interface documentation. -->
104+
105+
* * *
106+
107+
<section class="c">
108+
109+
## C APIs
110+
111+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
112+
113+
<section class="intro">
114+
115+
</section>
116+
117+
<!-- /.intro -->
118+
119+
<!-- C usage documentation. -->
120+
121+
<section class="usage">
122+
123+
### Usage
124+
125+
```c
126+
#include "stdlib/number/float64/base/add3.h"
127+
```
128+
129+
#### stdlib_base_float64_add3( x, y, z )
130+
131+
Computes the sum of three double-precision floating-point numbers.
132+
133+
```c
134+
double out = stdlib_base_float64_add3( -5.0, 2.0, 4.0 );
135+
// returns 1.0
136+
```
137+
138+
The function accepts the following arguments:
139+
140+
- **x**: `[in] double` first input value.
141+
- **y**: `[in] double` second input value.
142+
- **z**: `[in] double` third input value.
143+
144+
```c
145+
double stdlib_base_float64_add3( const double x, const double y, const double z );
146+
```
147+
148+
</section>
149+
150+
<!-- /.usage -->
151+
152+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
153+
154+
<section class="notes">
155+
156+
</section>
157+
158+
<!-- /.notes -->
159+
160+
<!-- C API usage examples. -->
161+
162+
<section class="examples">
163+
164+
### Examples
165+
166+
```c
167+
#include "stdlib/number/float64/base/add3.h"
168+
#include <stdio.h>
169+
170+
int main( void ) {
171+
const double x[] = { 3.14, -3.14, 0.0, 0.0/0.0 };
172+
const double y[] = { 3.14, -3.14, -0.0, 0.0/0.0 };
173+
const double z[] = { 2.0, -3.0, -0.0, 0.0/0.0 };
174+
175+
double out;
176+
int i;
177+
for ( i = 0; i < 4; i++ ) {
178+
out = stdlib_base_float64_add3( x[ i ], y[ i ], z[ i ] );
179+
printf( "%lf + %lf + %lf = %lf\n", x[ i ], y[ i ], z[ i ], out );
180+
}
181+
}
182+
```
183+
184+
</section>
185+
186+
<!-- /.examples -->
187+
188+
</section>
189+
190+
<!-- /.c -->
191+
192+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
193+
194+
<section class="related">
195+
196+
* * *
197+
198+
## See Also
199+
200+
- <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>
201+
202+
</section>
203+
204+
<!-- /.related -->
205+
206+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
207+
208+
<section class="links">
209+
210+
<!-- <related-links> -->
211+
212+
[@stdlib/number/float64/base/add]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/number/float64/base/add
213+
214+
<!-- </related-links> -->
215+
216+
</section>
217+
218+
<!-- /.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 add3 = 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 = add3( x, 5.0, i );
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;
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 add3 = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var opts = {
35+
'skip': ( add3 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 = add3( x, 5.0, i );
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)