53,602
edits
m (→Calculation: It's ((y - y0)/m) that was supposed to range from 1 to 100, not (y - y0).) |
|||
Line 113: | Line 113: | ||
<math display="block">y = (256 \cdot \operatorname{rrc}(IV_1) + \operatorname{rrc}(IV_2)) \oplus \operatorname{rrc}(ID)</math> | <math display="block">y = (256 \cdot \operatorname{rrc}(IV_1) + \operatorname{rrc}(IV_2)) \oplus \operatorname{rrc}(ID)</math> | ||
As a special case, if ''y'' < 10, then the Magikarp's length is equal to <math display="inline">190 + y</math>. Otherwise, the value ''y'' is used to find the corresponding values of ''x<sub>0</sub>'', ''y<sub>0</sub>'', and ''m'' in the following table, which defines a piecewise linear approximation of the inverse of a {{wp|normal cumulative distribution function}} with mean 800 and standard deviation 179. The column selected was intended to be the first column where ''y'' is less than the ''y<sub>0</sub>'' value of that same column. Due to a programming error, only the high bytes of ''y'' and ''y<sub>0</sub>'' are compared; this causes values to be looked up incorrectly from the table (including rendering the first and last columns inaccessible). | As a special case, if ''y'' < 10, then the Magikarp's length is equal to <math display="inline">190 + y</math>. Otherwise, the value ''y'' is used to find the corresponding values of ''x<sub>0</sub>'', ''y<sub>0</sub>'', and ''m'' in the following table, which defines a piecewise linear approximation of the inverse of a {{wp|normal cumulative distribution function}} with mean 800 and standard deviation 179. Due to an off-by-one error, the values of ''x<sub>0</sub>'' are calculated as 2 plus the zero-based index of the column (giving a mean of 800), rather than 3 plus the zero-based index of the column (giving a mean of 900). The column selected was intended to be the first column where ''y'' is less than the ''y<sub>0</sub>'' value of that same column. Due to a programming error, only the high bytes of ''y'' and ''y<sub>0</sub>'' are compared; this causes values to be looked up incorrectly from the table (including rendering the first and last columns inaccessible). | ||
{| class="roundtable" style="text-align:center; background:#{{johto color}}; border:3px solid #{{johto color dark}}; margin:auto" | {| class="roundtable" style="text-align:center; background:#{{johto color}}; border:3px solid #{{johto color dark}}; margin:auto" | ||
Line 129: | Line 129: | ||
|} | |} | ||
If one of the entries in the table matches, the final length of the Magikarp in millimeters is then calculated as follows. Due to a programming error, the function does not output <math display="inline">100 \cdot x_0 + \left\lfloor \frac{y - y_0}{m} \right\rfloor</math> as intended. The division routine expects the dividend to be an unsigned 16-bit value, but the subtraction always results in a negative value because ''y'' is always less than ''y<sub>0</sub>''. Additionally, only the low byte of the quotient is read, as the quotient was intended to only range from 1 to 100. These result in the sizes not correctly following a normal distribution as intended. | If one of the entries in the table matches, the final length of the Magikarp in millimeters is then calculated as follows. Due to a programming error, the function does not output <math display="inline">100 \cdot x_0 + \left\lfloor \frac{y - y_0}{m} \right\rfloor</math> as intended. The division routine expects the dividend to be an unsigned 16-bit value, but the subtraction always results in a negative value because ''y'' is always less than ''y<sub>0</sub>''. Additionally, only the low byte of the quotient is read, as the quotient was intended to only range from -1 to -100. These result in the sizes not correctly following a normal distribution as intended. | ||
<math display="block">\textit{Size} = 100 \cdot x_0 + \left( \left\lfloor \frac{65536 + y - y_0}{m} \right\rfloor \mathrm{mod}\ 256 \right)</math> | <math display="block">\textit{Size} = 100 \cdot x_0 + \left( \left\lfloor \frac{65536 + y - y_0}{m} \right\rfloor \mathrm{mod}\ 256 \right)</math> |