main.js (1314B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MAIN // 22 23 /** 24 * Converts an unsigned 32-bit integer to a signed 32-bit integer. 25 * 26 * @param {uinteger32} x - unsigned 32-bit integer 27 * @returns {integer32} signed 32-bit integer 28 * 29 * @example 30 * var float64ToUint32 = require( '@stdlib/number/float64/base/to-uint32' ); 31 * var y = uint32ToInt32( float64ToUint32( 4294967295 ) ); 32 * // returns -1 33 * 34 * @example 35 * var float64ToUint32 = require( '@stdlib/number/float64/base/to-uint32' ); 36 * var y = uint32ToInt32( float64ToUint32( 3 ) ); 37 * // returns 3 38 */ 39 function uint32ToInt32( x ) { 40 // NOTE: we could also use typed-arrays to achieve the same end. 41 return x|0; // asm type annotation 42 } 43 44 45 // EXPORTS // 46 47 module.exports = uint32ToInt32;