Libfixmath
Encyclopedia
libfixmath is a platform-independent fixed point
Fixed-point arithmetic
In computing, a fixed-point number representation is a real data type for a number that has a fixed number of digits after the radix point...

 maths library aimed at developers wanting to perform fast non-integer maths on platforms lacking a FPU
Floating point unit
A floating-point unit is a part of a computer system specially designed to carry out operations on floating point numbers. Typical operations are addition, subtraction, multiplication, division, and square root...

. It offers developers a similar interface to the standard math.h
Math.h
C mathematical operations are a group of functions in the standard library of the C programming language implementing basic mathematical functions. Most of the functions involve the use of floating point numbers. Different C standards provide different albeit backwards-compatible, sets of functions...

 functions for use on Q16.16
Q (number format)
Q is a fixed point number format where the number of fractional bits is specified. For example, a Q15 number has 15 fractional bits; a Q1.14 number has 1 integer bit and 14 fractional bits...

 fixed point
Fixed-point arithmetic
In computing, a fixed-point number representation is a real data type for a number that has a fixed number of digits after the radix point...

 numbers.
libfixmath has no external dependencies other than stdint.h and a compiler which supports 64-bit
64-bit
64-bit is a word size that defines certain classes of computer architecture, buses, memory and CPUs, and by extension the software that runs on them. 64-bit CPUs have existed in supercomputers since the 1970s and in RISC-based workstations and servers since the early 1990s...

 integer arithmetic (such as GCC
GNU Compiler Collection
The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain...

).
Work is underway to remove the requirement for a 64-bit
64-bit
64-bit is a word size that defines certain classes of computer architecture, buses, memory and CPUs, and by extension the software that runs on them. 64-bit CPUs have existed in supercomputers since the 1970s and in RISC-based workstations and servers since the early 1990s...

 capable compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

 as many compilers for microcontrollers
Microcontroller
A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small amount of RAM...

 and DSPs
Digital signal processor
A digital signal processor is a specialized microprocessor with an architecture optimized for the fast operational needs of digital signal processing.-Typical characteristics:...

 do not support 64-bit
64-bit
64-bit is a word size that defines certain classes of computer architecture, buses, memory and CPUs, and by extension the software that runs on them. 64-bit CPUs have existed in supercomputers since the 1970s and in RISC-based workstations and servers since the early 1990s...

 arithmetic.

History

libfixmath was originally developed by Ben Brewer (aka flatmush) and first released publicly as part of the Dingoo SDK. It has since been used to implement a software 3d graphics library called FGL.

Q16.16 Functions

Name Description
fix16_acos inverse cosine
fix16_asin inverse sine
fix16_atan one-parameter inverse tangent
fix16_atan2 two-parameter inverse tangent
Atan2
In trigonometry, the two-argument function atan2 is a variation of the arctangent function. For any real arguments and not both equal to zero, is the angle in radians between the positive -axis of a plane and the point given by the coordinates on it...

fix16_cos cosine
fix16_exp exponential function
Exponential function
In mathematics, the exponential function is the function ex, where e is the number such that the function ex is its own derivative. The exponential function is used to model a relationship in which a constant change in the independent variable gives the same proportional change In mathematics,...

fix16_sin sine
Sine
In mathematics, the sine function is a function of an angle. In a right triangle, sine gives the ratio of the length of the side opposite to an angle to the length of the hypotenuse.Sine is usually listed first amongst the trigonometric functions....

fix16_sqrt square root
Square root
In mathematics, a square root of a number x is a number r such that r2 = x, or, in other words, a number r whose square is x...

fix16_tan tangent
fix16_mul multiplication
Multiplication
Multiplication is the mathematical operation of scaling one number by another. It is one of the four basic operations in elementary arithmetic ....

fix16_div division
Division (mathematics)
right|thumb|200px|20 \div 4=5In mathematics, especially in elementary arithmetic, division is an arithmetic operation.Specifically, if c times b equals a, written:c \times b = a\,...

fix16_sadd saturated
Saturation arithmetic
Saturation arithmetic is a version of arithmetic in which all operations such as addition and multiplication are limited to a fixed range between a minimum and maximum value. If the result of an operation is greater than the maximum it is set to the maximum, while if it is below the minimum it is...

 addition
Addition
Addition is a mathematical operation that represents combining collections of objects together into a larger collection. It is signified by the plus sign . For example, in the picture on the right, there are 3 + 2 apples—meaning three apples and two other apples—which is the same as five apples....

fix16_smul saturated
Saturation arithmetic
Saturation arithmetic is a version of arithmetic in which all operations such as addition and multiplication are limited to a fixed range between a minimum and maximum value. If the result of an operation is greater than the maximum it is set to the maximum, while if it is below the minimum it is...

 multiplication
Multiplication
Multiplication is the mathematical operation of scaling one number by another. It is one of the four basic operations in elementary arithmetic ....

fix16_sdiv saturated
Saturation arithmetic
Saturation arithmetic is a version of arithmetic in which all operations such as addition and multiplication are limited to a fixed range between a minimum and maximum value. If the result of an operation is greater than the maximum it is set to the maximum, while if it is below the minimum it is...

 division
Division (mathematics)
right|thumb|200px|20 \div 4=5In mathematics, especially in elementary arithmetic, division is an arithmetic operation.Specifically, if c times b equals a, written:c \times b = a\,...


Other Functions

Name Description
fix16_to_dbl Convert Q16.16
Q (number format)
Q is a fixed point number format where the number of fractional bits is specified. For example, a Q15 number has 15 fractional bits; a Q1.14 number has 1 integer bit and 14 fractional bits...

 to a double
Double precision
In computing, double precision is a computer number format that occupies two adjacent storage locations in computer memory. A double-precision number, sometimes simply called a double, may be defined to be an integer, fixed point, or floating point .Modern computers with 32-bit storage locations...

fix16_to_float Convert Q16.16
Q (number format)
Q is a fixed point number format where the number of fractional bits is specified. For example, a Q15 number has 15 fractional bits; a Q1.14 number has 1 integer bit and 14 fractional bits...

 to a float
fix16_to_int Convert Q16.16
Q (number format)
Q is a fixed point number format where the number of fractional bits is specified. For example, a Q15 number has 15 fractional bits; a Q1.14 number has 1 integer bit and 14 fractional bits...

 to an integer
Integer (computer science)
In computer science, an integer is a datum of integral data type, a data type which represents some finite subset of the mathematical integers. Integral data types may be of different sizes and may or may not be allowed to contain negative values....

fix16_from_dbl Convert double
Double precision
In computing, double precision is a computer number format that occupies two adjacent storage locations in computer memory. A double-precision number, sometimes simply called a double, may be defined to be an integer, fixed point, or floating point .Modern computers with 32-bit storage locations...

 to a Q16.16
Q (number format)
Q is a fixed point number format where the number of fractional bits is specified. For example, a Q15 number has 15 fractional bits; a Q1.14 number has 1 integer bit and 14 fractional bits...

fix16_from_float Convert float to a Q16.16
Q (number format)
Q is a fixed point number format where the number of fractional bits is specified. For example, a Q15 number has 15 fractional bits; a Q1.14 number has 1 integer bit and 14 fractional bits...

fix16_from_int Convert integer
Integer (computer science)
In computer science, an integer is a datum of integral data type, a data type which represents some finite subset of the mathematical integers. Integral data types may be of different sizes and may or may not be allowed to contain negative values....

 to a Q16.16
Q (number format)
Q is a fixed point number format where the number of fractional bits is specified. For example, a Q15 number has 15 fractional bits; a Q1.14 number has 1 integer bit and 14 fractional bits...


Performance

For the most intensive function (atan2
Atan2
In trigonometry, the two-argument function atan2 is a variation of the arctangent function. For any real arguments and not both equal to zero, is the angle in radians between the positive -axis of a plane and the point given by the coordinates on it...

) benchmark results show the following results:
Name Time Compared to Float
ARM Cortex M0
ARM architecture
ARM is a 32-bit reduced instruction set computer instruction set architecture developed by ARM Holdings. It was named the Advanced RISC Machine, and before that, the Acorn RISC Machine. The ARM architecture is the most widely used 32-bit ISA in numbers produced...

 
26.3%
Marvell
Marvell
-People:* Andrew Marvell, 17th-century English metaphysical poet* Marvell Wynne , American soccer player* Marvell Wynne , American baseball player-Businesses:* Marvell Technology Group, U.S. semiconductor company...

 PXA270
XScale
The XScale, a microprocessor core, is Intel's and Marvell's implementation of the ARMv5 architecture, and consists of several distinct families: IXP, IXC, IOP, PXA and CE . Intel sold the PXA family to Marvell Technology Group in June 2006....

 (ARM
ARM architecture
ARM is a 32-bit reduced instruction set computer instruction set architecture developed by ARM Holdings. It was named the Advanced RISC Machine, and before that, the Acorn RISC Machine. The ARM architecture is the most widely used 32-bit ISA in numbers produced...

) @ 312MHz
58.45%
Intel T5500  120%
Intel Atom N280
Intel Atom
Intel Atom is the brand name for a line of ultra-low-voltage x86 and x86-64 CPUs from Intel, designed in 45 nm CMOS and used mainly in netbooks, nettops, embedded application ranging from health care to advanced robotics and Mobile Internet devices...

 
141%

Note: These results were calculated using fixtest with caching optimizations turned off.

Licensing

libfixmath is released under the GNU LGPL
GNU Lesser General Public License
The GNU Lesser General Public License or LGPL is a free software license published by the Free Software Foundation . It was designed as a compromise between the strong-copyleft GNU General Public License or GPL and permissive licenses such as the BSD licenses and the MIT License...

, a permissive free software licence
Permissive free software licence
A permissive free software licence is a class of free software licence with minimal requirements about how the software can be redistributed. This is in contrast to copyleft licences, which have reciprocity / share-alike requirements. Both sets of free software licences offer the same freedoms in...

, and is free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK