ref: 951c9b66f40592d26fc9cd9f97b05af3a7cb711e
dir: /doc/asm/expr_fix.htm/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>xAsm Fixed-point expression</title> <link rel="stylesheet" type="text/css" href="../style.css"> </head> <body> <h1>Fixed‐point Expressions</h1> <p>Fixed point constants are basically normal 32-bit constants where the upper 16 bits are used for the integer part and the lower 16 bits are used for the fraction (65536ths). This means that you can use them in normal integer expression and indeed some integer operators like plus and minus don't care whether the operands are integer or fixed-point. You can easily convert a fixed-point number to an integer by shifting it right 16 bits. It follows that you can convert an integer to a fixed-point number by shifting it left.</p> <p>Some things are different for fixed-point math though. Which is why you have the following functions to use:</p> <table> <thead> <tr> <th scope="col">Name</th> <th scope="col">Operation</th> </tr> </thead> <tr> <td>DIV(x,y)</td> <td>x/y</td> </tr> <tr> <td>MUL(x,y)</td> <td>x*y</td> </tr> <tr> <td>SIN(x)</td> <td>sin(x)</td> </tr> <tr> <td>COS(x)</td> <td>cos(x)</td> </tr> <tr> <td>TAN(x)</td> <td>tan(x)</td> </tr> <tr> <td>ASIN(x)</td> <td>sin<SUP>-1</SUP>(x)</td> </tr> <tr> <td>ACOS(x)</td> <td>cos<SUP>-1</SUP>(x)</td> </tr> <tr> <td>ATAN(x)</td> <td>tan<SUP>-1</SUP>(x)</td> </tr> <tr> <td>ATAN2(x,y)</td> <td>(x,y) angle</td> </tr> </table> <p>These functions are extremely useful for automatic generation of various tables. A circle has 65536.0 degrees. Sine values are between [-1.0;1.0]</p> <pre>; -- ; -- Generate a 256 byte sine table with values between 0 and 128 ; -- ANGLE SET 0.0 REPT 256 DB (MUL(64.0,SIN(ANGLE))+64.0)>>16 ANGLE SET ANGLE+256.0 ENDR</pre> <h1>See also:</h1> <ul> <li><a href="symbols.htm">Symbols</a> <li><a href="expr_int.htm">Integer and Boolean expressions</a> <li><a href="expr_str.htm">String expressions, functions and formatting</a> <li><a href="miscfunc.htm">Other functions</a> </ul> <hr> <p>Last updated 21 June 1997 by <a href="mailto:[email protected]">Carsten Sorensen</a></p> </body> </html>