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 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) |
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 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 |
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 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 |
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 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 |
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 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 |
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 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 |
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 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!'; | |
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 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!'; |
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 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'; |
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 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); | |