Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b60cbf1
feat: add \math/base/special/truncbf\
Amansingh0807 Dec 9, 2025
796dbd9
refactor: use powf and truncf for float32 operations in truncbf
Amansingh0807 Dec 9, 2025
8df7b42
fix: add dependencies to truncbf package.json
Amansingh0807 Dec 9, 2025
7fc7b09
feat: add comprehensive scaffold metadata to truncbf package.json
Amansingh0807 Dec 9, 2025
25364ab
fix: resolve all CI errors in truncbf
Amansingh0807 Dec 9, 2025
e76960e
fix: update binding.gyp, include.gypi, and manifest.json to use libra…
Amansingh0807 Dec 9, 2025
cee4280
fix: resolve all lint errors - remove trailing whitespace, fix doctes…
Amansingh0807 Dec 9, 2025
f0b6c67
fix: remove trailing whitespace from src/main.c and fix integer examp…
Amansingh0807 Dec 9, 2025
c6ca8b2
fix: restore correct includes in main.c - use pow/trunc instead of po…
Amansingh0807 Dec 9, 2025
784039b
fix: restore correct includes in main.c - use pow/trunc instead of po…
Amansingh0807 Dec 9, 2025
d7c8e6f
fix: restore correct includes in main.c - use pow/trunc instead of po…
Amansingh0807 Dec 9, 2025
fc6dae7
fix: restore correct includes in main.c - use pow/trunc instead of po…
Amansingh0807 Dec 9, 2025
5365aa1
fix: restore correct includes in main.c - use pow/trunc instead of po…
Amansingh0807 Dec 9, 2025
1cfe041
fix: restore correct includes in main.c - use pow/trunc instead of po…
Amansingh0807 Dec 9, 2025
8dba89f
fix: restore correct includes in main.c - use pow/trunc instead of po…
Amansingh0807 Dec 9, 2025
59e7e26
fix: restore correct includes in main.c - use pow/trunc instead of po…
Amansingh0807 Dec 9, 2025
e2aa63d
fix: add missing devDependencies and sort alphabetically
Amansingh0807 Dec 9, 2025
978ee5c
fix: add missing devDependencies and sort alphabetically
Amansingh0807 Dec 9, 2025
eca9d52
fix: add missing devDependencies and sort alphabetically
Amansingh0807 Dec 9, 2025
43ac720
fix: add missing devDependencies and sort alphabetically
Amansingh0807 Dec 9, 2025
69211a8
fix: add proper indentation to license headers
Amansingh0807 Dec 9, 2025
10dcf99
fix: add proper indentation to license headers
Amansingh0807 Dec 9, 2025
290359c
fix: use stdlib trunc in benchmark, single-precision functions in mai…
Amansingh0807 Dec 9, 2025
049e558
fix: use stdlib trunc in benchmark, single-precision functions in mai…
Amansingh0807 Dec 9, 2025
fac1b21
fix: add fii_f NAPI dependency to manifest.json
Amansingh0807 Dec 9, 2025
f09deb1
fix: add fii_f NAPI dependency to manifest.json
Amansingh0807 Dec 9, 2025
b196c75
fix: add fii_f NAPI dependency to manifest.json
Amansingh0807 Dec 9, 2025
0dbff21
fix: add fii_f NAPI dependency to manifest.json
Amansingh0807 Dec 9, 2025
0872aba
fix: add fii_f NAPI dependency to manifest.json
Amansingh0807 Dec 9, 2025
8935b9e
fix: add fii_f NAPI dependency to manifest.json
Amansingh0807 Dec 9, 2025
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
224 changes: 224 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/truncbf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
<!--

@license Apache-2.0

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

-->

# truncbf

> Round a [single-precision floating-point number][ieee754] toward zero to `n` digits in base `b`.

<section class="usage">

## Usage

```javascript
var truncbf = require( '@stdlib/math/base/special/truncbf' );
```

#### truncbf( x, n, b )

Rounds a [single-precision floating-point number][ieee754] toward zero to `n` digits in base `b`.

```javascript
var v = truncbf( 3.14159, 2, 10 );
// returns 3.140000104904175

v = truncbf( 3.14159, 3, 10 );
// returns 3.1410000324249268

v = truncbf( 15.0, -1, 10 );
// returns 10.0

v = truncbf( -3.14159, 2, 10 );
// returns -3.140000104904175
```

If provided `NaN` or a `base` of `0`, the function returns `NaN`.

```javascript
var v = truncbf( NaN, 2, 10 );
// returns NaN

v = truncbf( 3.14, 2, 0 );
// returns NaN
```

If provided `x = ±0` or `x = ±infinity`, the function returns `x`.

```javascript
var PINF = require( '@stdlib/constants/float32/pinf' );
var NINF = require( '@stdlib/constants/float32/ninf' );

var v = truncbf( 0.0, 2, 10 );
// returns 0.0

v = truncbf( -0.0, 2, 10 );
// returns -0.0

v = truncbf( PINF, 2, 10 );
// returns Infinity

v = truncbf( NINF, 2, 10 );
// returns -Infinity
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- This function is the [single-precision floating-point][ieee754] equivalent of [`truncb`][@stdlib/math/base/special/truncb].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var randu = require( '@stdlib/random/base/randu' );
var truncbf = require( '@stdlib/math/base/special/truncbf' );

var x;
var i;

for ( i = 0; i < 100; i++ ) {
x = (randu() * 100.0) - 50.0;
console.log( 'truncbf(%d, 2, 10) = %d', x, truncbf( x, 2, 10 ) );
}
```

</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/math/base/special/truncbf.h"
```

#### stdlib_base_truncbf( x, n, b )

Rounds a [single-precision floating-point number][ieee754] toward zero to `n` digits in base `b`.

```c
float y = stdlib_base_truncbf( 3.14159f, 2, 10 );
// returns 3.14f
```

The function accepts the following arguments:

- **x**: `[in] float` input value.
- **n**: `[in] int32_t` number of digits.
- **b**: `[in] int32_t` base.

```c
float stdlib_base_truncbf( const float x, const int32_t n, const int32_t b );
```

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

### Examples

```c
#include "stdlib/math/base/special/truncbf.h"
#include <stdio.h>

int main( void ) {
const float x[] = { 3.14159f, -3.14159f, 15.0f, -15.0f };
const int32_t n[] = { 2, 3, -1, 0 };
const int32_t b = 10;

float y;
int i;
for ( i = 0; i < 4; i++ ) {
y = stdlib_base_truncbf( x[i], n[i], b );
printf( "truncbf(%f, %d, %d) = %f\n", x[i], n[i], b, y );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

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

[ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985

[@stdlib/math/base/special/truncb]: https://github.com/stdlib-js/stdlib

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 randu = require( '@stdlib/random/base/randu' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pkg = require( './../package.json' ).name;
var truncbf = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = (randu() * 100.0) - 50.0;
y = truncbf( x, 2, 10 );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::built-in', function benchmark( b ) {
var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = (randu() * 100.0) - 50.0;
y = Math.trunc( x * 100 ) / 100;
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var truncbf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( truncbf instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var x;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = (randu() * 100.0) - 50.0;
y = truncbf( x, 2, 10 );
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading
Loading