smallest positive double number

G

gouqizi.lvcha

Hi, All:

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

Rick
 
R

Richard Bos

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
definite and useful answer.
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
 
G

Grumble

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)
 
J

Jean-Claude Arbaut

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.
 
T

Tim Prince

Grumble said:
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)
If you have IEEE gradual underflow enabled on your system, subnormal
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>.
 
A

AC

Grumble said:
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;
while(x/FLT_RADIX)
{
x = x/FLT_RADIX;
}
 
E

E. Robert Tisdale

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
 
G

Grumble

Jean-Claude Arbaut said:
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?
 
P

pete

Jean-Claude Arbaut said:
On 23/06/2005 10:35, Grumble wrote:

If the compiler knows of this type, yes.

long double has been standard, ever since there was a standard.

We usually assume standard C here, unless otherwise stated.
If you're stating something that's only intended to be true
for one of C89 or C99 or K&R, then it's best to specify which.
 
J

Jean-Claude Arbaut

long double has been standard, ever since there was a standard.

We usually assume standard C here, unless otherwise stated.
If you're stating something that's only intended to be true
for one of C89 or C99 or K&R, then it's best to specify which.

Ok, the compiler always knows. But that wasn't the problem. The OP asked for
the smallest positive double, and depending on what he is doing with it,
compiler optimizations can be nasty: there may be numbers smaller than that
at runtime, simply because it's computing in extended precision, and it
doesn't store/reload values between computation. The same kind of problem
happens on PPC with fma instructions (but there, reloading values does not
help). When doing fp computation, one must be careful with fpu flags, for
instance precision control flags. Even of PPC, you can have long double, if
they are implemented as two doubles, XLC has them for example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top