473,800 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2408
ar**********@go oglemail.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**********@go oglemail.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**********@go oglemail.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.hheade rs are described in section 5,
"Environmen t"; 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_Keit h) 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**********@go oglemail.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
3317
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 interact with a rich 3D environment. Seem to be 90% of the way there! My problems are related to calculations where the result tends to zero (or another defined limit.) Have loads of cases where this kind of interaction occurs but this one
31
3688
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. However, they generate slightly different results for floating point numbers. Are they really supposed to generate exactly the same results? I guess so because both platforms are supposed to be IEEE floating point standard (754?) compliant. ...
5
3753
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 using the Debug-Version of the program, but it fails (or leads to false results) if we are using the Release-Version. After a long debugging session we found out, that our program was working correctly, but the floating point processing...
687
23772
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 believe that. in pieces of the application where speed really matters you can still use "normal" functions or even static methods which is basically the same. in C there arent the simplest things present like constants, each struct and enum...
2
15872
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 IBM/370 float values into IEEE 754 'float' values that I can use directly with any modern C environment (that uses IEEE 754). I can handle endian conversion myself (the files are stored as big endian, and I'll process them on a little endian...
5
2416
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 opposite order? The idea is that the two fractions are almost identical and that the error introduced by going to floating point representation is bigger than the exact difference, but different for the two fractions such that it somehow turns...
10
18775
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
2838
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 would like your expert advise before I publish any serious nonsense. Any comments are welcome, style, organization, hard errors, etc.
137
6753
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 high speed. What would be the possible alternatives? Thanks for any help
39
3585
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 out there understands what happens. Essentially, when I subtract the (double) function value GRID_POINT(2) from a variable which has been assigned the same value before this gives a non-zero result and I really do not understand why.
0
9694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9553
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10509
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10256
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10039
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.