final int y = x >= 0 ? x : -x;
There is a fundamental problem with Math.abs. There is no corresponding positive value to Integer. MIN_VALUE and Long. MIN_VALUE, the most negative int and long respectively. Math. abs returns those values unchanged, i.e. negative.
You can strip the sign bit to avoid that problem. Then Long. MIN_VALUE becomes 0.
This page is posted
Optional Replicator mirror
Please read the feedback from other visitors, or send your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.
Your face IP:[184.108.40.206]
You are visitor number|