04.03.2013 Views

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Division (/)<br />

Structure - Math<br />

Divide one value (integer or fl oating point) by another value. Integer division discards fractional<br />

results. For example:<br />

result = 76/7<br />

will set the variable “result” to a value of 10. (The actual decimal result would be 10.857, but the<br />

decimal part is discarded, rounding is not done.) If your application requires fractional results you can<br />

use fl oating point numbers or the following solution.<br />

Use a fl oating point variable instead to get the full precision.<br />

result var fl oat<br />

result = 76.0/7.0<br />

Alternatively, when using integer variables multiply the dividend by 10, 100, 1000 etc. before dividing.<br />

The result will gain extra digits of precision but must be interpreted correctly. Using the previous<br />

example we can gain three digits of precision as follows. This is known as fi xed point division:<br />

temp = dividend * 1000 ;dividend is now 76000<br />

result = temp/7<br />

The example sets “result” to a value of 10857.<br />

High Multiplication (**)<br />

If two long variables or constants are multiplied, the result may exceed 32 bits. Normally, the multiply<br />

function will return the least signifi cant (lowest) 32 bits. The ** function will, instead, return the most<br />

signifi cant 32 bits.<br />

time = 80000 ** 80000 ; result returns high 32 bits<br />

The value of time would be equal to 0x1 which is the high 32 bits of the result 6,400,000,000.<br />

53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!