Skip to content

Files

Latest commit

a67388c · Dec 31, 2016

History

History

float32-to-word

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Dec 31, 2016
Jun 1, 2016
Sep 2, 2016
Dec 31, 2016
Dec 7, 2016

toWord

Return an unsigned 32-bit integer corresponding to the IEEE 754 binary representation of a single-precision floating-point number.

Usage

var toWordf = require( '@stdlib/math/base/utils/float32-to-word' );

toWordf( x )

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

Notes

  • The equivalent of this function in C/C++,

    unsigned int toWordf(float x) {
      return *(unsigned int*)&x;
    }

Examples

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 );
}