PCSX2 Documentation/What's clamping? And why do we need it?: Difference between revisions
PCSX2 Documentation/What's clamping? And why do we need it? (view source)
Revision as of 01:18, 9 January 2015
, 9 January 2015no edit summary
(Created page with "''Originally written by cottonvibes'' In pcsx2's advanced options dialog (if you've dared to look), you've might have noticed there's "FPU Clamp Mode" and "VU Clamp Mode" set...") |
No edit summary |
||
Line 67: | Line 67: | ||
Let me give you a quick example of something clamping can solve: | Let me give you a quick example of something clamping can solve: | ||
<nowiki> | |||
int main() { | int main() { | ||
float value = INF; | float value = INF; | ||
Line 74: | Line 74: | ||
if (value <= 1) { print("Hello World"); break; } | if (value <= 1) { print("Hello World"); break; } | ||
} while (true); | } while (true); | ||
} | }</nowiki> | ||
If the above code was ran on the ps2, it will eventually print "Hello World", because INF is treated as a regular large number, and will continue to be divided by 2 until its less than 1. | If the above code was ran on the ps2, it will eventually print "Hello World", because INF is treated as a regular large number, and will continue to be divided by 2 until its less than 1. | ||
Line 83: | Line 83: | ||
Clamping can solve this problem like this: | Clamping can solve this problem like this: | ||
<nowiki> | |||
int main() { | int main() { | ||
float value = INF; | float value = INF; | ||
Line 91: | Line 91: | ||
if (value <= 1) { print("Hello World"); break; } | if (value <= 1) { print("Hello World"); break; } | ||
} while (true); | } while (true); | ||
} | }</nowiki> | ||
The clamping will convert the INF into a normal (ordered) number. Then that normal number can be divided by 2 repetitively until its less than 1. Then it will eventually satisfy (value less or equal 1), and print "Hello World". | The clamping will convert the INF into a normal (ordered) number. Then that normal number can be divided by 2 repetitively until its less than 1. Then it will eventually satisfy (value less or equal 1), and print "Hello World". | ||
Line 109: | Line 109: | ||
In this case, we simulate the ps2's sqrt instruction by doing this | In this case, we simulate the ps2's sqrt instruction by doing this | ||
<nowiki> | |||
float ps2_sqrt(float value) { | float ps2_sqrt(float value) { | ||
value = clamp(value); // Clamp Value if NaN or Inf to an ordered/normal number | value = clamp(value); // Clamp Value if NaN or Inf to an ordered/normal number | ||
Line 115: | Line 115: | ||
value = sqrt(value); // Get sqrt of now-positive value | value = sqrt(value); // Get sqrt of now-positive value | ||
return value; | return value; | ||
} | }</nowiki> | ||
so: | so: |