Floating point precision

A

artifact.one

Hello.

Is there any reliable way to determine the number
of digits of precision given by the float/double
type? I read somewhere that the C99 standard
guarantees six digits of precision with the float
type, although I can't seem to find this
information now.

A cursory search through the C99 pdf doesn't bring
up anything particularly helpful.
 
S

santosh

Hello.

Is there any reliable way to determine the number
of digits of precision given by the float/double
type? I read somewhere that the C99 standard
guarantees six digits of precision with the float
type, although I can't seem to find this
information now.

A cursory search through the C99 pdf doesn't bring
up anything particularly helpful.

Yes. The Standard header float.h specifies the properties of the
implementation's floating-point types. Specifically you might want to
look at the FLT_DIG and DBL_DIG macros.
 
C

Coos Haak

Op 11 Mar 2007 08:06:21 -0700 schreef (e-mail address removed):
Hello.

Is there any reliable way to determine the number
of digits of precision given by the float/double
type? I read somewhere that the C99 standard
guarantees six digits of precision with the float
type, although I can't seem to find this
information now.

A cursory search through the C99 pdf doesn't bring
up anything particularly helpful.

Look for FLT_DIG
 
K

Keith Thompson

Is there any reliable way to determine the number
of digits of precision given by the float/double
type? I read somewhere that the C99 standard
guarantees six digits of precision with the float
type, although I can't seem to find this
information now.

A cursory search through the C99 pdf doesn't bring
up anything particularly helpful.

You're looking for FLT_DIG and DBL_DIG (and LDBL_DIG) in <float.h>,
C99 5.2.4.2.2.

The <limits.h> and <float.h> headers are described in section 5,
"Environment"; the other standard headers are described in section 7,
"Library". If you don't remember this, then can be difficult to find.
 
M

Martin Ambuhl

Hello.

Is there any reliable way to determine the number
of digits of precision given by the float/double
type? I read somewhere that the C99 standard
guarantees six digits of precision with the float
type, although I can't seem to find this
information now.

A cursory search through the C99 pdf doesn't bring
up anything particularly helpful.

Your search was a very cursory one, wasn't it:

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


int main(void)
{
printf
("Decimal precision of floating point types in "
"this implementation:\n"
"float: %d (standard requires at least 6)\n"
"double: %d (standard requires at least 10)\n", FLT_DIG,
DBL_DIG);
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
printf("long double: %d (standard requires at least 10)\n",
LDBL_DIG);

#endif
return 0;
}

[Output on my current version]

Decimal precision of floating point types in this implementation:
float: 6 (standard requires at least 6)
double: 15 (standard requires at least 10)
long double: 18 (standard requires at least 10)
 

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

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,062
Members
48,769
Latest member
Clifft

Latest Threads

Top