Atmel CAVR-4 Manual De Usuario

Descargar
Página de 323
CAVR-4
Part1. Using the compiler
Efficient coding for embedded applications
127
For details about representation of supported data types, pointers, and structures types, 
see the chapteData representation.
Floating-point types
Using floating-point types on a microprocessor without a math coprocessor is very 
inefficient, both in terms of code size and execution speed. The AVR IAR C/C++ 
Compiler supports two floating-point formats—32 and 64 bits. The 32-bit floating-point 
type 
float
 is more efficient in terms of code size and execution speed. However, the 
64-bit format 
double
 supports higher precision and larger numbers.
In the AVR IAR C/C++ Compiler, the floating-point type 
float
 always uses the 32-bit 
format. The format used by the 
double
 floating-point type depends on the compiler 
option 
--64bit_doubles
 (Use 64-bit doubles).
Unless the application requires the extra precision that 64-bit floating-point numbers 
give, we recommend using 32-bit floats instead. Also consider replacing code using 
floating-point operations with code using integers because these are more efficient.
Note that a floating-point constant in the source code is treated as being of the type 
double
. This can cause innocent-looking expressions to be evaluated in double 
precision. In the example below 
a
 is converted from a 
float
 to a 
double
1
 is added 
and the result is converted back to a 
float
:
float test(float a)
{
   return a+1.0;
}
To treat a floating-point constant as a 
float
 rather than as a 
double
, add an 
f
 to it, for 
example:
float test(float a)
{
   return a+1.0f;
}