Why the inconsistency?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no inconsistency: the methods are simply designed to follow different specifications.
long round(double a)longto the argument.double floor(double a)doublevalue that is less than or equal to the argument and is equal to a mathematical integer.double ceil(double a)double rint(double a)doublevalue that is closest in value to the argument and is equal to a mathematical integerSo by design
roundrounds to alongandrintrounds to adouble. This has always been the case since JDK 1.0.Other methods were added in JDK 1.2 (e.g.
toRadians,toDegrees); others were added in 1.5 (e.g.log10,ulp,signum, etc), and yet some more were added in 1.6 (e.g.copySign,getExponent,nextUp, etc) (look for the Since: metadata in the documentation); butroundandrinthave always had each other the way they are now since the beginning.Arguably, perhaps instead of
long roundanddouble rint, it’d be more “consistent” to name themdouble roundandlong rlong, but this is argumentative. That said, if you insist on categorically calling this an “inconsistency”, then the reason may be as unsatisfying as “because it’s inevitable”.Here’s a quote from Effective Java 2nd Edition, Item 40: Design method signatures carefully:
Distantly related questions
int num = Integer.getInteger("123")throwNullPointerException?