Looks like it is a precision problem.
ithelp
Nearly a Posting Maven
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
This is actually one of the most insidious problems people learning C/C++ get.
The problem is one of type.
1/2 is integer
1/2.0 is floating point
So, for example, when you go to calculate the PDF you say
pdf=((1/2)+INV_SQRT_2PI * ...
That one-half there is aninteger expression, which gets promoted to double after it is evaluated. Hence, 1 idiv 2 is 0, promoted to double is 0.0, + INV_SQRT_2PI etc..
All the places where you have something like /2 check to make sure your numerator is a doublebefore division occurs. If it isn't, change your denominator to a double (say, /2.0 ).
Hope this helps.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
All the places where you have something like /2 check to make sure your numerator is a doublebefore division occurs. If it isn't, change your denominator to a double (say, /2.0 ).
Or, more generally, make sure at least one of the values being divided is a floating point value.
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943