Re: for loop: different results on cygwin and on linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 03, 2007 at 07:01:21PM +0200, Lemaitre Laurent-r29173 wrote:
> I am trying to build a testsuite that I want to run on different
> platforms.
> My testsuite uses the printf command and a for-loop. But depending on
> the platform
> I compile my program my code gives unexpected different results.

   The difference is expected for floating point numbers.

> which gives on windows (printf.c compiled using gcc version 3.4.4):
> o 1.000000e+000
> # 1.000000e+000
> 
> and on linux (printf.c compiled using gcc version 3.2.3):
> o 1.000000e+00
> # 1.100000e+00
> 
> Is-there any way to change the code so that I am sure I will get
> identical results on both platforms (cygwin and linux)?

   Depending on what you think is the correct result, write the for() loops
like this

   for (v=0.0;v<1.25;v+=0.5)
   ;
   for (v=1.0;v<0.95;v+=0.1)
   ;

 or like this

   for (v=0.0;v<0.75;v+=0.5)
   ;
   for (v=1.0;v<1.05;v+=0.1)
   ;

-- 
Rask Ingemann Lambertsen

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux