Re: double is integer?



On Sat, 03 Feb 2007 20:12:57 -0500, Joseph M. Newcomer
<newcomer@xxxxxxxxxxxx> wrote:

There is no reliable way to actually compare doubles to integers and know that the double
is an integer value.

That's a little pessimistic. Doubles are required to support at least 10
decimal digits of precision, and every implementation I've seen is exact
when dealing with integers and simple arithmetic whose range is the
integers. It's only when you get into overflow (WRT the range of the
integer type in question) or fractions that it becomes imprecise. It's not
unheard of to use double essentially as a large integer in 32 bit
implementations that have no larger integer type; since double typically
has 15 decimal digits of precision, this may allow you to use the full
range of int/long while relieving you of overflow worries. ISTR seeing an
implementation of mktime that did this.

--
Doug Harrison
Visual C++ MVP
.



Relevant Pages

  • Re: about c to fortran
    ... > more than 16 significant figures of precision. ... Where d is the number of decimal digits you write and ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Re: Is it time to legitimise REAL*8 etc?
    ... want/need to specify things. ... Decimal digits of precision might seem fine ... but that just isn't a good match the reality of programming. ...
    (comp.lang.fortran)
  • Re: Ceil double problem
    ... power of 2; base 16 FP maths would be reasonable on some systems. ... DBL_DIG doesn't mandate an exact representation, ... all numbers to that precision be uniquely representable. ...
    (comp.lang.c)
  • Re: Conformance
    ... They give a precision of approx 30 decimal digits ... is called AT COMPILE TIME when the compiler finds an unknown number ... jacob at jacob point remcomp point fr ...
    (comp.std.c)
  • Re: Rounding a REAL
    ... ANINT rounding away from zero. ... Else the problem of overflow arises. ... It is also limited by the range of the integer type, ... needs to be careful about the range of X - single precision is good to ...
    (comp.lang.fortran)