Login     Register

        Contact Us     Search

XLeratorDB/financial Documentation

SQL Server relative error function


RelativeError

Updated: 18 September 2014

Use the scalar function RelativeError to calculate the relative error between two values.
Syntax
SELECT [wct].[RelativeError](
  <@TrueValue, float,>
 ,<@MeasuredValue, float,>
 ,<@NullReturnValue, float,>)
Arguments
@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.
@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.
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.
Relative Error
----------------------
-6.97211024136557E-07


Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service