/** * Tests whether the given double is equal to zero. * * @param value the value. * @return true or false. */ public static boolean isZero( double value ) { return isEqual( value, 0d ); }
/** * Rounds a number to a given number of significant decimal digits. * Note that the number will be left with *only* this number of * significant digits regardless of magnitude, e.g. 12345 to 3 digits * will be 12300, whereas 0.12345 will be 0.123. * * @param value the value to round off. * @param n the number of significant decimal digits desired. * @return a rounded off number. */ public static double roundToSignificantDigits( double value, int n ) { if ( isEqual( value, 0.0 ) ) { return 0.0; } final double d = Math.ceil( Math.log10( value < 0.0 ? -value : value ) ); final int power = n - (int) d; final double magnitude = Math.pow( 10.0, power ); final long shifted = Math.round( value * magnitude ); return shifted / magnitude; }
/** * Rounds the fractional part of a number to a given number of significant * decimal digits. Digits to the left of the decimal point will not * be rounded. For example, rounding 12345 to 3 digits will be 12345, * whereas 12.345 will be 12.3, and 0.12345 will be 0.123. * * @param value the value to round off. * @param n the number of significant fraction decimal digits desired. * @return a rounded off number. */ public static double roundFraction( double value, int n ) { if ( isEqual( value, 0.0 ) ) { return 0.0; } final double d = Math.ceil( Math.log10( value < 0.0 ? -value : value ) ); if ( d >= n ) { return (double) Math.round( value ); } return roundToSignificantDigits( value ,n ); }
/** * Evaluates whether an expression is true or false. * * @param expression the expression to evaluate. * @return True if the expression is true, false otherwise. */ public static boolean expressionIsTrue( String expression ) { final JEP parser = getJep(); parser.parseExpression( expression ); return isEqual( parser.getValue(), 1.0 ); }
if ( value != null && !MathUtils.isEqual( Double.parseDouble( String.valueOf( value ) ), 0d ) )
if ( chart.isRegression() && value != null && value instanceof Double && !MathUtils.isEqual( (Double) value, MathUtils.ZERO ) )
if ( !isEqual( denominatorValue, 0d ) )