About stdlib...
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!
Return a normal number
yand exponentexpsatisfyingx = y * 2^exp.
npm install @stdlib/number-float64-base-normalizeAlternatively,
- To load the package in a website via a
scripttag without installation and bundlers, use the ES Module available on theesmbranch (see README). - If you are using Deno, visit the
denobranch (see README for usage intructions). - For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the
umdbranch (see README).
The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
varnormalize=require('@stdlib/number-float64-base-normalize');Returns a normal number y and exponent exp satisfying x = y * 2^exp.
varpow=require('@stdlib/math-base-special-pow');varout=normalize(3.14e-319);// returns [ 1.4141234400356668e-303, -52 ]vary=out[0];varexp=out[1];varbool=(y*pow(2.0,exp)===3.14e-319);// returns trueThe function expects a finite, non-zero numeric value x. If x == 0,
varout=normalize(0.0);// returns [ 0.0, 0 ];If x is either positive or negative infinity or NaN,
varPINF=require('@stdlib/constants-float64-pinf');varNINF=require('@stdlib/constants-float64-ninf');varout=normalize(PINF);// returns [ Infinity, 0 ]out=normalize(NINF);// returns [ -Infinity, 0 ]out=normalize(NaN);// returns [ NaN, 0 ]Returns a normal number y and exponent exp satisfying x = y * 2^exp and assigns results to a provided output array.
varFloat64Array=require('@stdlib/array-float64');varout=newFloat64Array(2);varv=normalize.assign(3.14e-319,out,1,0);// returns <Float64Array>[ 1.4141234400356668e-303, -52 ]varbool=(v===out);// returns truevardiscreteUniform=require('@stdlib/random-base-discrete-uniform');varrandu=require('@stdlib/random-base-uniform');varpow=require('@stdlib/math-base-special-pow');varnormalize=require('@stdlib/number-float64-base-normalize');varfrac;varexp;varx;varv;vari;// Generate denormalized numbers and then normalize them...for(i=0;i<100;i++){// Generate a random fraction:frac=randu(0.0,10.0);// Generate an exponent on the interval (-308,-324):exp=discreteUniform(-323,-309);// Create a subnormal number (~2.23e-308, ~4.94e-324):x=frac*pow(10.0,exp);// Determine a `y` and an `exp` to "normalize" the subnormal:v=normalize(x);console.log('%d = %d * 2^%d = %d',x,v[0],v[1],v[0]*pow(2.0,v[1]));}#include"stdlib/number/float64/base/normalize.h"Returns a normal number y and exponent exp satisfying x = y * 2^exp.
#include<stdint.h>doubley;
int32_texp;
stdlib_base_float64_normalize( 3.14, &y, &exp );The function accepts the following arguments:
- x:
[in] doubleinput value. - y:
[out] double*destination for normal number. - exp:
[out] int32_t*destination for exponent.
voidstdlib_base_float64_normalize( constdoublex, double*y, int32_t*exp );#include"stdlib/number/float64/base/normalize.h"#include<stdint.h>#include<stdio.h>#include<inttypes.h>intmain( void ) {
doublex[] = { 1.0, 3.14, 0.0, -0.0, 3.14e-308, 3.14e308, 1.0/0.0, 0.0/0.0 };
int32_texp;
doubley;
inti;
for ( i=0; i<8; i++ ) {
stdlib_base_float64_normalize( x[ i ], &y, &exp );
printf( "%lf => y: %lf, exp: %"PRId32"\n", x[ i ], y, exp );
}
}@stdlib/number-float32/base/normalize: return a normal numberyand exponentexpsatisfyingx = y * 2^exp.
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-2026. The Stdlib Authors.