|
|
Fractional numbers representation using the 16.16 format (FIXED variables)
Author: AM Reference Number: AA-15441 Views: 6721 Created: 22-05-2018 15:07 Last Updated: 28-04-2021 17:49 |
0 Rating/ Voters
|
|
In TML, fractional numbers (usually stored in 32 bits fixed variables) are represented (in hex) using the "16.16" format. According to this format, to get the hex value of a fractional number, the first step is to multiply the fractional number with 65536. The result will be rounded or truncated and cast to a 32 bits signed integer value, that can be converted to hexadecimal.
Examples:
+4.6 = 4.6 (FLOAT) * 65536 = 301465.6
The result can be rounded or truncated to an integer number. Assuming that it was truncated to 301465 and cast to a 32 bits signed integer (INTEGER32), the hexadecimal value is:
0x00049999.
-3.3 IU = -3.3 (FLOAT) * 65536 = -216268.8 After the result is truncated to -216268 and cast to a 32 bits signed integer (INTEGER32), the hexadecimal value is: 0xFFFCB334. For more details regarding the Fixed Point Maths, please follow the link below.
-
http://www.hugi.scene.org/online/coding/hugi%2015%20-%20cmtadfix.htm
|
|
|