java - Is performance of "Math.abs()" better than expression with "if"? -


i have expression:

double getabs(double value){ return value> 0 ? value: value== 0 ? null : -value; } 

or better:

 double getabs(double value){ return math.abs(value); } 

i understand there differences nan. method math.abs(double) - have unboxing. in case performance better?

the "performance" in code jvm need unbox double double.

math.abs(double) uses ternary if statement follows:

public static double abs(double a) {     return (a <= 0.0d) ? 0.0d - : a; } 

so, if statement no performance worry @ all.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -