return FEELFnResult.ofResult( SqrtFunction.sqrt( mean ) );
public FEELFnResult<BigDecimal> invoke(@ParameterName("list") List<?> list) { if ( list == null ) { return FEELFnResult.ofError( new InvalidParametersEvent( FEELEvent.Severity.ERROR, "list", "the list cannot be null" ) ); } int n = list.size(); BigDecimal[] numbers = new BigDecimal[n]; for ( int i = 0; i < n; i++ ) { final BigDecimal val = EvalHelper.getBigDecimalOrNull( list.get( i ) ); if ( val == null ) { return FEELFnResult.ofError( new InvalidParametersEvent( FEELEvent.Severity.ERROR, "list", "an element in the list is not suitable for the stddev" ) ); } numbers[i] = val; } BigDecimal total = BigDecimal.ZERO; for ( int i = 0; i < n; i++ ) { total = total.add( numbers[i] ); } BigDecimal mean = total.divide( BigDecimal.valueOf( n ), MathContext.DECIMAL128 ); total = BigDecimal.ZERO; for ( int i = 0; i < n; i++ ) { BigDecimal distanceSquared = numbers[i].subtract( mean ).pow( 2, MathContext.DECIMAL128 ); total = total.add( distanceSquared ); } mean = total.divide( BigDecimal.valueOf( n - 1 ), MathContext.DECIMAL128 ); return FEELFnResult.ofResult( SqrtFunction.sqrt( mean ) ); }
public FEELFnResult<BigDecimal> invoke(@ParameterName( "number" ) BigDecimal number) { if ( number == null ) { return FEELFnResult.ofError( new InvalidParametersEvent( FEELEvent.Severity.ERROR, "number", "cannot be null" ) ); } if ( number.signum() < 0 ) { return FEELFnResult.ofError( new InvalidParametersEvent( FEELEvent.Severity.ERROR, "number", "is negative" ) ); } return FEELFnResult.ofResult( sqrt( EvalHelper.getBigDecimalOrNull( number ) ) ); }