Skip to content

Instantly share code, notes, and snippets.

View ghalimi's full-sized avatar

Ismael Ghalimi ghalimi

View GitHub Profile
@ghalimi
ghalimi / HEX2OCT.js
Last active December 11, 2015 01:48
HEX2OCT Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function HEX2OCT(number, places) {
// Return error if number is not hexadecimal or contains more than ten characters (10 digits)
if (!/^[0-9A-Fa-f]{1,10}$/.test(number)) return '#NUM!';
// Convert hexadecimal number to decimal
var decimal = parseInt(number, 16);
// Return error if number is positive and greater than 0x1fffffff (536870911)
@ghalimi
ghalimi / OCT2BIN.js
Created January 13, 2013 19:30
OCT2BIN Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function OCT2BIN(number, places) {
// Return error if number is not hexadecimal or contains more than ten characters (10 digits)
if (!/^[0-7]{1,10}$/.test(number)) return '#NUM!';
// Check if number is negative
var negative = (number.length === 10 && number.substring(0, 1) === '7') ? true : false;
// Convert octal number to decimal
@ghalimi
ghalimi / OCT2DEC.js
Created January 13, 2013 19:49
OCT2DEC Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function OCT2DEC(number) {
// Return error if number is not octal or contains more than ten characters (10 digits)
if (!/^[0-7]{1,10}$/.test(number)) return '#NUM!';
// Convert octal number to decimal
var decimal = parseInt(number, 8);
// Return decimal number
@ghalimi
ghalimi / OCT2HEX.js
Created January 13, 2013 20:10
OCT2HEX Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function OCT2HEX(number, places) {
// Return error if number is not octal or contains more than ten characters (10 digits)
if (!/^[0-7]{1,10}$/.test(number)) return '#NUM!';
// Convert octal number to decimal
var decimal = parseInt(number, 8);
// Ignore places and return a 10-character octal number if number is negative
@ghalimi
ghalimi / IMREAL.js
Last active December 11, 2015 01:49
IMREAL Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function IMREAL(inumber) {
// Return 0 if inumber is equal to 0
if (inumber === 0 || inumber === '0') return 0;
// Handle special cases
if (['i', '+i', '1i', '+1i', '-i', '-1i', 'j', '+j', '1j', '+1j', '-j', '-1j'].indexOf(inumber) >= 0) return 0;
// Lookup sign
@ghalimi
ghalimi / IMAGINARY.js
Last active December 11, 2015 01:49
IMAGINARY Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function IMAGINARY(inumber) {
// Return 0 if inumber is equal to 0
if (inumber === 0 || inumber === '0') return 0;
// Handle special cases
if (['i', 'j'].indexOf(inumber) >= 0) return 1;
// Normalize imaginary coefficient
@ghalimi
ghalimi / IMABS.js
Last active December 11, 2015 01:49
IMABS Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function IMABS(inumber) {
// Lookup real and imaginary coefficients using Formula.js [http://formulajs.org]
var x = IMREAL(inumber);
var y = IMAGINARY(inumber);
// Return error if either coefficient is not a number
if (x === '#NUM!' || y === '#NUM!') return '#NUM!';
@ghalimi
ghalimi / IMARGUMENT.js
Last active December 11, 2015 01:49
IMARGUMENT Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function IMARGUMENT(inumber) {
// Lookup real and imaginary coefficients using Formula.js [http://formulajs.org]
var x = IMREAL(inumber);
var y = IMAGINARY(inumber);
// Return error if either coefficient is not a number
if (x === '#NUM!' || y === '#NUM!') return '#NUM!';
@ghalimi
ghalimi / IMCONJUGATE.js
Last active December 11, 2015 01:58
IMCONJUGATE Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function IMCONJUGATE(inumber) {
// Lookup real and imaginary coefficients using Formula.js [http://formulajs.org]
var x = IMREAL(inumber);
var y = IMAGINARY(inumber);
// Lookup imaginary unit
var unit = inumber.substring(inumber.length - 1);
unit = (unit === 'i' || unit === 'j') ? unit : 'i';
@ghalimi
ghalimi / IMCOS.js
Last active December 11, 2015 01:58
IMCOS Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function IMCOS(inumber) {
// Return error if inumber is a logical value
if (inumber === true || inumber === false) return '#VALUE!';
// Lookup real and imaginary coefficients using Formula.js [http://formulajs.org]
var x = IMREAL(inumber);
var y = IMAGINARY(inumber);