util/bin.js
function writeLong(buffer, offset, value){

	var first = value, second = value >= 0 ? Math.floor(value / 2147483648) : Math.ceil(value / 2147483648);

	var sign = first > 0 ? 1 : -1;
	first = (sign*first) % 2147483648;
	
	first = sign*first;
	
	//require('sys').puts(value + ' k ' + (first + (second*2147483648)));
		
	//require('sys').puts('w ' + first + ',' + second);
	
	writeInt(buffer, offset, first);
	writeInt(buffer, offset+4, second);
}
function writeLong(buffer, offset, value){

	var first = value, second = value >= 0 ? Math.floor(value / 2147483648) : Math.ceil(value / 2147483648);

	var sign = first > 0 ? 1 : -1;
	first = (sign*first) % 2147483648;
	
	first = sign*first;
	
	//require('sys').puts(value + ' k ' + (first + (second*2147483648)));
		
	//require('sys').puts('w ' + first + ',' + second);
	
	writeInt(buffer, offset, first);
	writeInt(buffer, offset+4, second);
}
/*
function testCompactInts(){
var m = 1024*1024;
var k=0;
for(var i=k*m;i<2048*m;i+=m){
var b = new Buffer(5*m);
var off = 0;
for(var j=0;j<m;++j){
var n = j+i;
off += writeUnsignedIntCompactly(b, off, n);
}
off = 0;
for(var j=0;j<m;++j){
var n = j+i;
var res = readUnsignedIntCompactly(b, off);
if(n !== res[1]){
for(var i=0;i<5;++i){
console.log(b[off+i]);
}
console.log('error(' + res[0] + '), read(' + res[1] + ') does not match(' + n + ')');
throw 'error';
}
off += res[0];
}
console.log('passed ' + k + '/2048 (' + n + ') (' + off + '/' + (5*m) + ' : ' + (off/(5*m)) + ')');
++k;
}
console.log('compact int test passed');
_.errout('done');
}
testCompactInts();