http://stackoverflow.com/questions/5678432/decompressing-half-precision-floats-in-javascript
770249
function decodeHalf (u16) {
    var exponent = (u16 & 0x7C00) >> 10,
        fraction = u16 & 0x03FF;
    return (u16 >> 15 ? -1 : 1) * (
        exponent ?
        (
            exponent === 0x1F ?
            fraction ? NaN : Infinity :
            Math.pow(2, exponent - 15) * (1 + fraction / 0x400)
        ) :
        6.103515625e-5 * (fraction / 0x400)
    );
}
915806
function calculateMaxValue(precision, scale) {
  const arr = _.fill(Array(precision), '9');

  if (scale) {
    arr.splice(precision - scale, 0, '.');
  }

  return parseFloat(arr.join(''));
}
1321487
function(input_32_bit_float_audio_obj, output_16_bit_audio_obj) {

    // MUST assure input float is BOUNDED between +1.0 to -1.0 ONLY

    // this is a lossless process - no information is thrown away

    // this logic MAINTAINS full information of input ... 32 bit float --> two 16 bit integers 
    // so NO loss of information - output buffer size is twice input buffer size
    // output 16 bit format can be later converted back into identical input 32 bit floats
    // DO NOT use this method to convert floats into 16 bit ints as preliminary step to save into WAV format
    // because that is a LOSSY process 

    var size_32_bit_float_buff = input_32_bit_float_audio_obj.buffer.length;

    // console.log("size 32 bit float ", size_32_bit_float_buff);

    var num_16_bit_chunks_per_32_bit_float = Float32Array.BYTES_PER_ELEMENT / 
                                    Uint16Array.BYTES_PER_ELEMENT;

    // console.log("num_16_bit_chunks_per_32_bit_float ", num_16_bit_chunks_per_32_bit_float);


    var size_16_bit_int_buff = size_32_bit_float_buff * num_16_bit_chunks_per_32_bit_float;

    // console.log("size 16 bit ints ", size_16_bit_int_buff); //  is OK

    output_16_bit_audio_obj.buffer = new Buffer(size_16_bit_int_buff);// input buffer is 32 bit we want 16 bit so half it

    // var one_float = new Float32Array(1);

    var one_float_in_2_16_bit_ints;
    // var curr_float;
    // var index_16_bit_ints = 0;

    var offset = 0;
    var same_value_in_16_bit_signed_int;
    // var local_divisor;

    // stens TODO - put below for loop into a try catch so when :

    /*

    14 ' aboutttttt to show raw float ' 1.2392250299453735
buffer.js:564
    throw new TypeError('value is out of bounds');
          ^
TypeError: value is out of bounds
    at checkInt (buffer.js:564:11)
    at Buffer.writeInt16LE (buffer.js:642:5)
    at convert_32_bit_floats_into_16_bit_ints (node-genome/src/node_utils.js:689:40)
    at Object.exports.write_buffer_to_file 

        when above happens - due to input raw float OUTSIDE boundary +1 <=> -1

    */

    for (var index_float = 0; index_float < size_32_bit_float_buff; index_float++) {

        // one_float[0] = input_32_bit_float_audio_obj.buffer[index_float];

        // if (index_float < 20) {

        //     console.log(index_float, " one_float ", one_float[0], 
        //                 " convert_32_bit_floats_into_16_bit_ints"); // is OK            
        // }

        // var same_value_in_16_bit_signed_int = ~~(one_float[0] * (32768 - 1));
        // https://stackoverflow.com/questions/11682804/confusion-in-16-bit-data-type-range

        /*
        if (one_float[0] < 0) {

        	same_value_in_16_bit_signed_int = ~~(one_float[0] * (0x8000)); // 32768

        } else {

        	same_value_in_16_bit_signed_int = ~~(one_float[0] * (0x7FFF)); // 32767
        }
        */

        // local_divisor = (one_float[0] < 0) ? 0x8000 : 0x7FFF; // 0x8000 = 32768 ... 0x7FFF = 32767

		// same_value_in_16_bit_signed_int = ~~(one_float[0] * (local_divisor));
		// same_value_in_16_bit_signed_int = ~~(one_float[0] * ((one_float[0] < 0) ? 0x8000 : 0x7FFF));// WORKS

        // console.log(index_float, " aboutttttt to show raw float ", input_32_bit_float_audio_obj.buffer[index_float]);

		same_value_in_16_bit_signed_int = ~~(input_32_bit_float_audio_obj.buffer[index_float] * 
                                            ((input_32_bit_float_audio_obj.buffer[index_float] < 0) ? 0x8000 : 0x7FFF));

        // if (index_float < 20) {

        //     console.log("same_value_in_16_bit_signed_int ", same_value_in_16_bit_signed_int);
        // }

        // output_16_bit_audio_obj.buffer[index_16_bit_ints++] = one_float_in_two_16_bit_ints[index_16_bit];

        output_16_bit_audio_obj.buffer.writeInt16LE(same_value_in_16_bit_signed_int, offset);
        offset += num_16_bit_chunks_per_32_bit_float;
    }

    // process.exit(3);

}
759420
function pf(value) {
    if (value === (value | 0)) { // integer number
      return value.toString();
    }
    var s = value.toFixed(10);
    var i = s.length - 1;
    if (s[i] !== '0') {
      return s;
    }
    // removing trailing zeros
    do {
      i--;
    } while (s[i] === '0');
    return s.substr(0, s[i] === '.' ? i : i + 1);
  }
199158
function int64add(dst, x, y) {
        var w0 = (x.l & 0xffff) + (y.l & 0xffff);
        var w1 = (x.l >>> 16) + (y.l >>> 16) + (w0 >>> 16);
        var w2 = (x.h & 0xffff) + (y.h & 0xffff) + (w1 >>> 16);
        var w3 = (x.h >>> 16) + (y.h >>> 16) + (w2 >>> 16);
        dst.l = (w0 & 0xffff) | (w1 << 16);
        dst.h = (w2 & 0xffff) | (w3 << 16);
      }
69331
def encode_float(self, value):
        
        s = '%e' % value
        l = s.split('e')
        mantissa = l[0].ljust(18, '0')
        exponent = l[1]
        if value == 0.0:
            case = '3'
            exponent = '000'
        elif mantissa[0] != '-' and exponent[0] == '+':
            case = '5'
            exponent = exponent[1:].rjust(3, '0')
        elif mantissa[0] != '-' and exponent[0] == '-':
            case = '4'
            exponent = 999 + int(exponent)
            exponent = '%03d' % exponent
        elif mantissa[0] == '-' and exponent[0] == '-':
            case = '2'
            mantissa = '%f' % (10 + float(mantissa))
            mantissa = mantissa.ljust(18, '0')
            exponent = exponent[1:].rjust(3, '0')
        else:
            case = '1'
            mantissa = '%f' % (10 + float(mantissa))
            mantissa = mantissa.ljust(18, '0')
            exponent = 999 - int(exponent)
            exponent = '%03d' % exponent
        return '%s %s %s' % (case, exponent, mantissa)
406564
function (str) {
            
            var typeOf = typeof str;
            if (typeOf === 'number')
                return str;
            
            else if (typeOf !== 'string')
                return Number.NaN;
            
            else if (_floatRegex.test(str))
                return parseFloat(str);
                
            else if (   str === 'Infinity'
                     || str === '+Infinity' )
                return Number.POSITIVE_INFINITY;
            
            else if (str === '-Infinity')
                return Number.NEGATIVE_INFINITY;
            
            else  // whether "NaN" or any other string
                return Number.NaN;
        }
741125
function (val) {
/*Line 535 - 'Atom.js' */        if (!val)
/*Line 536 - 'Atom.js' */            return "";
/*Line 537 - 'Atom.js' */        if (val.constructor == String)
/*Line 538 - 'Atom.js' */            val = parseInt(val, 10);
/*Line 539 - 'Atom.js' */        if (val > 1073741824) {
/*Line 540 - 'Atom.js' */            return Math.round(val / 1073741824) + " GB";
/*Line 541 - 'Atom.js' */        }
/*Line 542 - 'Atom.js' */        if (val > 1048576) {
/*Line 543 - 'Atom.js' */            return Math.round(val / 1048576) + " MB";
/*Line 544 - 'Atom.js' */        }
/*Line 545 - 'Atom.js' */        if (val > 1024) {
/*Line 546 - 'Atom.js' */            return Math.round(val / 1024) + " KB";
/*Line 547 - 'Atom.js' */        }
/*Line 548 - 'Atom.js' */        return val + " B";
/*Line 549 - 'Atom.js' */    }
795209
def _unfloat(flt, precision=5):
    

    if flt == 0.:
        return "{}-0".format("0" * precision)

    num, _, exp = "{:.{}e}".format(flt, precision - 1).partition('e')
    exp = int(exp)
    num = num.replace('.', '')

    return "%s%d" % (num, exp + 1)
96863
function decode(str) {
	// FIXME: Check for multiplication overflow
	if (str.length > 12) {
		throw new TypeError("Number encoded is too large");
	}

	var num = new UInt64();
	for (let i=0; i<str.length; i++) {
		let n = CHARS.indexOf(str[i]);
		if (n === -1) {
			throw new TypeError("Unknown character in string");
		}
		num.multiply(SIXTY_TWO);
		num.add(new UInt64(n));
	}

	var buf = new Buffer(8);
	num.div(UINT32_CAPACITY);
	buf.writeUInt32BE(parseInt(num.toString()), 0);
	buf.writeUInt32BE(num.remainder, 4);
	return buf;
}
823239
function decimal(_num, _precision) {

	// If _num is undefined, assing 0	
	if(_num === undefined) _num = 0;
	
	// If _precision is undefined, assigned 2
	if(_precision === undefined) _num = 2;

    n = Math.abs(_num);
    
    var sign = '';
    if(_num < 0)
    	sign = '-';
    	
    return sign + n.toFixed(_precision);
}
604899
function precBase(base, value, precision) {
	const val = value.toString(base);
	const floatingPoint = val.indexOf('.');
	if (precision === 0 && floatingPoint > -1) {
		return val.substring(0, floatingPoint);//Node version > 0.10.*
	}
	if (floatingPoint === -1) {
		return val;
	}
	if (val.length - floatingPoint > precision) {
		return val.substring(0, floatingPoint + precision + 1);
	}
}
381167
def floats(s):
    """"""
    try:
        return float(s)
    except ValueError:
        s = re.sub(r'(\d)\s*\(\d+(\.\d+)?\)', r'\1', s)        # Remove bracketed numbers from end
        s = re.sub(r'(\d)\s*±\s*\d+(\.\d+)?', r'\1', s)        # Remove uncertainties from end
        s = s.rstrip('\'"+-=<>/,.:;!?)]}…∼~≈×*_≥≤')             # Remove trailing punctuation
        s = s.lstrip('\'"+=<>/([{∼~≈×*_≥≤£$€#§')                # Remove leading punctuation
        s = s.replace(',', '')                                 # Remove commas
        s = ''.join(s.split())                                  # Strip whitespace
        s = re.sub(r'(\d)\s*[×x]\s*10\^?(-?\d)', r'\1e\2', s)  # Convert scientific notation
        return float(s)
1150877
private static float bytesToFloat(byte b0, byte b1, byte b2, byte b3) {
        int mantissa = unsignedToSigned(unsignedByteToInt(b0)
                + (unsignedByteToInt(b1) << 8)
                + (unsignedByteToInt(b2) << 16), 24);
        return (float) (mantissa * Math.pow(10, b3));
    }
1325301
def float_to_knx2(floatval):
    """"""

    if floatval < -671088.64 or floatval > 670760.96:
        raise KNXException("float {} out of valid range".format(floatval))

    floatval = floatval * 100

    i = 0
    for i in range(0, 15):
        exp = pow(2, i)
        if ((floatval / exp) >= -2048) and ((floatval / exp) < 2047):
            break

    if floatval < 0:
        sign = 1
        mantisse = int(2048 + (floatval / exp))
    else:
        sign = 0
        mantisse = int(floatval / exp)

    return [(sign << 7) + (i << 3) + (mantisse >> 8),
            mantisse & 0xff]
564150
function floatSafeRemainder(val, step) {
  const valDecCount = (val.toString().split('.')[1] || '').length;
  const stepDecCount = (step.toString().split('.')[1] || '').length;
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
  const valInt = parseInt(val.toFixed(decCount).replace('.', ''), 10);
  const stepInt = parseInt(step.toFixed(decCount).replace('.', ''), 10);
  return (valInt % stepInt) / Math.pow(10, decCount);
}
285451
static void
    JS_dtostr(StringBuilder buffer, int mode, int precision, double d)
    {
        int decPt;                                    /* Position of decimal point relative to first digit returned by JS_dtoa */
        boolean[] sign = new boolean[1];            /* true if the sign bit was set in d */
        int nDigits;                                /* Number of significand digits returned by JS_dtoa */

//        JS_ASSERT(bufferSize >= (size_t)(mode <= DTOSTR_STANDARD_EXPONENTIAL ? DTOSTR_STANDARD_BUFFER_SIZE :
//                DTOSTR_VARIABLE_BUFFER_SIZE(precision)));

        if (mode == DTOSTR_FIXED && (d >= 1e21 || d <= -1e21))
            mode = DTOSTR_STANDARD; /* Change mode here rather than below because the buffer may not be large enough to hold a large integer. */

        decPt = JS_dtoa(d, dtoaModes[mode], mode >= DTOSTR_FIXED, precision, sign, buffer);
        nDigits = buffer.length();

        /* If Infinity, -Infinity, or NaN, return the string regardless of the mode. */
        if (decPt != 9999) {
            boolean exponentialNotation = false;
            int minNDigits = 0;         /* Minimum number of significand digits required by mode and precision */
            int p;

            switch (mode) {
                case DTOSTR_STANDARD:
                    if (decPt < -5 || decPt > 21)
                        exponentialNotation = true;
                    else
                        minNDigits = decPt;
                    break;

                case DTOSTR_FIXED:
                    if (precision >= 0)
                        minNDigits = decPt + precision;
                    else
                        minNDigits = decPt;
                    break;

                case DTOSTR_EXPONENTIAL:
//                    JS_ASSERT(precision > 0);
                    minNDigits = precision;
                    /* fallthru */
                case DTOSTR_STANDARD_EXPONENTIAL:
                    exponentialNotation = true;
                    break;

                case DTOSTR_PRECISION:
//                    JS_ASSERT(precision > 0);
                    minNDigits = precision;
                    if (decPt < -5 || decPt > precision)
                        exponentialNotation = true;
                    break;
            }

            /* If the number has fewer than minNDigits, pad it with zeros at the end */
            if (nDigits < minNDigits) {
                p = minNDigits;
                nDigits = minNDigits;
                do {
                    buffer.append('0');
                } while (buffer.length() != p);
            }

            if (exponentialNotation) {
                /* Insert a decimal point if more than one significand digit */
                if (nDigits != 1) {
                    buffer.insert(1, '.');
                }
                buffer.append('e');
                if ((decPt - 1) >= 0)
                    buffer.append('+');
                buffer.append(decPt - 1);
//                JS_snprintf(numEnd, bufferSize - (numEnd - buffer), "e%+d", decPt-1);
            } else if (decPt != nDigits) {
                /* Some kind of a fraction in fixed notation */
//                JS_ASSERT(decPt <= nDigits);
                if (decPt > 0) {
                    /* dd...dd . dd...dd */
                    buffer.insert(decPt, '.');
                } else {
                    /* 0 . 00...00dd...dd */
                    for (int i = 0; i < 1 - decPt; i++)
                        buffer.insert(0, '0');
                    buffer.insert(1, '.');
                }
            }
        }

        /* If negative and neither -0.0 nor NaN, output a leading '-'. */
        if (sign[0] &&
                !(word0(d) == Sign_bit && word1(d) == 0) &&
                !((word0(d) & Exp_mask) == Exp_mask &&
                  ((word1(d) != 0) || ((word0(d) & Frac_mask) != 0)))) {
            buffer.insert(0, '-');
        }
    }