Opened 17 years ago

Closed 17 years ago

#64 closed defect (fixed)

error due to integer division in mean example

Reported by: Stephen Siegel Owned by:
Priority: major Milestone:
Component: examples Version: 1.0
Keywords: mean, division, integer Cc:

Description

The impl version of the mean example was getting the wrong answer. The bug is due to the following:

  while (i < N + 1) {
    j = ( (i-1) / i ) *j + a[i-1]/i;
    i = i + 1;
  }

The division (i-1)/i is integer division when what you want is real division. You need to do something like ((i-1)*1.0)/i. MiniMP caught the bug, which was kind of cool.

By the way, can some please change the name of variable j to something else. j is usually used for an integer variable. This is a real variable.

Change History (1)

comment:1 by Stephen Siegel, 17 years ago

Resolution: fixed
Status: newclosed

I put in the 1.0 as suggested, and the test passed.

Note: See TracTickets for help on using tickets.