Skip to content

Instantly share code, notes, and snippets.

Avatar

Ismael Ghalimi ghalimi

View GitHub Profile
@ghalimi
ghalimi / COMPLEX.js
Last active Dec 10, 2015
COMPLEX Function
View COMPLEX.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function COMPLEX(real, imaginary, suffix) {
// Return error if either number is a non-numeric value
if (isNaN(real) || isNaN(imaginary)) return '#VALUE!';
// Set suffix
var suffix = (typeof suffix === 'undefined') ? 'i' : suffix;
// Return error if suffix is neither "i" nor "j"
@ghalimi
ghalimi / CONVERT.js
Created Jan 10, 2013
CONVERT Function
View CONVERT.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function CONVERT(number, from_unit, to_unit) {
// Return error if number is a non-numeric value
if (isNaN(number)) return '#VALUE!';
// List of units supported by CONVERT and units defined by the International System of Units
// [Name, Symbol, Alternate symbols, Quantity, International System of Units, Supported by CONVERT, Conversion ratio]
var units = [
["a.u. of action","ħ",null,"action",false,false,1.05457168181818e-34],
@ghalimi
ghalimi / DEC2BIN.js
Last active Dec 11, 2015
DEC2BIN Function
View DEC2BIN.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function DEC2BIN(number, places) {
// Return error if number is not a number
if (isNaN(number)) return '#VALUE!';
// Return error if number is not decimal, is lower than -512, or is greater than 511
if (!/^-?[0-9]{1,3}$/.test(number) || number < -512 || number > 511) return '#NUM!';
// Ignore places and return a 10-character binary number if number is negative
@ghalimi
ghalimi / DEC2OCT.js
Last active Dec 11, 2015
DEC2OCT Function
View DEC2OCT.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function DEC2OCT(number, places) {
// Return error if number is not a number
if (isNaN(number)) return '#VALUE!';
// Return error if number is not decimal, is lower than -549755813888, or is greater than 549755813887
if (!/^-?[0-9]{1,9}$/.test(number) || number < -536870912 || number > 536870911) return '#NUM!';
// Ignore places and return a 10-character octal number if number is negative
@ghalimi
ghalimi / DELTA.js
Created Jan 13, 2013
DELTA Function
View DELTA.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function DELTA(number1, number2) {
// Set number2 to zero if undefined
number2 = (typeof number2 === 'undefined') ? 0 : number2;
// Return error if either number is not a number
if (isNaN(number1) || isNaN(number2)) return '#VALUE!';
// Return delta
@ghalimi
ghalimi / ERFC.js
Created Jan 13, 2013
ERFC Function
View ERFC.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function ERFC(x) {
// Return error if x is not a number
if (isNaN(x)) return '#VALUE!';
// Return ERFC using jStat [http://www.jstat.org/]
return jStat.erfc(x);
}
@ghalimi
ghalimi / ERF.js
Created Jan 13, 2013
ERF Function
View ERF.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function ERF(lower_bound, upper_bound) {
// Set number2 to zero if undefined
upper_bound = (typeof upper_bound === 'undefined') ? 0 : upper_bound;
// Return error if either number is not a number
if (isNaN(lower_bound) || isNaN(upper_bound)) return '#VALUE!';
// Return ERFC using jStat [http://www.jstat.org/]
@ghalimi
ghalimi / GESTEP.js
Created Jan 13, 2013
GESTEP Function
View GESTEP.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function GESTEP(number, step) {
// Set step to zero if undefined
step = (typeof step === 'undefined') ? 0 : step;
// Return error if either number is not a number
if (isNaN(number) || isNaN(step)) return '#VALUE!';
// Return delta
@ghalimi
ghalimi / HEX2BIN.js
Last active Aug 7, 2016
HEX2BIN Function
View HEX2BIN.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function HEX2BIN(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!';
// Check if number is negative
var negative = (number.length === 10 && number.substring(0, 1).toLowerCase() === 'f') ? true : false;
// Convert hexadecimal number to decimal
@ghalimi
ghalimi / HEX2DEC.js
Last active May 18, 2021
HEX2DEC Function
View HEX2DEC.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function HEX2DEC(number) {
// 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 decimal number