📜  C库-

📅  最后修改于: 2020-12-19 05:37:16             🧑  作者: Mango


C标准库的float.h头文件包含一组与浮点值相关的各种依赖于平台的常量。这些常量由ANSI C提出。它们允许制作更多可移植的程序。在检查所有常量之前,最好了解浮点数由以下四个元素组成:

Sr.No. Component & Component Description
1

S

sign ( +/- )

2

b

base or radix of the exponent representation, 2 for binary, 10 for decimal, 16 for hexadecimal, and so on…

3

e

exponent, an integer between a minimum emin and a maximum emax.

4

p

precision, the number of base-b digits in the significand.

基于以上四个组成部分,浮点的值如下:

floating-point = ( S ) p x be

or

floating-point = (+/-) precision x baseexponent

图书馆巨集

以下值为特定于实现的值,并使用#define指令定义,但这些值不得低于此处给出的值。请注意,在所有情况下,FLT表示float类型,DBL表示double类型,而LDBL表示long double类型

Sr.No. Macro & Description
1

FLT_ROUNDS

Defines the rounding mode for floating point addition and it can have any of the following values −

  • -1 − indeterminable
  • 0 − towards zero
  • 1 − to nearest
  • 2 − towards positive infinity
  • 3 − towards negative infinity
2

FLT_RADIX 2

This defines the base radix representation of the exponent. A base-2 is binary, base-10 is the normal decimal representation, base-16 is Hex.

3

FLT_MANT_DIG

DBL_MANT_DIG

LDBL_MANT_DIG

These macros define the number of digits in the number (in the FLT_RADIX base).

4

FLT_DIG 6

DBL_DIG 10

LDBL_DIG 10

These macros define the maximum number decimal digits (base-10) that can be represented without change after rounding.

5

FLT_MIN_EXP

DBL_MIN_EXP

LDBL_MIN_EXP

These macros define the minimum negative integer value for an exponent in base FLT_RADIX.

6

FLT_MIN_10_EXP -37

DBL_MIN_10_EXP -37

LDBL_MIN_10_EXP -37

These macros define the minimum negative integer value for an exponent in base 10.

7

FLT_MAX_EXP

DBL_MAX_EXP

LDBL_MAX_EXP

These macros define the maximum integer value for an exponent in base FLT_RADIX.

8

FLT_MAX_10_EXP +37

DBL_MAX_10_EXP +37

LDBL_MAX_10_EXP +37

These macros define the maximum integer value for an exponent in base 10.

9

FLT_MAX 1E+37

DBL_MAX 1E+37

LDBL_MAX 1E+37

These macros define the maximum finite floating-point value.

10

FLT_EPSILON 1E-5

DBL_EPSILON 1E-9

LDBL_EPSILON 1E-9

These macros define the least significant digit representable.

11

FLT_MIN 1E-37

DBL_MIN 1E-37

LDBL_MIN 1E-37

These macros define the minimum floating-point values.

以下示例显示了float.h文件中定义的几个常量的用法。

#include 
#include 

int main () {
   printf("The maximum value of float = %.10e\n", FLT_MAX);
   printf("The minimum value of float = %.10e\n", FLT_MIN);

   printf("The number of digits in the number = %.10e\n", FLT_MANT_DIG);
}

让我们编译并运行上面的程序,它将产生以下结果-

The maximum value of float = 3.4028234664e+38
The minimum value of float = 1.1754943508e-38
The number of digits in the number = 7.2996655210e-312