473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Floating point precision

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
5 2378
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
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
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
FLT_DIG

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

Mar 11 '07 #5
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave | last post by:
Hi folks, I am trying to develop a routine that will handle sphere-sphere and sphere-triangle collisions and interactions. My aim is to develop a quake style collision engine where a player can...
31
by: JS | last post by:
We have the same floating point intensive C++ program that runs on Windows on Intel chip and on Sun Solaris on SPARC chips. The program reads the exactly the same input files on the two platforms....
5
by: Anton Noll | last post by:
We are using Visual Studio 2003.NET (C++) for the development of our software in the fields digital signal processing and numerical acoustics. One of our programs was working correctly if we are...
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
2
by: Benjamin Rutt | last post by:
Does anyone have C code laying around to do this? I have to read in some binary data files that contains some 4-byte IBM/370 floating point values. I would like a function to convert 4-byte...
5
by: Steffen | last post by:
Hi, is it possible to have two fractions, which (mathematically) have the order a/b < c/d (a,b,c,d integers), but when (correctly) converted into floating point representation just have the...
10
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
4
by: jacob navia | last post by:
Hi people I continue to work in the tutorial for lcc-win32, and started to try to explain the floating point flags. Here is the relevant part of the tutorial. Since it is a difficult part, I...
137
by: mathieu.dutour | last post by:
Dear all, I want to do multiprecision floating point, i.e. I want to go beyond single precision, double precision and have quadruple precision, octuple precision and the like, and possibly with...
39
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.