Logo

RelativeError

Updated 2023-10-12 14:50:58.937000

Syntax

SELECT [westclintech].[wct].[RelativeError](
  <@TrueValue, float,>
 ,<@MeasuredValue, float,>
 ,<@NullReturnValue, float,>)

Description

Use the scalar function RelativeError to calculate the relative error between two values.

Arguments

@NullReturnValue

the value to be returned if the relative error calculation produces an illegal arithmetic operation. @NullReturnValue is an expression of type float or of a type that can be implicitly converted to float.

@TrueValue

the denominator value in the relative error calculation. @TrueValue is an expression of type float or of a type that can be implicitly converted to float.

@MeasuredValue

the numerator value in the relative error calculation. @MeasuredValue is an expression of type float or of a type that can be implicitly converted to float.

Return Type

float

Remarks

If @TrueValue = 0 and @MeasuredValue = 0 then RelativeError= 0.

If @TrueValue = NULL and @MeasuredValue = NULL then RelativeError= 0.

If @TrueValue = 0 then RelativeError = @NullReturnValue.

If @TrueValue = NULL then RelativeError= @NullReturnValue.

If @MeasuredValue = NULL then RelativeError = @NullReturnValue.

RelativeError= @MeasuredValue / @TrueValue - 1

Examples

SELECT wct.RelativeError(

                            PI(),

                            768

                            * SQRT(2

                                   - SQRT(2 + SQRT(2 + SQRT(2 + SQRT(2 + SQRT(2 + 

                                             SQRT(2 + SQRT(2 + SQRT(2 + 1))))))))

                                  ),

                            NULL

                        ) as [Relative Error];

This produces the following result.

{"columns":[{"field":"Relative Error","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Relative Error":"-6.97211024136557E-07"}]}