Velocity Reviews > smallest positive double number

# smallest positive double number

gouqizi.lvcha@gmail.com
Guest
Posts: n/a

 06-22-2005
Hi, All:

I wonder what is the smallest positive double numbers in C in 32 bit
CPU?

Rick

CBFalconer
Guest
Posts: n/a

 06-22-2005
"(E-Mail Removed)" wrote:
>
> I wonder what is the smallest positive double numbers in C in
> 32 bit CPU?

I have no idea (on your system), but you do. #include <float.h>

--
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

Richard Bos
Guest
Posts: n/a

 06-22-2005
"(E-Mail Removed)" <(E-Mail Removed)> wrote:

> I wonder what is the smallest positive double numbers in C in 32 bit
> CPU?

That question cannot really be answered. OTOH, there is probably a very
It cannot be answered because having a "32 bit CPU", whichever that
means, does not necessarily mean anything for your integers; means
nearly nothing for the size of your doubles; and means even less for the
representation of those doubles within that size. How a double is
represented is decided by your implementation, not by the CPU. The
implementation probably does take certain aspects of the hardware into
account, but the relevant ones are most likely to be the layout of the
registers of the floating point unit, not the size of the data bus,
fastest or largest integer registers, or whatever aspect of the CPU is
called "32 bit".
It can be answered quite authoritatively for the implementation you are
compiling on at the moment, though: DBL_MIN, from <float.h>, is the
smallest positive normalised double value.

Richard

Grumble
Guest
Posts: n/a

 06-22-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I wonder what is the smallest positive double numbers in C
> in 32 bit CPU?

DBL_MIN yields the smallest normalized, finite representable value
of type double. DBL_EPSILON yields the smallest X of type double
such that 1.0 + X != 1.0.

(Source www.dinkumware.com)

Jean-Claude Arbaut
Guest
Posts: n/a

 06-22-2005

On 22/06/2005 09:29, Richard Bos wrote:

> "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>
>> I wonder what is the smallest positive double numbers in C in 32 bit
>> CPU?

>

I wonder... Actually a CPU could have no FPU at all, which happened on 8086,
80286 and 80386 at least, and probably on 68000. Second, it's perfectly
possible that a C compiler don't use the FPU, if there is one, and sometimes
it depends on how you run the compiler. So there are two different
questions: how does your C compiler handle double numbers, and how does your
CPU, if that makes sense. The first was already answered, the second is in
your CPU's manual. If you have not that manual, it's probably on the web:
there are PDF files for Pentium, PowerPC, 68000, Alpha and Sparc, at least.

You question is also tricky for another reason: usually a C compiler handles
float and double numbers, but the Pentium processor can work with extended
precision (that can be set by an asm instruction, maybe no accessible from
C, and certainly not in C standard). If you work with usual 64 bits IEEE754
doubles on a pentium, you may have different results in your computations
depending on which precision is used internally. There is the same kind of
problem on machines with fused-multiply-add (fma). So be aware that you
question is not only related to your compiler, it's also related to your
CPU. Both are off-topic anyway.

Tim Prince
Guest
Posts: n/a

 06-22-2005
Grumble wrote:
> (E-Mail Removed) wrote:
>
>> I wonder what is the smallest positive double numbers in C
>> in 32 bit CPU?

>
>
> DBL_MIN yields the smallest normalized, finite representable value
> of type double. DBL_EPSILON yields the smallest X of type double
> such that 1.0 + X != 1.0.
>
> (Source www.dinkumware.com)

values DBL_MIN * DBL_EPSILON <= X < DBL_EPSILON are available. This has
nothing to do with "32 bit CPU," nor does "32 bit CPU" have anything to
do with C, except as reflected in <float.h> and <limits.h>.

AC
Guest
Posts: n/a

 06-22-2005

"Grumble" <(E-Mail Removed)> wrote in message
news:d9ba31\$c74\$(E-Mail Removed)...
> (E-Mail Removed) wrote:
>
>> I wonder what is the smallest positive double numbers in C
>> in 32 bit CPU?

>
> DBL_MIN yields the smallest normalized, finite representable value
> of type double. DBL_EPSILON yields the smallest X of type double
> such that 1.0 + X != 1.0.
>
> (Source www.dinkumware.com)

The smallest floating point value might not be normal.

What about something like (pseudo code)

x=1;
{
}

E. Robert Tisdale
Guest
Posts: n/a

 06-22-2005
(E-Mail Removed) wrote:

> I wonder what is the smallest positive double number is
> in C in 32 bit CPU?

> cat main.c

#include <stdio.h>
#include <float.h>

int main(int argc, char* argv[]) {
const
double x = DBL_MIN*DBL_EPSILON;
const unsigned
long int* p = (const unsigned long int*)(&x);
fprintf(stdout, "x = %g\n", x);
fprintf(stdout, "p[1] = %lu\tp[0] = %lu\n", p[1], p[0]);
return 0;
}

> gcc -Wall -std=c99 -pedantic -o main main.c
> ./main

x = 4.94066e-324
p[1] = 0 p[0] = 1

Grumble
Guest
Posts: n/a

 06-23-2005
Jean-Claude Arbaut wrote:

> You question is also tricky for another reason: usually a C compiler handles
> float and double numbers, but the Pentium processor can work with extended
> precision (that can be set by an asm instruction, maybe no accessible from
> C, and certainly not in C standard).

long double?

Jean-Claude Arbaut
Guest
Posts: n/a

 06-23-2005

On 23/06/2005 10:35, Grumble wrote:

> Jean-Claude Arbaut wrote:
>
>> You question is also tricky for another reason: usually a C compiler handles
>> float and double numbers, but the Pentium processor can work with extended
>> precision (that can be set by an asm instruction, maybe no accessible from
>> C, and certainly not in C standard).

>
> long double?

If the compiler knows of this type, yes.