From: frabb AT worldaccess DOT nl Newsgroups: comp.os.msdos.djgpp Subject: Antw: Re: doubles vs. floats Date: Fri, 31 Jan 97 09:48:00 GMT Organization: World Access Lines: 51 Message-ID: References: <199701292356 DOT SAA28049 AT delorie DOT com> NNTP-Posting-Host: grn1-7.worldaccess.nl To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp DJ Delorie wrote: > No, on ALL pcs (FPU or Emulator), all float calculations are done as > "long double" (80-bit native 387 format), so both floats and doubles > get converted. > > However, many floats will get promoted to double to be passed as an > argument to a function (printf) and most math functions return double, > so using floats will result in extra conversions in those cases. I agree, that is why the following program astonishes me: ------------------------------------------------------------------- #include #include #include /* always have 1 TYPE and 2 noTYPEs: */ #define noTYPE float /* 150 ticks (40) */ #define noTYPE double /* 170 ticks (40) */ #define TYPE long double /* 195 ticks (46) */ int main(void) { int i, j; TYPE a, b, c; clock_t t; clock(); for(i = 0; i<1000; i++) for(j = 0; j<1000; j++) { a = (TYPE) 2.0; b = sqrt(a); c = a/b; if((c-b)>0.001 || (b-c)>0.001){printf("\n%f,%f,error",c,b); exit(-1);} } t = clock(); printf("%d ticks\n",t); return t; } ----------------------------------------------------- The three lines specifying TYPE as float, double or long double also contain the number of clockticks used by the program. It appears that float is faster than double is faster than long double. The program is compiled using RHIDE on a P-100, without any options. (Another nice feature of RHIDE: it shows the return value of a program, that is the reason for the "return t" line.) What worries me even more is the number between ( ), this is obtained by compiling the program with TC...