Range : port the `compare` functions from javascript and add `testCompare`

TODO: more doc and tests