By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,132 Members | 1,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,132 IT Pros & Developers. It's quick & easy.

Floating point precision

P: n/a
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.

Mar 11 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ar**********@googlemail.com wrote:
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.

Mar 11 '07 #2

P: n/a
Op 11 Mar 2007 08:06:21 -0700 schreef ar**********@googlemail.com:
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
--
Coos
Mar 11 '07 #3

P: n/a
ar**********@googlemail.com writes:
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.hand <float.hheaders 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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 11 '07 #4

P: n/a
FLT_DIG

Excellent, that's just what I was looking for. Thanks.

Mar 11 '07 #5

P: n/a
ar**********@googlemail.com wrote:
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)

Mar 11 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.