3D Graphics with OpenGL ES and M3G- P42:Mobile phones are the new vehicle for bringing interactive graphics technologies to consumers. Graphics that in the 1980s was only seen in industrial flight simulators and at the turn of the millennium in desktop PCs and game consoles is now in the hands of billions of people. This book is about the technology underpinnings of mobile threedimensional graphics, the newest and most rapidly advancing area of computer graphics. | 394 FIXED-POINT MATHEMATICS APPENDIX A does not require this large a range as only magnitudes up to 232 need to be representable and for colors even 210 is enough. The precision of these fixed-point numbers is fixed 1 65536 whereas the precision of floats depends on the magnitude of the values. Values close to zero have a very high accuracy two consecutive floats at around have a precision of 1 16777216 floats at around have roughly the same precision as fixed-point numbers while larger numbers become more inaccurate two consecutive floats around 17 million are further than units apart . OpenGL requires only accuracy of one part in 105 which is a little under 17 bits single-precision floats have 24 bits of accuracy. Below are C macros for converting from float to fixed and vice versa define float_to_fixed a int a 1 16 define fixed_to_float a float a 1 16 These are quick-and-dirty versions of conversion. float_to_fixed can overflow if the magnitude of the float value is too great or underflow if it is too small. fixed_to_float can be made slightly more accurate by rounding. For example asymmetric arithmetic rounding works by adding to the number before truncating it to an integer . int floor a . Finally note that some of these conversions are expensive on some processors and thus should not be used in performance-critical code such as inner loops. Here are some fixed-point numbers expressed in hexadecimal and the corresponding decimal numbers 0x 0001 0000 0x 0002 0000 0x 0010 0000 0x 0000 8000 0x 0000 4000 0x 0000 2000 0x 0000 0001 65536 0x ffff ffff 65536 0x fffe 0000 Depending on the situation it may make sense to move the decimal point to some other location although is a good general choice. For example if you are only interested in numbers between zero and one but excluding one you should move the decimal point all the way to the left if you use 32 bits denote that with .