Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
<!--

@license Apache-2.0

Copyright (c) 2026 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.

-->

# Float32Results

> Create a NaN-aware summation single-precision floating-point results object.

<!-- 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 -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var Float32Results = require( '@stdlib/blas/ext/base/nannsum/results/float32' );
```

#### Float32Results( \[arg\[, byteOffset\[, byteLength]]] )

Returns a NaN-aware summation single-precision floating-point results object.

```javascript
var results = new Float32Results();
// returns {...}
```

The function supports the following parameters:

- **arg**: an [`ArrayBuffer`][@stdlib/array/buffer] or a data object (_optional_).
- **byteOffset**: byte offset (_optional_).
- **byteLength**: maximum byte length (_optional_).

A data object argument is an object having one or more of the following properties:

- **sum**: sum of non-NaN elements.
- **count**: number of non-NaN elements.

#### Float32Results.prototype.sum

Sum of non-NaN elements.

```javascript
var results = new Float32Results();
// returns {...}

// ...

var v = results.sum;
// returns <number>
```

#### Float32Results.prototype.count

Number of non-NaN elements.

```javascript
var results = new Float32Results();
// returns {...}

// ...

var v = results.count;
// returns <bigint>
```

#### Float32Results.prototype.toString( \[options] )

Serializes a results object to a formatted string.

```javascript
var results = new Float32Results();
// returns {...}

// ...

var v = results.toString();
// returns <string>
```

The method supports the following options:

- **digits**: number of digits to display after decimal points. Default: `4`.

Example output:

```text

NaN-aware summation

sum: 11.7586
count: 5

```

#### Float32Results.prototype.toJSON()

Serializes a results object as a JSON object.

```javascript
var results = new Float32Results();
// returns {...}

// ...

var v = results.toJSON();
// returns {...}
```

`JSON.stringify()` implicitly calls this method when stringifying a results instance.

#### Float32Results.prototype.toDataView()

Returns a [`DataView`][@stdlib/array/dataview] of a results object.

```javascript
var results = new Float32Results();
// returns {...}

// ...

var v = results.toDataView();
// returns <DataView>
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- A results object is a [`struct`][@stdlib/dstructs/struct] providing a fixed-width composite data structure for storing NaN-aware summation results and providing an ABI-stable data layout for JavaScript-C interoperation.

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var BigInt = require( '@stdlib/bigint/ctor' );
var f32 = require( '@stdlib/number/float64/base/to-float32' );
var Results = require( '@stdlib/blas/ext/base/nannsum/results/float32' );

var results = new Results({
'sum': f32( 11.7586 ),
'count': BigInt( 5 )
});

var str = results.toString();
console.log( str );
```

</section>

<!-- /.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/blas/ext/base/nannsum/results/float32.h"
```

#### stdlib_blas_ext_base_nannsum_float32_results

Structure for storing NaN-aware summation results.

<!-- run-disable -->

```c
#include <stdint.h>

struct stdlib_blas_ext_base_nannsum_float32_results {
// Sum of non-NaN elements:
float sum;

// Number of non-NaN elements:
int64_t count;
};
```

</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">

</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">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/dstructs/struct]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/dstructs/struct

[@stdlib/array/dataview]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/dataview

[@stdlib/array/buffer]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/buffer

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 bench = require( '@stdlib/bench' );
var isObject = require( '@stdlib/assert/is-object' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Float32Results = require( './../lib' );


// MAIN //

bench( format( '%s::constructor,new', pkg ), function benchmark( b ) {
var v;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = new Float32Results();
if ( typeof v !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isObject( v ) ) {
b.fail( 'should return an object' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::constructor,no_new', pkg ), function benchmark( b ) {
var results;
var v;
var i;

results = Float32Results;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = results();
if ( typeof v !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isObject( v ) ) {
b.fail( 'should return an object' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

{{alias}}( [arg[, byteOffset[, byteLength]]] )
Returns a NaN-aware summation single-precision floating-point results
object.

Parameters
----------
arg: Object|ArrayBuffer (optional)
ArrayBuffer or data object.

byteOffset: integer (optional)
Byte offset.

byteLength: integer (optional)
Maximum byte length.

Returns
-------
out: Object
Results object.

Examples
--------
> var r = new {{alias}}();
> r.toString()
<string>

See Also
--------

Loading
Loading