16 bit fixed point precision with basic math, logarithms, trigonometric functions, and exponentiation. Available in binary and decimal resolutions. Re-entrant, thread safe, fully interruptible.
Fork of s16math by
DESCRIPTION.txt@0:306417d5f0a0, 2014-09-02 (annotated)
- Committer:
- bbatten
- Date:
- Tue Sep 02 05:17:00 2014 +0000
- Revision:
- 0:306417d5f0a0
Committed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bbatten | 0:306417d5f0a0 | 1 | Description |
bbatten | 0:306417d5f0a0 | 2 | |
bbatten | 0:306417d5f0a0 | 3 | s16math is a compact library of 16 bit fixed point[1] math functions |
bbatten | 0:306417d5f0a0 | 4 | for microcontroller - MCU - environments without fixed or floating |
bbatten | 0:306417d5f0a0 | 5 | point hardware. |
bbatten | 0:306417d5f0a0 | 6 | |
bbatten | 0:306417d5f0a0 | 7 | The development platform is Debian Linux running on an X86 machine |
bbatten | 0:306417d5f0a0 | 8 | using basic GNU/Linux cross compilation development tools. The package |
bbatten | 0:306417d5f0a0 | 9 | provides tools to build deployable object versions of the library for a |
bbatten | 0:306417d5f0a0 | 10 | variety of targets. |
bbatten | 0:306417d5f0a0 | 11 | |
bbatten | 0:306417d5f0a0 | 12 | Capabilities are focused on processor and memory constrained embedded |
bbatten | 0:306417d5f0a0 | 13 | applications such as resource limited battery powered sensors and |
bbatten | 0:306417d5f0a0 | 14 | wearable medical devices. MCUs such as the HC08, HC11, 8051, Z80, and |
bbatten | 0:306417d5f0a0 | 15 | ARM machines operating in 16-bit mode are supported, maximizing use of |
bbatten | 0:306417d5f0a0 | 16 | limited MCU registers while minimizing the software overhead of 32 and |
bbatten | 0:306417d5f0a0 | 17 | 64 bit operations. |
bbatten | 0:306417d5f0a0 | 18 | |
bbatten | 0:306417d5f0a0 | 19 | The trigonometric and math functions make the library well suited for |
bbatten | 0:306417d5f0a0 | 20 | software defined radio - SDR - signal management requirements. |
bbatten | 0:306417d5f0a0 | 21 | |
bbatten | 0:306417d5f0a0 | 22 | The virtual fixed point format provides 65,536 discrete signed values |
bbatten | 0:306417d5f0a0 | 23 | between -32768 and +32767 inclusive, with an equivalent decimal fixed |
bbatten | 0:306417d5f0a0 | 24 | point range of -327.68 through +327.67. If binary resolution is used, |
bbatten | 0:306417d5f0a0 | 25 | the range is -256.000 through +255.127 (see text on dot (".") notation |
bbatten | 0:306417d5f0a0 | 26 | below). If your application requires numbers outside this range, then |
bbatten | 0:306417d5f0a0 | 27 | this masterpiece - alas - is not for you. |
bbatten | 0:306417d5f0a0 | 28 | |
bbatten | 0:306417d5f0a0 | 29 | Machine level integers are treated as virtual fixed point[1] numbers |
bbatten | 0:306417d5f0a0 | 30 | with sign, integer, and fractional parts specified in either decimal or |
bbatten | 0:306417d5f0a0 | 31 | Qm.n[2] format. The most significant bit is the sign bit, leaving 15 |
bbatten | 0:306417d5f0a0 | 32 | bits to be allocated between the integer and the fractional components. |
bbatten | 0:306417d5f0a0 | 33 | |
bbatten | 0:306417d5f0a0 | 34 | Numbers are a ratio of two integers: the numerator is kept in storage, |
bbatten | 0:306417d5f0a0 | 35 | the denominator is implied and is equal to either a power of 10 or a |
bbatten | 0:306417d5f0a0 | 36 | power of 2. The integer and fractional parts are given by the integer |
bbatten | 0:306417d5f0a0 | 37 | division of the whole number by the denominator: the integer portion is |
bbatten | 0:306417d5f0a0 | 38 | the quotient and the fractional part is the remainder. A dot (".") |
bbatten | 0:306417d5f0a0 | 39 | notation is used to separate the integer and fractional portions of the |
bbatten | 0:306417d5f0a0 | 40 | number when it is displayed. |
bbatten | 0:306417d5f0a0 | 41 | |
bbatten | 0:306417d5f0a0 | 42 | If exact fractional powers of ten are desired, then a decimal format |
bbatten | 0:306417d5f0a0 | 43 | should be used[1]. This provides more range than the binary format, but |
bbatten | 0:306417d5f0a0 | 44 | less resolution. |
bbatten | 0:306417d5f0a0 | 45 | |
bbatten | 0:306417d5f0a0 | 46 | So where the denominator is 100, the number 30 is treated as 30/100, or |
bbatten | 0:306417d5f0a0 | 47 | 2.30; 250 is treated as 250/100, or 2.50. In this library, denominators |
bbatten | 0:306417d5f0a0 | 48 | of 10, 100, and 1000 are used. |
bbatten | 0:306417d5f0a0 | 49 | |
bbatten | 0:306417d5f0a0 | 50 | In Qm.n format 'm' is the number of bits in the integer portion of the |
bbatten | 0:306417d5f0a0 | 51 | number, and 'n' is the number of bits in the fractional part. The |
bbatten | 0:306417d5f0a0 | 52 | denominator is a constant equal to 2^n[2]. |
bbatten | 0:306417d5f0a0 | 53 | |
bbatten | 0:306417d5f0a0 | 54 | So where n is 6, 2^n is 64, and the number 30 is treated as 30/64 |
bbatten | 0:306417d5f0a0 | 55 | (0.30); 250 is treated as 250/64, or 3 58/64 (3.58). Where n is 7, 2^n |
bbatten | 0:306417d5f0a0 | 56 | is 128, and the number 30 is treated as 30/128 (0.030); 250 is treated |
bbatten | 0:306417d5f0a0 | 57 | as 250/128, or 1 122/128 (1.122) etc. In this library, Q11.4, Q8.7, and |
bbatten | 0:306417d5f0a0 | 58 | Q6.9 formats are used. |
bbatten | 0:306417d5f0a0 | 59 | |
bbatten | 0:306417d5f0a0 | 60 | The advantage of the Qm.n format is that the rounding operations needed |
bbatten | 0:306417d5f0a0 | 61 | to preserve precision may be done with bit shifts instead of division |
bbatten | 0:306417d5f0a0 | 62 | and multiplication, which can significantly boost performance and save |
bbatten | 0:306417d5f0a0 | 63 | code overhead in machines without integer multiplication and division |
bbatten | 0:306417d5f0a0 | 64 | hardware. |
bbatten | 0:306417d5f0a0 | 65 | |
bbatten | 0:306417d5f0a0 | 66 | Installation |
bbatten | 0:306417d5f0a0 | 67 | |
bbatten | 0:306417d5f0a0 | 68 | The download file unpacks into a directory named "eval". So change to |
bbatten | 0:306417d5f0a0 | 69 | the directory where you wish to install it, download the zip file and |
bbatten | 0:306417d5f0a0 | 70 | unzip it. |
bbatten | 0:306417d5f0a0 | 71 | |
bbatten | 0:306417d5f0a0 | 72 | You should now see the subdirectory "eval". Go there. Peruse README. |
bbatten | 0:306417d5f0a0 | 73 | Alternately, point your browser to eval/html and peruse README.html. |
bbatten | 0:306417d5f0a0 | 74 | Proceed thence. |
bbatten | 0:306417d5f0a0 | 75 | |
bbatten | 0:306417d5f0a0 | 76 | [1] Fixed-point arithmetic |
bbatten | 0:306417d5f0a0 | 77 | http://en.wikipedia.org/wiki/Fixed-point_arithmetic |
bbatten | 0:306417d5f0a0 | 78 | |
bbatten | 0:306417d5f0a0 | 79 | [2] Q (number format) |
bbatten | 0:306417d5f0a0 | 80 | http://en.wikipedia.org/wiki/Q_%28number_format%29 |
bbatten | 0:306417d5f0a0 | 81 | # vi:set expandtab: |