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 
http://mindprod.com/jgloss/abs.html  
Optional Replicator mirror

J:\mindprod\jgloss\abs.html  
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.  
Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[107.22.127.78] 
 
Feedback 
You are visitor number  