Mulscale: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
fix my example.
Fox (talk | contribs)
Wow, much complicated
Line 1: Line 1:
'''mulscale''' ''<res>'' <eax> <edx> <ecx>
'''mulscale''' <Result> <Value 1> <Value 2> <Value 3>


The formula is<br/>
Equals the following series of commands:
res=(eax*edx)>>ecx


The intermediate value is computed using 64 bits to prevent overflow and the result is 32 bits wide.
set <Result> <Value 1>
This is a math function which is implemented in assembler programing language because it makes the calculation faster.
mul <Result> <Value 2>
shiftr <Result> <Value 3>


The primary use of this function is in calculations involving scaled integers, that is, integers that have a binary point somewhere by convention. For example, the trigonometric functions [[Sin]] and [[Cos]] use a scaling of 1:16384, corresponding to a 14 bit shift. So, if you wanted to multiply some length (say, ''dx'') by a cosine value (say, ''cosang''), you could write
The main difference is that the calculation uses 64 bits to prevent overflow, while using gamevars for intermediate values would limit it to 31 bits.
 
  '''mulscale''' ''dx'' ''dx'' ''cosang'' 14


One example of where this limitation takes places is with rotatesprite scaling, where 320*65536 scaled with [[statusbarscale]] is dangerously close to 31 bits.


[[Category:EDuke32 specific commands]]
[[Category:EDuke32 specific commands]]
[[Category:Gamevar manipulation]]
[[Category:Gamevar manipulation]]

Revision as of 07:56, 10 November 2019

mulscale <Result> <Value 1> <Value 2> <Value 3>

Equals the following series of commands:

set <Result> <Value 1>
mul <Result> <Value 2>
shiftr <Result> <Value 3>

The main difference is that the calculation uses 64 bits to prevent overflow, while using gamevars for intermediate values would limit it to 31 bits.

One example of where this limitation takes places is with rotatesprite scaling, where 320*65536 scaled with statusbarscale is dangerously close to 31 bits.