I l @ ve RuBoard |
A variable of type double has about twice the precision of a normal float variable. Most people assume that double-precision arithmetic takes longer than single-precision. This is not always the case. Let's assume we have one of the older compilers that does everything in double . For the equation: float answer, number1, number2; answer = number1 + number2; C++ must perform the following steps:
If the variables were of type double , C++ would have to perform only the following steps:
As you can see, the second form is a lot simpler, requiring three fewer conversions. In some cases, converting a program from single precision to double precision makes it run faster .
Many computers, including the PC and Sun/3 series machines, have a special chip called a floating-point processor that does all the floating-point arithmetic. Actual tests using the Motorola 68881 floating-point chip (which is used in the Sun/3) and floating point on the PC show that single precision and double precision run at the same speed. |
I l @ ve RuBoard |