Return an unsigned 32-bit integer corresponding to the IEEE 754 binary representation of a single-precision floating-point number.
var toWordf = require( '@stdlib/math/base/utils/float32-to-word' );
Returns an unsigned 32-bit integer
corresponding to the IEEE 754 binary representation of a single-precision floating-point number.
var float64ToFloat32 = require( '@stdlib/math/base/utils/float64-to-float32' );
var f32 = float64ToFloat32( 1.337 );
// returns 1.3370000123977661
var w = toWordf( f32 ); // => 0 01111111 01010110010001011010001
// returns 1068180177
-
The equivalent of this function in C/C++,
unsigned int toWordf(float x) { return *(unsigned int*)&x; }
var float64ToFloat32 = require( '@stdlib/math/base/utils/float64-to-float32' );
var randu = require( '@stdlib/math/base/random/randu' );
var toWordf = require( '@stdlib/math/base/utils/float32-to-word' );
var word;
var f64;
var f32;
var i;
// Convert single-precision floating-point numbers to integers representing the binary literal...
for ( i = 0; i < 1000; i++ ) {
f64 = (randu()*100.0) - 50.0;
f32 = float64ToFloat32( f64 );
word = toWordf( f32 );
console.log( 'float64: %d => float32: %d => word: %d', f64, f32, word );
}