Hi all,
I need help with a small piece of code ...
If I compile and execute the above code, the message box pops up with the (wrong) answer 0.000000000000000100000001686.
If I compile and DEBUG the above code and then run it in debug mode I get a different (!) answer (the right one): 0.100008508707700254000000000.
Am I the only one whose getting this kind of behaviour?
Cheers,
Alan.
I need help with a small piece of code ...
Code:
#COMPILE EXE #DIM ALL FUNCTION GetChiPValue(BYVAL X AS EXT, BYVAL F AS EXT) AS EXT ' ' FUNCTION PCHI2 - CALCULATES THE P-VALUE FROM ' THE CHI-SQUARE VALUE AND THE DEGREES OF FREEDOM ' The probability is calculated using series expansion 26.4.6. For the ' gamma functions 6.1.12, 6.1.8 and 6.1.1 are used. ' In: Handbook of mathematical Functions. Editors: Abramowitz M & Stegun IA, ' Dover, New York, 1972. ' Original code by Erik Christensen LOCAL D##,E##,R##,G##,H##,SL##,S##,T##,P##,C##,SK##,Q## Q = 1 IF X = 0 OR F = 0 THEN GOTO 26 D = F : E = D / 2 : R = F - INT(F / 2) * 2 G = 1 IF R > .3 THEN GOTO 20 19 E = E - 1 IF E < 1.8 THEN GOTO 22 G = G * E : GOTO 19 20 G = SQR(ATN(1) * 4) ' = PI 21 E = E - 1 IF E < .3 THEN GOTO 22 G = G * E: GOTO 21 22 H = ((X / 2) ^ (D / 2) * EXP(-X / 2)) / (X * G) SL = H * 2 * X / D : S = 0 : T = 0 : P = 1 23 D = D + 2 : P = P * X / D : S = S + P : C = ABS(S - T) IF C < 1E-16 THEN GOTO 24 T = S : GOTO 23 24 SK = (S + 1) * SL : Q = 1 - SK 25 IF Q < 1E-16 THEN Q = 1E-16 26 FUNCTION = Q END FUNCTION FUNCTION PBMAIN () AS LONG LOCAL xxx AS EXT xxx = GetChiPValue(4.605, 2) MSGBOX( FORMAT$( xxx, "0.000000000000000000000000000" ) ) END FUNCTION
If I compile and DEBUG the above code and then run it in debug mode I get a different (!) answer (the right one): 0.100008508707700254000000000.
Am I the only one whose getting this kind of behaviour?
Cheers,
Alan.
Comment