mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
feat(bitwise): Function to check if a number is positive (#204)
This commit is contained in:
13
src/algorithms/math/bits/isPositive.js
Normal file
13
src/algorithms/math/bits/isPositive.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @param {number} number
|
||||
* @return {boolean}
|
||||
*/
|
||||
export default function isPositive(number) {
|
||||
// Zero is neither a positive nor a negative number
|
||||
if (number === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The most signification bit can be used to determine whether .
|
||||
return ((number >> 31) & 1) === 0;
|
||||
}
|
||||
Reference in New Issue
Block a user