Wii VC Round-to-Zero: Difference between revisions

m
no edit summary
No edit summary
mNo edit summary
Line 10: Line 10:
</syntaxhighlight>
</syntaxhighlight>


In the above code sample, <code>y</code> and <code>sins(t)</code> are both single precision floats. However, in C, the numeric literal <code>0.58</code> is a double since it lacks a trailing <code>f</code>, as in <code>0.58f</code>. This causes the expression to evaluate to a double, which is then converted to a float before being stored in <code>y</code>. Examples such as this one arise in many places in the game's source code, and over time they result in large discrepancies between the N64 and Wii VC versions of the game. For this reason, TASes produced for one of these platforms can not generally be played back on the other without desync.
In the above code sample, <code>y</code> and <code>sins(t)</code> are both single precision floats. However, in C, the numeric literal <code>0.58</code> is a double since it lacks a trailing <code>f</code>, as in <code>0.58f</code>. This causes the expression to evaluate to a double, which is then converted to a float before being stored in <code>y</code>. Examples such as this one arise in many places in the game's source code, and over time they result in large discrepancies between the N64 and Wii VC versions of the game. For this reason, TASes produced for one of these platforms cannot generally be played back on the other without desync.


The example given above is taken from the code controlling the oscillation of the platforms at the beginning of [[Bowser in the Fire Sea]]. Using the N64's rounding mode, the <code>y</code> variable, which represents the platform's height, will repeatedly return to its original value and continue oscillating with fixed maximum height. Even though each double to single conversion produces a small amount of error, this error balances out over the course of the platform's cycle. On the Wii VC, however, the error always accumulates in the same direction (upward if the platform is below ''y'' = 0, and downward if the platform is above ''y'' = 0), and so the platform slowly drifts in the vertical direction. This is known as '''Wii VC platform drift'''.
The example given above is taken from the code controlling the oscillation of the platforms at the beginning of [[Bowser in the Fire Sea]]. Using the N64's rounding mode, the <code>y</code> variable, which represents the platform's height, will repeatedly return to its original value and continue oscillating with fixed maximum height. Even though each double to single conversion produces a small amount of error, this error balances out over the course of the platform's cycle. On the Wii VC, however, the error always accumulates in the same direction (upward if the platform is below ''y'' = 0, and downward if the platform is above ''y'' = 0), and so the platform slowly drifts in the vertical direction. This is known as '''Wii VC platform drift'''.