Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@stdlib/number-float64-base-to-float32
Advanced tools
Convert a double-precision floating-point number to the nearest single-precision floating-point number.
@stdlib/number-float64-base-to-float32 is a utility package that provides functionality to convert 64-bit floating-point numbers (float64) to 32-bit floating-point numbers (float32). This can be useful in scenarios where memory efficiency is critical, or when interfacing with systems that require 32-bit floating-point numbers.
Convert float64 to float32
This feature allows you to convert a 64-bit floating-point number to a 32-bit floating-point number. The code sample demonstrates converting the number π (pi) from float64 to float32.
const toFloat32 = require('@stdlib/number-float64-base-to-float32');
const float64 = 3.141592653589793;
const float32 = toFloat32(float64);
console.log(float32); // 3.1415927410125732
While not directly converting float64 to float32, 'typedarray-to-buffer' can be used to handle various typed arrays, including Float32Array. It is useful for converting typed arrays to Node.js buffers, which can then be manipulated or converted as needed.
Convert a double-precision floating-point number to the nearest single-precision floating-point number.
npm install @stdlib/number-float64-base-to-float32
var float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );
Converts a double-precision floating-point number to the nearest single-precision floating-point number.
var y = float64ToFloat32( 1.337 );
// returns 1.3370000123977661
Math.fround
.var randu = require( '@stdlib/random-base-randu' );
var float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );
var f64;
var f32;
var i;
// Convert random double-precision floating-point numbers to the nearest single-precision floating-point number...
for ( i = 0; i < 1000; i++ ) {
f64 = randu() * 100.0;
f32 = float64ToFloat32( f64 );
console.log( 'float64: %d => float32: %d', f64, f32 );
}
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-2021. The Stdlib Authors.
0.0.5 (2021-08-22)
No changes reported for this release.
</section> <!-- /.release --> <section class="release" id="v0.0.4">FAQs
Convert a double-precision floating-point number to the nearest single-precision floating-point number.
The npm package @stdlib/number-float64-base-to-float32 receives a total of 0 weekly downloads. As such, @stdlib/number-float64-base-to-float32 popularity was classified as not popular.
We found that @stdlib/number-float64-base-to-float32 demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.