
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
@stdlib/math-base-special-round
Advanced tools
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
Round a numeric value to the nearest integer.
npm install @stdlib/math-base-special-round
var round = require( '@stdlib/math-base-special-round' );
Rounds a numeric
value to the nearest integer
.
var v = round( -4.2 );
// returns -4.0
v = round( -4.5 );
// returns -4.0
v = round( -4.6 );
// returns -5.0
v = round( 9.99999 );
// returns 10.0
v = round( 9.5 );
// returns 10.0
v = round( 9.2 );
// returns 9.0
v = round( 0.0 );
// returns 0.0
v = round( -0.0 );
// returns -0.0
v = round( Infinity );
// returns Infinity
v = round( -Infinity );
// returns -Infinity
v = round( NaN );
// returns NaN
var randu = require( '@stdlib/random-base-randu' );
var round = require( '@stdlib/math-base-special-round' );
var x;
var i;
for ( i = 0; i < 100; i++ ) {
x = (randu()*100.0) - 50.0;
console.log( 'Value: %d. Rounded: %d.', x, round( x ) );
}
#include "stdlib/math/base/special/round.h"
Rounds a numeric
value to the nearest integer
.
double out = stdlib_base_round( -4.2 );
// returns -4.0
The function accepts the following arguments:
[in] double
input value.double stdlib_base_round( const double x );
#include "stdlib/math/base/special/round.h"
#include <stdio.h>
int main( void ) {
const double x[] = { -5.0, -3.89, -2.78, -1.67, -0.56, 0.56, 1.67, 2.78, 3.89, 5.0 };
double v;
int i;
for ( i = 0; i < 10; i++ ) {
v = stdlib_base_round( x[ i ] );
printf( "round(%lf) = %lf\n", x[ i ], v );
}
}
@stdlib/math-base/special/ceil
: round a double-precision floating-point number toward positive infinity.@stdlib/math-base/special/floor
: round a double-precision floating-point number toward negative infinity.@stdlib/math-base/special/roundn
: round a double-precision floating-point number to the nearest multiple of 10^n.@stdlib/math-base/special/trunc
: round a double-precision floating-point number toward zero.This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2024. The Stdlib Authors.
0.3.0 (2024-07-27)
<section class="features">0227bf0
- add C implementation for math/base/special/round
947e77f
- handle large numbers correctly and revert to Math.round for JS62e703a
- docs: add missing @private
in math/base/special/round/lib/native.js
(#2536) (by Gunj Joshi)133dd8b
- chore: update package meta data (#2251) (by stdlib-bot)c37109b
- test: fix missing argument (by Athan Reines)947e77f
- fix: handle large numbers correctly and revert to Math.round for JS (by Philipp Burckhardt)0227bf0
- feat: add C implementation for math/base/special/round
(by Pranav Goswami, Philipp Burckhardt)A total of 4 people contributed to this release. Thank you to the following contributors:
FAQs
Round a numeric value to the nearest integer.
The npm package @stdlib/math-base-special-round receives a total of 46,550 weekly downloads. As such, @stdlib/math-base-special-round popularity was classified as popular.
We found that @stdlib/math-base-special-round demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.