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

problems with large values of doubles


I am having some very basic problems with double
data type. Consider the following program --

  double d1 = 9999999999999999.1;
  double d2 = 9999999999977777.1;
  // double d1 = 9999.9999999999991;
  // double d2 = 9777.9999999777771;

  int i1 = (int) (d1-d2);

  printf( "d1 = %d, d2 = %d, i1 = %d\n", (int)d1, (int)d2, i1 );

It gives me incorrect answers with this -
% test_program
d1 = 2147483647, d2 = 2147483647, i1 = 0

But if I replace values of d1, d2 with smaller ones
(the ones in the comment), the program gives me
correct output. -
% test_program
d1 = 10000, d2 = 9778, i1 = 222

Is there any problem with doubles on Etrax? Am I
linking a wrong C library? I had asked a similar
question related to fmod() before, but didnt get
any reply.

In a similar note, why are doubles disabled in
printfs? How can I print large doubles(greater
than MAX_INT) then?

I am using Axis 2400 camera server board with 1.0.2
release of software(including cris-dist-1.7).

best wishes,
-- prabhat

Prabhat Avasare    IMEC (DESICS)          email: avasare@xxxxxxx.be
                   Kapeldreef 75            Tel: +32-16-281525
                   B3001 Leuven             Fax: +32-16-281515