English 中文(简体)
Lower Bounds For Floating Points
原标题:

Are there any lower bounds for floating point types in C? Like there are lower bounds for integral types (int being at least 16 bits)?

问题回答

Yes. float.h contains constants such as:

FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON this is the least magnitude non-zero value which can be represented by float, double, and long double representations.

FLT_MAX and FLT_MIN represent the extreme positive and negative numbers which can be represented for float. Similar DBL_ and LDBL_ are available.

FLT_DIG, DBL_DIG, LDBL_DIG are defined as the number of decimal digits precision.

You are asking for either the xxx_MIN or the xxx_EPSILON value.

Along these lines, here is a question wherein I posted some code which displays the internals of a 64-bit IEEE-754 floating-point number.

To be strict and grounded:

ISO/IEC 9899:TC2: (WG14/N1124m May 6, 2005):

5.2.4.2.2, Characteristics of floating types <float.h>

float.h contains many macros describing various properties of the floating types (including FLT_MIN and DBL_MIN).

The description of the requirements of the limits infloat.h is given in the standard (C90 or C99 - 5.2.4.2.2 "Characteristics of floating types").

In particular, according to the standard any implementation must support a lower-bound of at least 1E-37 for float or double. But an implementation is free to do better than that (and indicate what it does in FLT_MIN and DBL_MIN).

See this question for information on where to get a copy of the standards documents if you need one:

Maybe this helps: float.h reference (it is C++, I m not sure if it applies to plain C as well)

This Draft C99 standard (PDF) notes minimum values for floating point type precision in section 5.2.4.2.2.

(Found via Wikipedia on C99.)

A useful reference here is What Every Computer Scientist Should Know About Floating-Point Arithmetic.

The nature of a floating point number — its size, precision, limits — is really defined by the hardware, rather than the programming language. A single-precision float on an x86 is the same in C, C#, Java, and any other practical programming language. (The exception is esoteric programming languages that implement odd widths of floating point number in software.)

Excerpts from the Standard draft (n1401.pdf)

                                      Annex F
                                    (normative)
                       IEC 60559 floating-point arithmetic
    F.1 Introduction
1   ... An implementation that defines _ _STDC_IEC_559_ _ shall conform to
    the specifications in this annex. ...

    F.2 Types
1   The C floating types match the IEC 60559 formats as follows:
    -- The float type matches the IEC 60559 single format.
    -- The double type matches the IEC 60559 double format.
    -- The long double type matches an IEC 60559 extended format ...

Wikipedia has an article about IEC 559 (or rather IEEE 754-1985) you might find interesting.





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签