Created
September 1, 2018 04:42
-
-
Save westc/8069af4c97dd6dd1148e271d0314aba2 to your computer and use it in GitHub Desktop.
YourJS candidate functions: int8(), uint8(), int16(), uint16(), int32(), and uint32()
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
// Creates the following functions: int8(), uint8(), int16(), uint16(), int32(), and uint32() | |
// The int functions convert a number into a signed integer that can be represented by the number of bits specified by the function name (int8() returns 8-bit signed integers). | |
// The uint functions convert a number into an unsigned integer that can be represented by the number of bits specified by the function name (uint8() returns 8-bit unsigned integers). | |
eval('uUi32I32uUi16I16uUi8I8'.replace(/(u?)([UI]i?)(\d\d?)/g, 'var $1int$3;(function(a){$1int$3=function(x){return a[0]=x,a[0]}})(new $2nt$3Array(1));')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.yourjs.com/console?gist=8069af4c97dd6dd1148e271d0314aba2&file=integer+functions.js