[Top][All Lists]

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

asserting the equality of double values

From: Kamaraju S Kusumanchi
Subject: asserting the equality of double values
Date: Sat, 15 Sep 2007 13:53:59 -0400
User-agent: KNode/0.10.5

I was browsing the source code of guile 1.8.2 and have couple of trivial
questions. I would be very grateful if you can answer the following

1) In test-suite/standalone/test-round.c (lines 90-96) we have

      /* 2^DBL_MANT_DIG-1
         In the past scm_c_round had incorrectly incremented this value, due
         to the way that x+0.5 would round upwards (in the usual default
         nearest-even mode on most systems).  */
      x = ldexp (1.0, DBL_MANT_DIG) - 1.0;
      assert (x == floor (x));      /* should be an integer already */

here ldexp and floor both return double values. Is it guaranteed that
asserting the equality of two double values will always work? When learning
C, I remember reading somewhere not to rely on such comparisons.

I also do not understand the comment /* should be an integer already */ at
the end of the line. AFAIK both ldexp, floor function return double values
and not integers. Can someone explain the comment?

I am interested in knowing this because guile 1.8.2 fails to build on a
Debian machine using alpha architecture. According to the build log of the
failure (
it occurs around this part of the code.

2) The above code uses DBL_MANT_DIG macro. How can I easily find out where
this macro is defined? Is there any book or reference which discuss this
kind of macros. For now I did a grep in /usr/include and found that such a
macro is defined in /usr/include/c++/4.2/limits file. This brings up
another question. 

If you are using a macro defined in a standard c++ library header, shouldn't
the file be named test-round.cpp instead of test-round.c?


Kamaraju S Kusumanchi

reply via email to

[Prev in Thread] Current Thread [Next in Thread]