Skip to content

Instantly share code, notes, and snippets.

Avatar

Ismael Ghalimi ghalimi

View GitHub Profile
@ghalimi
ghalimi / NORMDIST.js
Last active Sep 25, 2019
NORMDIST Function
View NORMDIST.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function NORMDIST(x, mean, sd, cumulative) {
// Check parameters
if (isNaN(x) || isNaN(mean) || isNaN(sd)) return '#VALUE!';
if (sd <= 0) return '#NUM!';
// Return normal distribution computed by jStat [http://jstat.org]
return (cumulative) ? jStat.normal.cdf(x, mean, sd) : jStat.normal.pdf(x, mean, sd);
}
@ghalimi
ghalimi / BIN2HEX.js
Last active Dec 10, 2015
BIN2HEX Function
View BIN2HEX.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function BIN2HEX(number, places) {
// Return error if number is not binary or contains more than 10 characters (10 digits)
if (!/^[01]{1,10}$/.test(number)) return '#NUM!';
// Ignore places and return a 10-character hexadecimal number if number is negative
var stringified = number.toString();
if (stringified.length === 10 && stringified.substring(0, 1) === '1') {
return (1099511627264 + parseInt(stringified.substring(1), 2)).toString(16);
@ghalimi
ghalimi / BIN2DEC.js
Last active Dec 10, 2015
BIN2DEC Function
View BIN2DEC.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function BIN2DEC(number) {
// Return error if number is not binary or contains more than 10 characters (10 digits)
if (!/^[01]{1,10}$/.test(number)) return '#NUM!';
// Convert binary number to decimal
var result = parseInt(number, 2);
// Handle negative numbers
@ghalimi
ghalimi / BIN2OCT.js
Last active Dec 10, 2015
BIN2OCT Function
View BIN2OCT.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function BIN2OCT(number, places) {
// Return error if number is not binary or contains more than 10 characters (10 digits)
if (!/^[01]{1,10}$/.test(number)) return '#NUM!';
// Ignore places and return a 10-character octal number if number is negative
var stringified = number.toString();
if (stringified.length === 10 && stringified.substring(0, 1) === '1') {
return (1073741312 + parseInt(stringified.substring(1), 2)).toString(8);
@ghalimi
ghalimi / DEC2HEX.js
Last active Mar 22, 2022
DEC2HEX Function
View DEC2HEX.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function DEC2HEX(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,12}$/.test(number) || number < -549755813888 || number > 549755813887) return '#NUM!';
// Ignore places and return a 10-character hexadecimal number if number is negative
@ghalimi
ghalimi / BITAND.js
Created Jan 8, 2013
BITAND Function
View BITAND.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function BITAND(number1, number2) {
// Return error if either number is a non-numeric value
if (isNaN(number1) || isNaN(number2)) return '#VALUE!';
// Return error if either number is less than 0
if (number1 < 0 || number2 < 0) return '#NUM!';
// Return error if either number is a non-integer
@ghalimi
ghalimi / BITOR.js
Created Jan 8, 2013
BITOR Function
View BITOR.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function BITOR(number1, number2) {
// Return error if either number is a non-numeric value
if (isNaN(number1) || isNaN(number2)) return '#VALUE!';
// Return error if either number is less than 0
if (number1 < 0 || number2 < 0) return '#NUM!';
// Return error if either number is a non-integer
@ghalimi
ghalimi / BITXOR.js
Created Jan 8, 2013
BITXOR Function
View BITXOR.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function BITXOR(number1, number2) {
// Return error if either number is a non-numeric value
if (isNaN(number1) || isNaN(number2)) return '#VALUE!';
// Return error if either number is less than 0
if (number1 < 0 || number2 < 0) return '#NUM!';
// Return error if either number is a non-integer
@ghalimi
ghalimi / BITLSHIFT.js
Last active Dec 10, 2015
BITLSHIFT Function
View BITLSHIFT.js
// 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
@ghalimi
ghalimi / BITRSHIFT.js
Created Jan 8, 2013
BITRSHIFT Function
View BITRSHIFT.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function BITRSHIFT(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