Last active
December 10, 2015 20:38
-
-
Save ghalimi/4488961 to your computer and use it in GitHub Desktop.
BITLSHIFT Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2012 Sutoiku, Inc. (MIT License) | |
function BITLSHIFT(number, shift) { | |
// Return error if either number is a non-numeric value | |
if (isNaN(number) || isNaN(shift)) return '#VALUE!'; | |
// Return error if number is less than 0 | |
if (number < 0) return '#NUM!'; | |
// Return error if number is a non-integer | |
if (Math.floor(number) !== number) return '#NUM!'; | |
// Return error if number is greater than (2^48)-1 | |
if (number > 281474976710655) return '#NUM!'; | |
// Return error if the absolute value of shift is greater than 53 | |
if (Math.abs(shift) > 53) return '#NUM!'; | |
// Return number shifted by shift bits to the left or to the right if shift is negative | |
return (shift >= 0 ) ? number << shift : number >> -shift; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment