Programming languages — C (INTERNATIONAL STANDARD ISO/IEC 9899:TC3) - page 1

 

  Главная      Manuals     Programming languages — C (INTERNATIONAL STANDARD ISO/IEC 9899:TC3) - 2007 year

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..      1       2         ..

 

 

 

Programming languages — C (INTERNATIONAL STANDARD ISO/IEC 9899:TC3) - page 1

 

 

6.5.1 Primary expressions

. . . . . . . . . . . . . . . . .

69

6.5.2 Postfix operators

. . . . . . . . . . . . . . . . . . .

69

6.5.3 Unary operators

. . . . . . . . . . . . . . . . . . .

78

6.5.4 Cast operators

. . . . . . . . . . . . . . . . . . . .

81

6.5.5 Multiplicative operators

. . . . . . . . . . . . . . . .

82

6.5.6 Additive operators

. . . . . . . . . . . . . . . . . .

82

6.5.7 Bitwise shift operators

. . . . . . . . . . . . . . . . .

84

6.5.8 Relational operators

. . . . . . . . . . . . . . . . . .

85

6.5.9 Equality operators

. . . . . . . . . . . . . . . . . .

86

6.5.10 Bitwise

AND

operator

. . . . . . . . . . . . . . . . .

87

6.5.11 Bitwise exclusive

OR

operator

. . . . . . . . . . . . .

88

6.5.12 Bitwise inclusive

OR

operator

. . . . . . . . . . . . . .

88

6.5.13 Logical

AND

operator

. . . . . . . . . . . . . . . . .

89

6.5.14 Logical

OR

operator

. . . . . . . . . . . . . . . . .

89

6.5.15 Conditional operator

. . . . . . . . . . . . . . . . .

90

6.5.16 Assignment operators

. . . . . . . . . . . . . . . . .

91

6.5.17 Comma operator

. . . . . . . . . . . . . . . . . . .

94

6.6 Constant expressions

. . . . . . . . . . . . . . . . . . . . .

95

6.7 Declarations

. . . . . . . . . . . . . . . . . . . . . . . .

97

6.7.1 Storage-class specifiers

. . . . . . . . . . . . . . . .

98

6.7.2 Type specifiers

. . . . . . . . . . . . . . . . . . . .

99

6.7.3 Type qualifiers

. . . . . . . . . . . . . . . . . . . . 108

6.7.4 Function specifiers

. . . . . . . . . . . . . . . . . . 112

6.7.5 Declarators

. . . . . . . . . . . . . . . . . . . . . 114

6.7.6 Type names

. . . . . . . . . . . . . . . . . . . . . 122

6.7.7 Type definitions

. . . . . . . . . . . . . . . . . . . 123

6.7.8 Initialization

. . . . . . . . . . . . . . . . . . . . 125

6.8 Statements and blocks

. . . . . . . . . . . . . . . . . . . . 131

6.8.1 Labeled statements

. . . . . . . . . . . . . . . . . . 131

6.8.2 Compound statement

. . . . . . . . . . . . . . . . . 132

6.8.3 Expression and null statements

. . . . . . . . . . . . . 132

6.8.4 Selection statements

. . . . . . . . . . . . . . . . . 133

6.8.5 Iteration statements

. . . . . . . . . . . . . . . . . . 135

6.8.6 Jump statements

. . . . . . . . . . . . . . . . . . . 136

6.9 External definitions

. . . . . . . . . . . . . . . . . . . . . 140

6.9.1 Function definitions

. . . . . . . . . . . . . . . . . . 141

6.9.2 External object definitions

. . . . . . . . . . . . . . . 143

6.10 Preprocessing directives

. . . . . . . . . . . . . . . . . . . 145

6.10.1 Conditional inclusion

. . . . . . . . . . . . . . . . . 147

6.10.2 Source file inclusion

. . . . . . . . . . . . . . . . . 149

6.10.3 Macro replacement

. . . . . . . . . . . . . . . . . . 151

6.10.4 Line control

. . . . . . . . . . . . . . . . . . . . . 158

6.10.5 Error directive

. . . . . . . . . . . . . . . . . . . . 159

6.10.6 Pragma directive

. . . . . . . . . . . . . . . . . . . 159

iv Contents

FE_DFL_ENV

represents the default floating-point environment — the one installed at program startup
— and has type ‘‘pointer to const-qualified

fenv_t

’’. It can be used as an argument to

<fenv.h>

functions that manage the floating-point environment.

9

Additional implementation-defined environments, with macro definitions beginning with

FE_

and an uppercase letter, and having type ‘‘pointer to const-qualified

fenv_t

’’, may

also be specified by the implementation.

7.6.1 The

FENV_ACCESS

pragma

Synopsis

1

#include <fenv.h>

#pragma STDC FENV_ACCESS

on-off-switch

Description

2

The

FENV_ACCESS

pragma provides a means to inform the implementation when a

program might access the floating-point environment to test floating-point status flags or
run under non-default floating-point control modes.

184)

The pragma shall occur either

outside external declarations or preceding all explicit declarations and statements inside a
compound statement. When outside external declarations, the pragma takes effect from
its occurrence until another

FENV_ACCESS

pragma is encountered, or until the end of

the translation unit. When inside a compound statement, the pragma takes effect from its
occurrence until another

FENV_ACCESS

pragma is encountered (including within a

nested compound statement), or until the end of the compound statement; at the end of a
compound statement the state for the pragma is restored to its condition just before the
compound statement. If this pragma is used in any other context, the behavior is
undefined. If part of a program tests floating-point status flags, sets floating-point control
modes, or runs under non-default mode settings, but was translated with the state for the

FENV_ACCESS

pragma ‘‘off’’, the behavior is undefined. The default state (‘‘on’’ or

‘‘off’’) for the pragma is implementation-defined. (When execution passes from a part of
the program translated with

FENV_ACCESS

‘‘off’’ to a part translated with

FENV_ACCESS

‘‘on’’, the state of the floating-point status flags is unspecified and the

floating-point control modes have their default settings.)

184) The purpose of the

FENV_ACCESS

pragma is to allow certain optimizations that could subvert flag

tests and mode changes (e.g., global common subexpression elimination, code motion, and constant
folding). In general, if the state of

FENV_ACCESS

is ‘‘off’’, the translator can assume that default

modes are in effect and the flags are not tested.

§7.6.1 Library

189

6.10.7 Null directive

. . . . . . . . . . . . . . . . . . . . 160

6.10.8 Predefined macro names

. . . . . . . . . . . . . . . . 160

6.10.9 Pragma operator

. . . . . . . . . . . . . . . . . . . 161

6.11 Future language directions

. . . . . . . . . . . . . . . . . . 163

6.11.1 Floating types

. . . . . . . . . . . . . . . . . . . . 163

6.11.2 Linkages of identifiers

. . . . . . . . . . . . . . . . . 163

6.11.3 External names

. . . . . . . . . . . . . . . . . . . 163

6.11.4 Character escape sequences

. . . . . . . . . . . . . . 163

6.11.5 Storage-class specifiers

. . . . . . . . . . . . . . . . 163

6.11.6 Function declarators

. . . . . . . . . . . . . . . . . 163

6.11.7 Function definitions

. . . . . . . . . . . . . . . . . . 163

6.11.8 Pragma directives

. . . . . . . . . . . . . . . . . . 163

6.11.9 Predefined macro names

. . . . . . . . . . . . . . . . 163

7. Library

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

7.1 Introduction

. . . . . . . . . . . . . . . . . . . . . . . . 164

7.1.1 Definitions of terms

. . . . . . . . . . . . . . . . . . 164

7.1.2 Standard headers

. . . . . . . . . . . . . . . . . . . 165

7.1.3 Reserved identifiers

. . . . . . . . . . . . . . . . . . 166

7.1.4 Use of library functions

. . . . . . . . . . . . . . . . 166

7.2 Diagnostics

<assert.h>

. . . . . . . . . . . . . . . . . . 169

7.2.1 Program diagnostics

. . . . . . . . . . . . . . . . . 169

7.3 Complex arithmetic

<complex.h>

. . . . . . . . . . . . . . 170

7.3.1 Introduction

. . . . . . . . . . . . . . . . . . . . . 170

7.3.2 Conventions

. . . . . . . . . . . . . . . . . . . . . 171

7.3.3 Branch cuts

. . . . . . . . . . . . . . . . . . . . . 171

7.3.4 The

CX_LIMITED_RANGE

pragma

. . . . . . . . . . . 171

7.3.5 Trigonometric functions

. . . . . . . . . . . . . . . . 172

7.3.6 Hyperbolic functions

. . . . . . . . . . . . . . . . . 174

7.3.7 Exponential and logarithmic functions

. . . . . . . . . . 176

7.3.8 Power and absolute-value functions

. . . . . . . . . . . 177

7.3.9 Manipulation functions

. . . . . . . . . . . . . . . . 178

7.4 Character handling

<ctype.h>

. . . . . . . . . . . . . . . . 181

7.4.1 Character classification functions

. . . . . . . . . . . . 181

7.4.2 Character case mapping functions

. . . . . . . . . . . . 184

7.5 Errors

<errno.h>

. . . . . . . . . . . . . . . . . . . . . 186

7.6 Floating-point environment

<fenv.h>

. . . . . . . . . . . . . 187

7.6.1 The

FENV_ACCESS

pragma

. . . . . . . . . . . . . . 189

7.6.2 Floating-point exceptions

. . . . . . . . . . . . . . . 190

7.6.3 Rounding

. . . . . . . . . . . . . . . . . . . . . . 193

7.6.4 Environment

. . . . . . . . . . . . . . . . . . . . 194

7.7 Characteristics of floating types

<float.h>

. . . . . . . . . . . 197

7.8 Format conversion of integer types

<inttypes.h>

. . . . . . . . 198

7.8.1 Macros for format specifiers

. . . . . . . . . . . . . . 198

7.8.2 Functions for greatest-width integer types

. . . . . . . . . 199

Contents v

7.9 Alternative spellings

<iso646.h>

. . . . . . . . . . . . . . . 202

7.10 Sizes of integer types

<limits.h>

. . . . . . . . . . . . . . 203

7.11 Localization

<locale.h>

. . . . . . . . . . . . . . . . . . 204

7.11.1 Locale control

. . . . . . . . . . . . . . . . . . . . 205

7.11.2 Numeric formatting convention inquiry

. . . . . . . . . . 206

7.12 Mathematics

<math.h>

. . . . . . . . . . . . . . . . . . . 212

7.12.1 Treatment of error conditions

. . . . . . . . . . . . . . 214

7.12.2 The

FP_CONTRACT

pragma

. . . . . . . . . . . . . . 215

7.12.3 Classification macros

. . . . . . . . . . . . . . . . . 216

7.12.4 Trigonometric functions

. . . . . . . . . . . . . . . . 218

7.12.5 Hyperbolic functions

. . . . . . . . . . . . . . . . . 221

7.12.6 Exponential and logarithmic functions

. . . . . . . . . . 223

7.12.7 Power and absolute-value functions

. . . . . . . . . . . 228

7.12.8 Error and gamma functions

. . . . . . . . . . . . . . . 230

7.12.9 Nearest integer functions

. . . . . . . . . . . . . . . . 231

7.12.10 Remainder functions

. . . . . . . . . . . . . . . . . 235

7.12.11 Manipulation functions

. . . . . . . . . . . . . . . . 236

7.12.12 Maximum, minimum, and positive difference functions

. . . 238

7.12.13 Floating multiply-add

. . . . . . . . . . . . . . . . . 239

7.12.14 Comparison macros

. . . . . . . . . . . . . . . . . . 240

7.13 Nonlocal jumps

<setjmp.h>

. . . . . . . . . . . . . . . . 243

7.13.1 Save calling environment

. . . . . . . . . . . . . . . 243

7.13.2 Restore calling environment

. . . . . . . . . . . . . . 244

7.14 Signal handling

<signal.h>

. . . . . . . . . . . . . . . . . 246

7.14.1 Specify signal handling

. . . . . . . . . . . . . . . . 247

7.14.2 Send signal

. . . . . . . . . . . . . . . . . . . . . 248

7.15 Variable arguments

<stdarg.h>

. . . . . . . . . . . . . . . 249

7.15.1 Variable argument list access macros

. . . . . . . . . . . 249

7.16 Boolean type and values

<stdbool.h>

. . . . . . . . . . . . 253

7.17 Common definitions

<stddef.h>

. . . . . . . . . . . . . . . 254

7.18 Integer types

<stdint.h>

. . . . . . . . . . . . . . . . . . 255

7.18.1 Integer types

. . . . . . . . . . . . . . . . . . . . 255

7.18.2 Limits of specified-width integer types

. . . . . . . . . . 257

7.18.3 Limits of other integer types

. . . . . . . . . . . . . . 259

7.18.4 Macros for integer constants

. . . . . . . . . . . . . . 260

7.19 Input/output

<stdio.h>

. . . . . . . . . . . . . . . . . . 262

7.19.1 Introduction

. . . . . . . . . . . . . . . . . . . . . 262

7.19.2 Streams

. . . . . . . . . . . . . . . . . . . . . . 264

7.19.3 Files

. . . . . . . . . . . . . . . . . . . . . . . . 266

7.19.4 Operations on files

. . . . . . . . . . . . . . . . . . 268

7.19.5 File access functions

. . . . . . . . . . . . . . . . . 270

7.19.6 Formatted input/output functions

. . . . . . . . . . . . 274

7.19.7 Character input/output functions

. . . . . . . . . . . . . 296

7.19.8 Direct input/output functions

. . . . . . . . . . . . . . 301

vi Contents

7.6.2.2 The

fegetexceptflag

function

Synopsis

1

#include <fenv.h>

int fegetexceptflag(fexcept_t *flagp,

int excepts);

Description

2

The

fegetexceptflag

function attempts to store an implementation-defined

representation of the states of the floating-point status flags indicated by the argument

excepts

in the object pointed to by the argument

flagp

.

Returns

3

The

fegetexceptflag

function returns zero if the representation was successfully

stored. Otherwise, it returns a nonzero value.

7.6.2.3 The

feraiseexcept

function

Synopsis

1

#include <fenv.h>

int feraiseexcept(int excepts);

Description

2

The

feraiseexcept

function attempts to raise the supported floating-point exceptions

represented by its argument.

187)

The order in which these floating-point exceptions are

raised is unspecified, except as stated in F.7.6. Whether the

feraiseexcept

function

additionally raises the ‘‘inexact’’ floating-point exception whenever it raises the
‘‘overflow’’ or ‘‘underflow’’ floating-point exception is implementation-defined.

Returns

3

The

feraiseexcept

function returns zero if the

excepts

argument is zero or if all

the specified exceptions were successfully raised. Otherwise, it returns a nonzero value.

187) The effect is intended to be similar to that of floating-point exceptions raised by arithmetic operations.

Hence, enabled traps for floating-point exceptions raised by this function are taken. The specification
in F.7.6 is in the same spirit.

§7.6.2.3 Library

191

3

EXAMPLE

#include <fenv.h>

void f(double x)

{

#pragma STDC FENV_ACCESS ON

void g(double);

void h(double);

/*

...

*/

g(x + 1);

h(x + 1);

/*

...

*/

}

4

If the function

g

might depend on status flags set as a side effect of the first

x + 1

, or if the second

x + 1

might depend on control modes set as a side effect of the call to function

g

, then the program shall

contain an appropriately placed invocation of

#pragma STDC FENV_ACCESS ON

.

185)

7.6.2 Floating-point exceptions

1

The following functions provide access to the floating-point status flags.

186)

The

int

input argument for the functions represents a subset of floating-point exceptions, and can
be zero or the bitwise

OR

of one or more floating-point exception macros, for example

FE_OVERFLOW | FE_INEXACT

. For other argument values the behavior of these

functions is undefined.

7.6.2.1 The

feclearexcept

function

Synopsis

1

#include <fenv.h>

int feclearexcept(int excepts);

Description

2

The

feclearexcept

function attempts to clear the supported floating-point exceptions

represented by its argument.

Returns

3

The

feclearexcept

function returns zero if the

excepts

argument is zero or if all

the specified exceptions were successfully cleared. Otherwise, it returns a nonzero value.

185) The side effects impose a temporal ordering that requires two evaluations of

x + 1

. On the other

hand, without the

#pragma STDC FENV_ACCESS ON

pragma, and assuming the default state is

‘‘off’’, just one evaluation of

x + 1

would suffice.

186) The functions

fetestexcept

,

feraiseexcept

, and

feclearexcept

support the basic

abstraction of flags that are either set or clear. An implementation may endow floating-point status
flags with more information — for example, the address of the code which first raised the floating-
point exception; the functions

fegetexceptflag

and

fesetexceptflag

deal with the full

content of flags.

190 Library

§7.6.2.1

7.19.9 File positioning functions

. . . . . . . . . . . . . . . 302

7.19.10 Error-handling functions

. . . . . . . . . . . . . . . . 304

7.20 General utilities

<stdlib.h>

. . . . . . . . . . . . . . . . 306

7.20.1 Numeric conversion functions

. . . . . . . . . . . . . . 307

7.20.2 Pseudo-random sequence generation functions

. . . . . . . 312

7.20.3 Memory management functions

. . . . . . . . . . . . . 313

7.20.4 Communication with the environment

. . . . . . . . . . 315

7.20.5 Searching and sorting utilities

. . . . . . . . . . . . . . 318

7.20.6 Integer arithmetic functions

. . . . . . . . . . . . . . 320

7.20.7 Multibyte/wide character conversion functions

. . . . . . . 321

7.20.8 Multibyte/wide string conversion functions

. . . . . . . . 323

7.21 String handling

<string.h>

. . . . . . . . . . . . . . . . . 325

7.21.1 String function conventions

. . . . . . . . . . . . . . . 325

7.21.2 Copying functions

. . . . . . . . . . . . . . . . . . 325

7.21.3 Concatenation functions

. . . . . . . . . . . . . . . . 327

7.21.4 Comparison functions

. . . . . . . . . . . . . . . . . 328

7.21.5 Search functions

. . . . . . . . . . . . . . . . . . . 330

7.21.6 Miscellaneous functions

. . . . . . . . . . . . . . . . 333

7.22 Type-generic math

<tgmath.h>

. . . . . . . . . . . . . . . 335

7.23 Date and time

<time.h>

. . . . . . . . . . . . . . . . . . 338

7.23.1 Components of time

. . . . . . . . . . . . . . . . . 338

7.23.2 Time manipulation functions

. . . . . . . . . . . . . . 339

7.23.3 Time conversion functions

. . . . . . . . . . . . . . . 341

7.24 Extended multibyte and wide character utilities

<wchar.h>

. . . . . 348

7.24.1 Introduction

. . . . . . . . . . . . . . . . . . . . . 348

7.24.2 Formatted wide character input/output functions

. . . . . . 349

7.24.3 Wide character input/output functions

. . . . . . . . . . 367

7.24.4 General wide string utilities

. . . . . . . . . . . . . . 371

7.24.5 Wide character time conversion functions

. . . . . . . . . 385

7.24.6 Extended multibyte/wide character conversion utilities

. . . . 386

7.25 Wide character classification and mapping utilities

<wctype.h>

. . . 393

7.25.1 Introduction

. . . . . . . . . . . . . . . . . . . . . 393

7.25.2 Wide character classification utilities

. . . . . . . . . . . 394

7.25.3 Wide character case mapping utilities

. . . . . . . . . . . 399

7.26 Future library directions

. . . . . . . . . . . . . . . . . . . 401

7.26.1 Complex arithmetic

<complex.h>

. . . . . . . . . . . 401

7.26.2 Character handling

<ctype.h>

. . . . . . . . . . . . 401

7.26.3 Errors

<errno.h>

. . . . . . . . . . . . . . . . . 401

7.26.4 Format conversion of integer types

<inttypes.h>

. . . . 401

7.26.5 Localization

<locale.h>

. . . . . . . . . . . . . . 401

7.26.6 Signal handling

<signal.h>

. . . . . . . . . . . . . 401

7.26.7 Boolean type and values

<stdbool.h>

. . . . . . . . . 401

7.26.8 Integer types

<stdint.h>

. . . . . . . . . . . . . . 401

7.26.9 Input/output

<stdio.h>

. . . . . . . . . . . . . . . 402

Contents vii

7.26.10 General utilities

<stdlib.h>

. . . . . . . . . . . . . 402

7.26.11 String handling

<string.h>

. . . . . . . . . . . . . 402

7.26.12 Extended multibyte and wide character utilities

<wchar.h>

. . . . . . . . . . . . . . . . . . . . 402

7.26.13 Wide character classification and mapping utilities

<wctype.h>

. . . . . . . . . . . . . . . . . . . . 402

Annex A (informative) Language syntax summary

. . . . . . . . . . . . 403

A.1 Lexical grammar

. . . . . . . . . . . . . . . . . . . . . . 403

A.2 Phrase structure grammar

. . . . . . . . . . . . . . . . . . . 409

A.3 Preprocessing directives

. . . . . . . . . . . . . . . . . . . 416

Annex B (informative) Library summary

. . . . . . . . . . . . . . . . 419

B.1 Diagnostics

<assert.h>

. . . . . . . . . . . . . . . . . . 419

B.2 Complex

<complex.h>

. . . . . . . . . . . . . . . . . . . 419

B.3 Character handling

<ctype.h>

. . . . . . . . . . . . . . . . 421

B.4 Errors

<errno.h>

. . . . . . . . . . . . . . . . . . . . . 421

B.5 Floating-point environment

<fenv.h>

. . . . . . . . . . . . . 421

B.6 Characteristics of floating types

<float.h>

. . . . . . . . . . . 422

B.7 Format conversion of integer types

<inttypes.h>

. . . . . . . . 422

B.8 Alternative spellings

<iso646.h>

. . . . . . . . . . . . . . . 423

B.9 Sizes of integer types

<limits.h>

. . . . . . . . . . . . . . 423

B.10 Localization

<locale.h>

. . . . . . . . . . . . . . . . . . 423

B.11 Mathematics

<math.h>

. . . . . . . . . . . . . . . . . . . 423

B.12 Nonlocal jumps

<setjmp.h>

. . . . . . . . . . . . . . . . 428

B.13 Signal handling

<signal.h>

. . . . . . . . . . . . . . . . . 428

B.14 Variable arguments

<stdarg.h>

. . . . . . . . . . . . . . . 428

B.15 Boolean type and values

<stdbool.h>

. . . . . . . . . . . . 428

B.16 Common definitions

<stddef.h>

. . . . . . . . . . . . . . . 429

B.17 Integer types

<stdint.h>

. . . . . . . . . . . . . . . . . . 429

B.18 Input/output

<stdio.h>

. . . . . . . . . . . . . . . . . . 429

B.19 General utilities

<stdlib.h>

. . . . . . . . . . . . . . . . 431

B.20 String handling

<string.h>

. . . . . . . . . . . . . . . . . 433

B.21 Type-generic math

<tgmath.h>

. . . . . . . . . . . . . . . 434

B.22 Date and time

<time.h>

. . . . . . . . . . . . . . . . . . 434

B.23 Extended multibyte/wide character utilities

<wchar.h>

. . . . . . 435

B.24 Wide character classification and mapping utilities

<wctype.h>

. . . 437

Annex C (informative) Sequence points

. . . . . . . . . . . . . . . . . 439

Annex D (normative) Universal character names for identifiers

. . . . . . . 440

Annex E (informative) Implementation limits

. . . . . . . . . . . . . . 442

Annex F (normative) IEC 60559 floating-point arithmetic

. . . . . . . . . . 444

F.1

Introduction

. . . . . . . . . . . . . . . . . . . . . . . . 444

F.2

Types

. . . . . . . . . . . . . . . . . . . . . . . . . . . 444

F.3

Operators and functions

. . . . . . . . . . . . . . . . . . . 445

viii Contents

#include <fenv.h>

/*

...

*/

{

#pragma STDC FENV_ACCESS ON

int set_excepts;

feclearexcept(FE_INVALID | FE_OVERFLOW);

//

maybe raise exceptions

set_excepts = fetestexcept(FE_INVALID | FE_OVERFLOW);

if (set_excepts & FE_INVALID) f();

if (set_excepts & FE_OVERFLOW) g();

/*

...

*/

}

7.6.3 Rounding

1

The

fegetround

and

fesetround

functions provide control of rounding direction

modes.

7.6.3.1 The

fegetround

function

Synopsis

1

#include <fenv.h>

int fegetround(void);

Description

2

The

fegetround

function gets the current rounding direction.

Returns

3

The

fegetround

function returns the value of the rounding direction macro

representing the current rounding direction or a negative value if there is no such
rounding direction macro or the current rounding direction is not determinable.

7.6.3.2 The

fesetround

function

Synopsis

1

#include <fenv.h>

int fesetround(int round);

Description

2

The

fesetround

function establishes the rounding direction represented by its

argument

round

. If the argument is not equal to the value of a rounding direction macro,

the rounding direction is not changed.

Returns

3

The

fesetround

function returns zero if and only if the requested rounding direction

was established.

§7.6.3.2 Library

193

F.4

Floating to integer conversion

. . . . . . . . . . . . . . . . . 447

F.5

Binary-decimal conversion

. . . . . . . . . . . . . . . . . . 447

F.6

Contracted expressions

. . . . . . . . . . . . . . . . . . . . 448

F.7

Floating-point environment

. . . . . . . . . . . . . . . . . . 448

F.8

Optimization

. . . . . . . . . . . . . . . . . . . . . . . . 451

F.9

Mathematics

<math.h>

. . . . . . . . . . . . . . . . . . . 454

Annex G (informative) IEC 60559-compatible complex arithmetic

. . . . . . 467

G.1 Introduction

. . . . . . . . . . . . . . . . . . . . . . . . 467

G.2 Types

. . . . . . . . . . . . . . . . . . . . . . . . . . . 467

G.3 Conventions

. . . . . . . . . . . . . . . . . . . . . . . . 467

G.4 Conversions

. . . . . . . . . . . . . . . . . . . . . . . . 468

G.5 Binary operators

. . . . . . . . . . . . . . . . . . . . . . 468

G.6 Complex arithmetic

<complex.h>

. . . . . . . . . . . . . . 472

G.7 Type-generic math

<tgmath.h>

. . . . . . . . . . . . . . . 480

Annex H (informative) Language independent arithmetic

. . . . . . . . . . 481

H.1 Introduction

. . . . . . . . . . . . . . . . . . . . . . . . 481

H.2 Types

. . . . . . . . . . . . . . . . . . . . . . . . . . . 481

H.3 Notification

. . . . . . . . . . . . . . . . . . . . . . . . 485

Annex I (informative) Common warnings

. . . . . . . . . . . . . . . . 487

Annex J (informative) Portability issues

. . . . . . . . . . . . . . . . . 489

J.1 Unspecified behavior

. . . . . . . . . . . . . . . . . . . . . 489

J.2 Undefined behavior

. . . . . . . . . . . . . . . . . . . . . 492

J.3 Implementation-defined behavior

. . . . . . . . . . . . . . . . 505

J.4 Locale-specific behavior

. . . . . . . . . . . . . . . . . . . 512

J.5 Common extensions

. . . . . . . . . . . . . . . . . . . . . 513

Bibliography

. . . . . . . . . . . . . . . . . . . . . . . . . . . 516

Index

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519

Contents ix

x

Contents

Returns

3

The

feholdexcept

function returns zero if and only if non-stop floating-point

exception handling was successfully installed.

7.6.4.3 The

fesetenv

function

Synopsis

1

#include <fenv.h>

int fesetenv(const fenv_t *envp);

Description

2

The

fesetenv

function attempts to establish the floating-point environment represented

by the object pointed to by

envp

. The argument

envp

shall point to an object set by a

call to

fegetenv

or

feholdexcept

, or equal a floating-point environment macro.

Note that

fesetenv

merely installs the state of the floating-point status flags

represented through its argument, and does not raise these floating-point exceptions.

Returns

3

The

fesetenv

function returns zero if the environment was successfully established.

Otherwise, it returns a nonzero value.

7.6.4.4 The

feupdateenv

function

Synopsis

1

#include <fenv.h>

int feupdateenv(const fenv_t *envp);

Description

2

The

feupdateenv

function attempts to save the currently raised floating-point

exceptions in its automatic storage, install the floating-point environment represented by
the object pointed to by

envp

, and then raise the saved floating-point exceptions. The

argument

envp

shall point to an object set by a call to

feholdexcept

or

fegetenv

,

or equal a floating-point environment macro.

Returns

3

The

feupdateenv

function returns zero if all the actions were successfully carried out.

Otherwise, it returns a nonzero value.

189) IEC 60559 systems have a default non-stop mode, and typically at least one other mode for trap

handling or aborting; if the system provides only the non-stop mode then installing it is trivial. For
such systems, the

feholdexcept

function can be used in conjunction with the

feupdateenv

function to write routines that hide spurious floating-point exceptions from their callers.

§7.6.4.4 Library

195

4

EXAMPLE Save, set, and restore the rounding direction. Report an error and abort if setting the
rounding direction fails.

#include <fenv.h>

#include <assert.h>

void f(int round_dir)

{

#pragma STDC FENV_ACCESS ON

int save_round;

int setround_ok;

save_round = fegetround();

setround_ok = fesetround(round_dir);

assert(setround_ok == 0);

/*

...

*/

fesetround(save_round);

/*

...

*/

}

7.6.4 Environment

1

The functions in this section manage the floating-point environment — status flags and
control modes — as one entity.

7.6.4.1 The

fegetenv

function

Synopsis

1

#include <fenv.h>

int fegetenv(fenv_t *envp);

Description

2

The

fegetenv

function attempts to store the current floating-point environment in the

object pointed to by

envp

.

Returns

3

The

fegetenv

function returns zero if the environment was successfully stored.

Otherwise, it returns a nonzero value.

7.6.4.2 The

feholdexcept

function

Synopsis

1

#include <fenv.h>

int feholdexcept(fenv_t *envp);

Description

2

The

feholdexcept

function saves the current floating-point environment in the object

pointed to by

envp

, clears the floating-point status flags, and then installs a non-stop

(continue on floating-point exceptions) mode, if available, for all floating-point
exceptions.

189)

194 Library

§7.6.4.2

 

 

 

 

 

 

 

 

Content      ..      1       2         ..

 

 

///////////////////////////////////////