Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Created July 28, 2014 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmpvar/fd36cc4c3ed71743894a to your computer and use it in GitHub Desktop.
Save tmpvar/fd36cc4c3ed71743894a to your computer and use it in GitHub Desktop.
attempt at robust-split for robust geometric predicates
var SPLITTER = +(Math.pow(2, 27) + 1.0)
var rsplit = function(a) {
var ret = new Array(2);
var c = SPLITTER*a
ret[1] = c - (c - a);
ret[0] = a - ret[1];
return ret;
}
console.log(rsplit(.3));
// output: [2.980232227667301e-9, 0.29999999701976776]
// vs
// robust-sum([.1], [.2]) === [-2.7755575615628914e-17, 0.30000000000000004]
// twoSum(.2, .1).toString() === robustSum([.2], [.1]).toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment