|8Ch||FN$STD||calculate standard deviation of a list|
|Input||Pointer on stack to floating-point numbers.
Word on stack specifying the number of floats.
|Output||Floating-point result on the stack.|
Returns the sample standard deviation of the floating-point numbers pointed to by the parameter on the run-time stack at RTA_SP. The number of floats is passed as a word on the stack at RTA_SP+2.
The result is pushed onto the run-time stack, leaving the input parameters intact.
The sample standard deviation differs from the population standard deviation in assuming that the data set provided constitutes a sample of the data rather than the complete population.
The sample standard deviation has the formula:
N std(Xi) = sqrt((Sigma (Xi-Xm)**2)/(N-1)) = sqrt(var(Xi)) i=1
where Xm is the arithmetic mean.
If the complete data set IS provided, the population standard deviation can be calculated by multiplying the sample standard deviation by sqrt((N-1)/N).
The following code calculates the sample standard deviation of COUNT
floats at TABFLOATS and leaves the result on the stack.
LDD RTA_SP: ;CURRENT RUNTIME STACK POINTER SUBD #4 ;PREPARE TO PUSH 2 WORDS XGDX CPX ALA_FREE ;ENOUGH MEMORY FREE? BCS ERROR1 ;NO STX RTA_SP: ;NEW STACK POINTER LDD #TABFLOATS ;POINT TO TABLE OF FLOATS STD 0,X ;POINTER ON STACK LDD COUNT ;COUNT OF FLOATS AT TABFLOATS STD 2,X ;COUNT ON STACK OS FN$STD ;STD ON STACK BCS ERROR2 RTS
|Errors|| 253 - exponent overflow
249 - stack overflow