Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Numerical Recipes Official Announcements > Old Bug Reports (Obsolete Editions of NR)

Reply
 
Thread Tools Display Modes
  #1  
Old 11-11-2004, 02:54 PM
Saul Teukolsky Saul Teukolsky is offline
Numerical Recipes Author
 
Join Date: Dec 2001
Posts: 183
Bug in kstwo.cpp

The lines

if ((d1=data1[j1]) <= (d2=data2[j2])) fn1=j1++/en1;
if (d2 <= d1) fn2=j2++/en2;

should be

if ((d1=data1[j1]) <= (d2=data2[j2])) fn1=++j1/en1;
if (d2 <= d1) fn2=++j2/en2;

(i.e., change j1++ to ++j1 and similarly for j2).

This bug skips the contribution from the first data point (if any),
so it is negligible for reasonably large data sets. But you would
definitely notice it on small test cases.

This bug is present only in the C++ code, and only in v2.10 and
v2.11.

Thanks to Heng Sun for reporting this.
Reply With Quote
  #2  
Old 10-30-2009, 11:06 AM
maxhec maxhec is offline
Registered User
 
Join Date: Oct 2009
Posts: 1
Fix is wrong

Because we start with j=1, the correct code is j++ instead of ++j. If we start in j=0, then we use ++j.

This is due to the unit-offset of arrays' head pointer discussed in page 18 of the version 2 of the book.

I confirmed my results with Matlab and other KS-Test code.
Reply With Quote
  #3  
Old 10-30-2009, 01:08 PM
Saul Teukolsky Saul Teukolsky is offline
Numerical Recipes Author
 
Join Date: Dec 2001
Posts: 183
Hi,

You are referring to the C routine, kstwo.c, which is indeed correct. This fix refers to the C++ version, kstwo.cpp, where arrays are zero-based. The bug has been fixed in the 3rd edition.

Saul Teukolsky
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:10 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.