下面的头文件来自CodeBlocks 13.12配套的MINGW,主要是为了方便好奇的同学。
第一个文件是stdio.h。
EOF在第47行
printf在第294行
FILE在第139行
stdin在第158行
1 /* 2 * stdio.h 3 * This file has no copyright assigned and is placed in the Public Domain. 4 * This file is a part of the mingw-runtime package. 5 * No warranty is given; refer to the file DISCLAIMER within the package. 6 * 7 * Definitions of types and prototypes of functions for standard input and 8 * output. 9 * 10 * NOTE: The file manipulation functions provided by Microsoft seem to 11 * work with either slash (/) or backslash (\) as the directory separator. 12 * 13 */ 14 15 #ifndef _STDIO_H_ 16 #define _STDIO_H_ 17 18 /* All the headers include this file. */ 19 #include <_mingw.h> 20 21 #ifndef RC_INVOKED 22 #define __need_size_t 23 #define __need_NULL 24 #define __need_wchar_t 25 #define __need_wint_t 26 #include <stddef.h> 27 #define __need___va_list 28 #include <stdarg.h> 29 #endif /* Not RC_INVOKED */ 30 31 32 /* Flags for the iobuf structure */ 33 #define _IOREAD 1 /* currently reading */ 34 #define _IOWRT 2 /* currently writing */ 35 #define _IORW 0x0080 /* opened as "r+w" */ 36 37 38 /* 39 * The three standard file pointers provided by the run time library. 40 * NOTE: These will go to the bit-bucket silently in GUI applications! 41 */ 42 #define STDIN_FILENO 0 43 #define STDOUT_FILENO 1 44 #define STDERR_FILENO 2 45 46 /* Returned by various functions on end of file condition or error. */ 47 #define EOF (-1) 48 49 /* 50 * The maximum length of a file name. You should use GetVolumeInformation 51 * instead of this constant. But hey, this works. 52 * Also defined in io.h. 53 */ 54 #ifndef FILENAME_MAX 55 #define FILENAME_MAX (260) 56 #endif 57 58 /* 59 * The maximum number of files that may be open at once. I have set this to 60 * a conservative number. The actual value may be higher. 61 */ 62 #define FOPEN_MAX (20) 63 64 /* After creating this many names, tmpnam and tmpfile return NULL */ 65 #define TMP_MAX 32767 66 /* 67 * Tmpnam, tmpfile and, sometimes, _tempnam try to create 68 * temp files in the root directory of the current drive 69 * (not in pwd, as suggested by some older MS doc's). 70 * Redefining these macros does not effect the CRT functions. 71 */ 72 #define _P_tmpdir "\\" 73 #ifndef __STRICT_ANSI__ 74 #define P_tmpdir _P_tmpdir 75 #endif 76 #define _wP_tmpdir L"\\" 77 78 /* 79 * The maximum size of name (including NUL) that will be put in the user 80 * supplied buffer caName for tmpnam. 81 * Inferred from the size of the static buffer returned by tmpnam 82 * when passed a NULL argument. May actually be smaller. 83 */ 84 #define L_tmpnam (16) 85 86 #define _IOFBF 0x0000 /* full buffered */ 87 #define _IOLBF 0x0040 /* line buffered */ 88 #define _IONBF 0x0004 /* not buffered */ 89 90 #define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */ 91 #define _IOEOF 0x0010 /* EOF reached on read */ 92 #define _IOERR 0x0020 /* I/O error from system */ 93 #define _IOSTRG 0x0040 /* Strange or no file descriptor */ 94 #ifdef _POSIX_SOURCE 95 # define _IOAPPEND 0x0200 96 #endif 97 /* 98 * The buffer size as used by setbuf such that it is equivalent to 99 * (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ). 100 */ 101 #define BUFSIZ 512 102 103 /* Constants for nOrigin indicating the position relative to which fseek 104 * sets the file position. Defined unconditionally since ISO and POSIX 105 * say they are defined here. */ 106 #define SEEK_SET 0 107 #define SEEK_CUR 1 108 #define SEEK_END 2 109 110 #ifndef RC_INVOKED 111 112 #ifndef __VALIST 113 #ifdef __GNUC__ 114 #define __VALIST __gnuc_va_list 115 #else 116 #define __VALIST char* 117 #endif 118 #endif /* defined __VALIST */ 119 120 /* 121 * The structure underlying the FILE type. 122 * 123 * Some believe that nobody in their right mind should make use of the 124 * internals of this structure. Provided by Pedro A. Aranda Gutiirrez 125 * <[email protected]>. 126 */ 127 #ifndef _FILE_DEFINED 128 #define _FILE_DEFINED 129 typedef struct _iobuf 130 { 131 char* _ptr; 132 int _cnt; 133 char* _base; 134 int _flag; 135 int _file; 136 int _charbuf; 137 int _bufsiz; 138 char* _tmpfname; 139 } FILE; 140 #endif /* Not _FILE_DEFINED */ 141 142 143 /* 144 * The standard file handles 145 */ 146 #ifndef __DECLSPEC_SUPPORTED 147 148 extern FILE (*_imp___iob)[]; /* A pointer to an array of FILE */ 149 150 #define _iob (*_imp___iob) /* An array of FILE */ 151 152 #else /* __DECLSPEC_SUPPORTED */ 153 154 __MINGW_IMPORT FILE _iob[]; /* An array of FILE imported from DLL. */ 155 156 #endif /* __DECLSPEC_SUPPORTED */ 157 158 #define stdin (&_iob[STDIN_FILENO]) 159 #define stdout (&_iob[STDOUT_FILENO]) 160 #define stderr (&_iob[STDERR_FILENO]) 161 162 #ifdef __cplusplus 163 extern "C" { 164 #endif 165 166 /* 167 * File Operations 168 */ 169 _CRTIMP FILE* __cdecl __MINGW_NOTHROW fopen (const char*, const char*); 170 _CRTIMP FILE* __cdecl __MINGW_NOTHROW freopen (const char*, const char*, FILE*); 171 _CRTIMP int __cdecl __MINGW_NOTHROW fflush (FILE*); 172 _CRTIMP int __cdecl __MINGW_NOTHROW fclose (FILE*); 173 /* MS puts remove & rename (but not wide versions) in io.h also */ 174 _CRTIMP int __cdecl __MINGW_NOTHROW remove (const char*); 175 _CRTIMP int __cdecl __MINGW_NOTHROW rename (const char*, const char*); 176 _CRTIMP FILE* __cdecl __MINGW_NOTHROW tmpfile (void); 177 _CRTIMP char* __cdecl __MINGW_NOTHROW tmpnam (char*); 178 179 #ifndef __STRICT_ANSI__ 180 _CRTIMP char* __cdecl __MINGW_NOTHROW _tempnam (const char*, const char*); 181 _CRTIMP int __cdecl __MINGW_NOTHROW _rmtmp(void); 182 _CRTIMP int __cdecl __MINGW_NOTHROW _unlink (const char*); 183 184 #ifndef NO_OLDNAMES 185 _CRTIMP char* __cdecl __MINGW_NOTHROW tempnam (const char*, const char*); 186 _CRTIMP int __cdecl __MINGW_NOTHROW rmtmp(void); 187 _CRTIMP int __cdecl __MINGW_NOTHROW unlink (const char*); 188 #endif 189 #endif /* __STRICT_ANSI__ */ 190 191 _CRTIMP int __cdecl __MINGW_NOTHROW setvbuf (FILE*, char*, int, size_t); 192 193 _CRTIMP void __cdecl __MINGW_NOTHROW setbuf (FILE*, char*); 194 195 /* 196 * Formatted Output 197 * 198 * MSVCRT implementations are not ANSI C99 conformant... 199 * we offer these conforming alternatives from libmingwex.a 200 */ 201 #undef __mingw_stdio_redirect__ 202 #define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __mingw_##F 203 204 extern int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...); 205 extern int __mingw_stdio_redirect__(printf)(const char*, ...); 206 extern int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...); 207 extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...); 208 extern int __mingw_stdio_redirect__(vfprintf)(FILE*, const char*, __VALIST); 209 extern int __mingw_stdio_redirect__(vprintf)(const char*, __VALIST); 210 extern int __mingw_stdio_redirect__(vsprintf)(char*, const char*, __VALIST); 211 extern int __mingw_stdio_redirect__(vsnprintf)(char*, size_t, const char*, __VALIST); 212 213 #if __USE_MINGW_ANSI_STDIO 214 /* 215 * User has expressed a preference for C99 conformance... 216 */ 217 # undef __mingw_stdio_redirect__ 218 # ifdef __cplusplus 219 /* 220 * For C++ we use inline implementations, to avoid interference 221 * with namespace qualification, which may result from using #defines. 222 */ 223 # define __mingw_stdio_redirect__ inline __cdecl __MINGW_NOTHROW 224 225 # elif defined __GNUC__ 226 /* 227 * FIXME: Is there any GCC version prerequisite here? 228 * 229 * We also prefer inline implementations for C, when we can be confident 230 * that the GNU specific __inline__ mechanism is supported. 231 */ 232 # define __mingw_stdio_redirect__ static __inline__ __cdecl __MINGW_NOTHROW 233 234 # else 235 /* 236 * Can't use inlines; fall back on module local static stubs. 237 */ 238 # define __mingw_stdio_redirect__ static __cdecl __MINGW_NOTHROW 239 # endif 240 241 __mingw_stdio_redirect__ 242 int fprintf (FILE *__stream, const char *__format, ...) 243 { 244 register int __retval; 245 __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format ); 246 __retval = __mingw_vfprintf( __stream, __format, __local_argv ); 247 __builtin_va_end( __local_argv ); 248 return __retval; 249 } 250 251 __mingw_stdio_redirect__ 252 int printf (const char *__format, ...) 253 { 254 register int __retval; 255 __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format ); 256 __retval = __mingw_vprintf( __format, __local_argv ); 257 __builtin_va_end( __local_argv ); 258 return __retval; 259 } 260 261 __mingw_stdio_redirect__ 262 int sprintf (char *__stream, const char *__format, ...) 263 { 264 register int __retval; 265 __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format ); 266 __retval = __mingw_vsprintf( __stream, __format, __local_argv ); 267 __builtin_va_end( __local_argv ); 268 return __retval; 269 } 270 271 __mingw_stdio_redirect__ 272 int vfprintf (FILE *__stream, const char *__format, __VALIST __local_argv) 273 { 274 return __mingw_vfprintf( __stream, __format, __local_argv ); 275 } 276 277 __mingw_stdio_redirect__ 278 int vprintf (const char *__format, __VALIST __local_argv) 279 { 280 return __mingw_vprintf( __format, __local_argv ); 281 } 282 283 __mingw_stdio_redirect__ 284 int vsprintf (char *__stream, const char *__format, __VALIST __local_argv) 285 { 286 return __mingw_vsprintf( __stream, __format, __local_argv ); 287 } 288 289 #else 290 /* 291 * Default configuration: simply direct all calls to MSVCRT... 292 */ 293 _CRTIMP int __cdecl __MINGW_NOTHROW fprintf (FILE*, const char*, ...); 294 _CRTIMP int __cdecl __MINGW_NOTHROW printf (const char*, ...); 295 _CRTIMP int __cdecl __MINGW_NOTHROW sprintf (char*, const char*, ...); 296 _CRTIMP int __cdecl __MINGW_NOTHROW vfprintf (FILE*, const char*, __VALIST); 297 _CRTIMP int __cdecl __MINGW_NOTHROW vprintf (const char*, __VALIST); 298 _CRTIMP int __cdecl __MINGW_NOTHROW vsprintf (char*, const char*, __VALIST); 299 300 #endif 301 /* 302 * Regardless of user preference, always offer these alternative 303 * entry points, for direct access to the MSVCRT implementations. 304 */ 305 #undef __mingw_stdio_redirect__ 306 #define __mingw_stdio_redirect__(F) __cdecl __MINGW_NOTHROW __msvcrt_##F 307 308 _CRTIMP int __mingw_stdio_redirect__(fprintf)(FILE*, const char*, ...); 309 _CRTIMP int __mingw_stdio_redirect__(printf)(const char*, ...); 310 _CRTIMP int __mingw_stdio_redirect__(sprintf)(char*, const char*, ...); 311 _CRTIMP int __mingw_stdio_redirect__(vfprintf)(FILE*, const char*, __VALIST); 312 _CRTIMP int __mingw_stdio_redirect__(vprintf)(const char*, __VALIST); 313 _CRTIMP int __mingw_stdio_redirect__(vsprintf)(char*, const char*, __VALIST); 314 315 #undef __mingw_stdio_redirect__ 316 317 /* The following pair ALWAYS refer to the MSVCRT implementations... 318 */ 319 _CRTIMP int __cdecl __MINGW_NOTHROW _snprintf (char*, size_t, const char*, ...); 320 _CRTIMP int __cdecl __MINGW_NOTHROW _vsnprintf (char*, size_t, const char*, __VALIST); 321 _CRTIMP int __cdecl __MINGW_NOTHROW _vscprintf (const char*, __VALIST); 322 323 #ifndef __NO_ISOCEXT /* externs in libmingwex.a */ 324 /* 325 * Microsoft does not provide implementations for the following, 326 * which are required by C99. Note in particular that the corresponding 327 * Microsoft implementations of _snprintf() and _vsnprintf() are *not* 328 * compatible with C99, but the following are; if you want the MSVCRT 329 * behaviour, you *must* use the Microsoft uglified names. 330 */ 331 int __cdecl __MINGW_NOTHROW snprintf (char *, size_t, const char *, ...); 332 int __cdecl __MINGW_NOTHROW vsnprintf (char *, size_t, const char *, __VALIST); 333 334 int __cdecl __MINGW_NOTHROW vscanf (const char * __restrict__, __VALIST); 335 int __cdecl __MINGW_NOTHROW vfscanf (FILE * __restrict__, const char * __restrict__, 336 __VALIST); 337 int __cdecl __MINGW_NOTHROW vsscanf (const char * __restrict__, 338 const char * __restrict__, __VALIST); 339 340 #endif /* !__NO_ISOCEXT */ 341 342 /* 343 * Formatted Input 344 */ 345 346 _CRTIMP int __cdecl __MINGW_NOTHROW fscanf (FILE*, const char*, ...); 347 _CRTIMP int __cdecl __MINGW_NOTHROW scanf (const char*, ...); 348 _CRTIMP int __cdecl __MINGW_NOTHROW sscanf (const char*, const char*, ...); 349 /* 350 * Character Input and Output Functions 351 */ 352 353 _CRTIMP int __cdecl __MINGW_NOTHROW fgetc (FILE*); 354 _CRTIMP char* __cdecl __MINGW_NOTHROW fgets (char*, int, FILE*); 355 _CRTIMP int __cdecl __MINGW_NOTHROW fputc (int, FILE*); 356 _CRTIMP int __cdecl __MINGW_NOTHROW fputs (const char*, FILE*); 357 _CRTIMP char* __cdecl __MINGW_NOTHROW gets (char*); 358 _CRTIMP int __cdecl __MINGW_NOTHROW puts (const char*); 359 _CRTIMP int __cdecl __MINGW_NOTHROW ungetc (int, FILE*); 360 361 /* Traditionally, getc and putc are defined as macros. but the 362 standard doesn't say that they must be macros. 363 We use inline functions here to allow the fast versions 364 to be used in C++ with namespace qualification, eg., ::getc. 365 366 _filbuf and _flsbuf are not thread-safe. */ 367 _CRTIMP int __cdecl __MINGW_NOTHROW _filbuf (FILE*); 368 _CRTIMP int __cdecl __MINGW_NOTHROW _flsbuf (int, FILE*); 369 370 #if !defined _MT 371 372 __CRT_INLINE int __cdecl __MINGW_NOTHROW getc (FILE* __F) 373 { 374 return (--__F->_cnt >= 0) 375 ? (int) (unsigned char) *__F->_ptr++ 376 : _filbuf (__F); 377 } 378 379 __CRT_INLINE int __cdecl __MINGW_NOTHROW putc (int __c, FILE* __F) 380 { 381 return (--__F->_cnt >= 0) 382 ? (int) (unsigned char) (*__F->_ptr++ = (char)__c) 383 : _flsbuf (__c, __F); 384 } 385 386 __CRT_INLINE int __cdecl __MINGW_NOTHROW getchar (void) 387 { 388 return (--stdin->_cnt >= 0) 389 ? (int) (unsigned char) *stdin->_ptr++ 390 : _filbuf (stdin); 391 } 392 393 __CRT_INLINE int __cdecl __MINGW_NOTHROW putchar(int __c) 394 { 395 return (--stdout->_cnt >= 0) 396 ? (int) (unsigned char) (*stdout->_ptr++ = (char)__c) 397 : _flsbuf (__c, stdout);} 398 399 #else /* Use library functions. */ 400 401 _CRTIMP int __cdecl __MINGW_NOTHROW getc (FILE*); 402 _CRTIMP int __cdecl __MINGW_NOTHROW putc (int, FILE*); 403 _CRTIMP int __cdecl __MINGW_NOTHROW getchar (void); 404 _CRTIMP int __cdecl __MINGW_NOTHROW putchar (int); 405 406 #endif 407 408 /* 409 * Direct Input and Output Functions 410 */ 411 412 _CRTIMP size_t __cdecl __MINGW_NOTHROW fread (void*, size_t, size_t, FILE*); 413 _CRTIMP size_t __cdecl __MINGW_NOTHROW fwrite (const void*, size_t, size_t, FILE*); 414 415 /* 416 * File Positioning Functions 417 */ 418 419 _CRTIMP int __cdecl __MINGW_NOTHROW fseek (FILE*, long, int); 420 _CRTIMP long __cdecl __MINGW_NOTHROW ftell (FILE*); 421 _CRTIMP void __cdecl __MINGW_NOTHROW rewind (FILE*); 422 423 #if __MSVCRT_VERSION__ >= 0x800 424 _CRTIMP int __cdecl __MINGW_NOTHROW _fseek_nolock (FILE*, long, int); 425 _CRTIMP long __cdecl __MINGW_NOTHROW _ftell_nolock (FILE*); 426 427 _CRTIMP int __cdecl __MINGW_NOTHROW _fseeki64 (FILE*, __int64, int); 428 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _ftelli64 (FILE*); 429 _CRTIMP int __cdecl __MINGW_NOTHROW _fseeki64_nolock (FILE*, __int64, int); 430 _CRTIMP __int64 __cdecl __MINGW_NOTHROW _ftelli64_nolock (FILE*); 431 #endif 432 433 #ifdef __USE_MINGW_FSEEK /* These are in libmingwex.a */ 434 /* 435 * Workaround for limitations on win9x where a file contents are 436 * not zero'd out if you seek past the end and then write. 437 */ 438 439 int __cdecl __MINGW_NOTHROW __mingw_fseek (FILE *, long, int); 440 size_t __cdecl __MINGW_NOTHROW __mingw_fwrite (const void*, size_t, size_t, FILE*); 441 #define fseek(fp, offset, whence) __mingw_fseek(fp, offset, whence) 442 #define fwrite(buffer, size, count, fp) __mingw_fwrite(buffer, size, count, fp) 443 #endif /* __USE_MINGW_FSEEK */ 444 445 /* 446 * An opaque data type used for storing file positions... The contents of 447 * this type are unknown, but we (the compiler) need to know the size 448 * because the programmer using fgetpos and fsetpos will be setting aside 449 * storage for fpos_t structres. Actually I tested using a byte array and 450 * it is fairly evident that the fpos_t type is a long (in CRTDLL.DLL). 451 * Perhaps an unsigned long? TODO? It's definitely a 64-bit number in 452 * MSVCRT however, and for now `long long' will do. 453 */ 454 #ifdef __MSVCRT__ 455 typedef long long fpos_t; 456 #else 457 typedef long fpos_t; 458 #endif 459 460 _CRTIMP int __cdecl __MINGW_NOTHROW fgetpos (FILE*, fpos_t*); 461 _CRTIMP int __cdecl __MINGW_NOTHROW fsetpos (FILE*, const fpos_t*); 462 463 /* 464 * Error Functions 465 */ 466 467 _CRTIMP int __cdecl __MINGW_NOTHROW feof (FILE*); 468 _CRTIMP int __cdecl __MINGW_NOTHROW ferror (FILE*); 469 470 #ifdef __cplusplus 471 inline int __cdecl __MINGW_NOTHROW feof (FILE* __F) 472 { return __F->_flag & _IOEOF; } 473 inline int __cdecl __MINGW_NOTHROW ferror (FILE* __F) 474 { return __F->_flag & _IOERR; } 475 #else 476 #define feof(__F) ((__F)->_flag & _IOEOF) 477 #define ferror(__F) ((__F)->_flag & _IOERR) 478 #endif 479 480 _CRTIMP void __cdecl __MINGW_NOTHROW clearerr (FILE*); 481 _CRTIMP void __cdecl __MINGW_NOTHROW perror (const char*); 482 483 484 #ifndef __STRICT_ANSI__ 485 /* 486 * Pipes 487 */ 488 _CRTIMP FILE* __cdecl __MINGW_NOTHROW _popen (const char*, const char*); 489 _CRTIMP int __cdecl __MINGW_NOTHROW _pclose (FILE*); 490 491 #ifndef NO_OLDNAMES 492 _CRTIMP FILE* __cdecl __MINGW_NOTHROW popen (const char*, const char*); 493 _CRTIMP int __cdecl __MINGW_NOTHROW pclose (FILE*); 494 #endif 495 496 /* 497 * Other Non ANSI functions 498 */ 499 _CRTIMP int __cdecl __MINGW_NOTHROW _flushall (void); 500 _CRTIMP int __cdecl __MINGW_NOTHROW _fgetchar (void); 501 _CRTIMP int __cdecl __MINGW_NOTHROW _fputchar (int); 502 _CRTIMP FILE* __cdecl __MINGW_NOTHROW _fdopen (int, const char*); 503 _CRTIMP int __cdecl __MINGW_NOTHROW _fileno (FILE*); 504 _CRTIMP int __cdecl __MINGW_NOTHROW _fcloseall (void); 505 _CRTIMP FILE* __cdecl __MINGW_NOTHROW _fsopen (const char*, const char*, int); 506 #ifdef __MSVCRT__ 507 _CRTIMP int __cdecl __MINGW_NOTHROW _getmaxstdio (void); 508 _CRTIMP int __cdecl __MINGW_NOTHROW _setmaxstdio (int); 509 #endif 510 511 #if __MSVCRT_VERSION__ >= 0x800 512 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _get_output_format (void); 513 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _set_output_format (unsigned int); 514 515 #define _TWO_DIGIT_EXPONENT 1 516 517 _CRTIMP int __cdecl __MINGW_NOTHROW _get_printf_count_output (void); 518 _CRTIMP int __cdecl __MINGW_NOTHROW _set_printf_count_output (int); 519 #endif 520 521 #ifndef _NO_OLDNAMES 522 _CRTIMP int __cdecl __MINGW_NOTHROW fgetchar (void); 523 _CRTIMP int __cdecl __MINGW_NOTHROW fputchar (int); 524 _CRTIMP FILE* __cdecl __MINGW_NOTHROW fdopen (int, const char*); 525 _CRTIMP int __cdecl __MINGW_NOTHROW fileno (FILE*); 526 #endif /* Not _NO_OLDNAMES */ 527 528 #define _fileno(__F) ((__F)->_file) 529 #ifndef _NO_OLDNAMES 530 #define fileno(__F) ((__F)->_file) 531 #endif 532 533 #if defined (__MSVCRT__) && !defined (__NO_MINGW_LFS) 534 #include <sys/types.h> 535 __CRT_INLINE FILE* __cdecl __MINGW_NOTHROW fopen64 (const char* filename, const char* mode) 536 { 537 return fopen (filename, mode); 538 } 539 540 int __cdecl __MINGW_NOTHROW fseeko64 (FILE*, off64_t, int); 541 542 #ifdef __USE_MINGW_FSEEK 543 int __cdecl __MINGW_NOTHROW __mingw_fseeko64 (FILE *, off64_t, int); 544 #define fseeko64(fp, offset, whence) __mingw_fseeko64(fp, offset, whence) 545 #endif 546 547 __CRT_INLINE off64_t __cdecl __MINGW_NOTHROW ftello64 (FILE * stream) 548 { 549 fpos_t pos; 550 if (fgetpos(stream, &pos)) 551 return -1LL; 552 else 553 return ((off64_t) pos); 554 } 555 #endif /* __NO_MINGW_LFS */ 556 557 #endif /* Not __STRICT_ANSI__ */ 558 559 /* Wide versions */ 560 561 #ifndef _WSTDIO_DEFINED 562 /* also in wchar.h - keep in sync */ 563 _CRTIMP int __cdecl __MINGW_NOTHROW fwprintf (FILE*, const wchar_t*, ...); 564 _CRTIMP int __cdecl __MINGW_NOTHROW wprintf (const wchar_t*, ...); 565 _CRTIMP int __cdecl __MINGW_NOTHROW _snwprintf (wchar_t*, size_t, const wchar_t*, ...); 566 _CRTIMP int __cdecl __MINGW_NOTHROW vfwprintf (FILE*, const wchar_t*, __VALIST); 567 _CRTIMP int __cdecl __MINGW_NOTHROW vwprintf (const wchar_t*, __VALIST); 568 _CRTIMP int __cdecl __MINGW_NOTHROW _vsnwprintf (wchar_t*, size_t, const wchar_t*, __VALIST); 569 _CRTIMP int __cdecl __MINGW_NOTHROW _vscwprintf (const wchar_t*, __VALIST); 570 _CRTIMP int __cdecl __MINGW_NOTHROW fwscanf (FILE*, const wchar_t*, ...); 571 _CRTIMP int __cdecl __MINGW_NOTHROW wscanf (const wchar_t*, ...); 572 _CRTIMP int __cdecl __MINGW_NOTHROW swscanf (const wchar_t*, const wchar_t*, ...); 573 _CRTIMP wint_t __cdecl __MINGW_NOTHROW fgetwc (FILE*); 574 _CRTIMP wint_t __cdecl __MINGW_NOTHROW fputwc (wchar_t, FILE*); 575 _CRTIMP wint_t __cdecl __MINGW_NOTHROW ungetwc (wchar_t, FILE*); 576 577 /* These differ from the ISO C prototypes, which have a maxlen parameter (like snprintf). */ 578 #ifndef __STRICT_ANSI__ 579 _CRTIMP int __cdecl __MINGW_NOTHROW swprintf (wchar_t*, const wchar_t*, ...); 580 _CRTIMP int __cdecl __MINGW_NOTHROW vswprintf (wchar_t*, const wchar_t*, __VALIST); 581 #endif 582 583 #ifdef __MSVCRT__ 584 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW fgetws (wchar_t*, int, FILE*); 585 _CRTIMP int __cdecl __MINGW_NOTHROW fputws (const wchar_t*, FILE*); 586 _CRTIMP wint_t __cdecl __MINGW_NOTHROW getwc (FILE*); 587 _CRTIMP wint_t __cdecl __MINGW_NOTHROW getwchar (void); 588 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _getws (wchar_t*); 589 _CRTIMP wint_t __cdecl __MINGW_NOTHROW putwc (wint_t, FILE*); 590 _CRTIMP int __cdecl __MINGW_NOTHROW _putws (const wchar_t*); 591 _CRTIMP wint_t __cdecl __MINGW_NOTHROW putwchar (wint_t); 592 _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfdopen(int, const wchar_t *); 593 _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfopen (const wchar_t*, const wchar_t*); 594 _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfreopen (const wchar_t*, const wchar_t*, FILE*); 595 _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfsopen (const wchar_t*, const wchar_t*, int); 596 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtmpnam (wchar_t*); 597 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtempnam (const wchar_t*, const wchar_t*); 598 _CRTIMP int __cdecl __MINGW_NOTHROW _wrename (const wchar_t*, const wchar_t*); 599 _CRTIMP int __cdecl __MINGW_NOTHROW _wremove (const wchar_t*); 600 _CRTIMP void __cdecl __MINGW_NOTHROW _wperror (const wchar_t*); 601 _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wpopen (const wchar_t*, const wchar_t*); 602 #endif /* __MSVCRT__ */ 603 604 #ifndef __NO_ISOCEXT /* externs in libmingwex.a */ 605 int __cdecl __MINGW_NOTHROW snwprintf (wchar_t* s, size_t n, const wchar_t* format, ...); 606 int __cdecl __MINGW_NOTHROW vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg); 607 #ifndef __NO_INLINE__ 608 __CRT_INLINE int __cdecl __MINGW_NOTHROW 609 vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg) 610 { return _vsnwprintf ( s, n, format, arg);} 611 #endif 612 int __cdecl __MINGW_NOTHROW vwscanf (const wchar_t * __restrict__, __VALIST); 613 int __cdecl __MINGW_NOTHROW vfwscanf (FILE * __restrict__, 614 const wchar_t * __restrict__, __VALIST); 615 int __cdecl __MINGW_NOTHROW vswscanf (const wchar_t * __restrict__, 616 const wchar_t * __restrict__, __VALIST); 617 #endif 618 619 #define _WSTDIO_DEFINED 620 #endif /* _WSTDIO_DEFINED */ 621 622 #ifndef __STRICT_ANSI__ 623 #ifdef __MSVCRT__ 624 #ifndef NO_OLDNAMES 625 _CRTIMP FILE* __cdecl __MINGW_NOTHROW wpopen (const wchar_t*, const wchar_t*); 626 #endif /* not NO_OLDNAMES */ 627 #endif /* MSVCRT runtime */ 628 629 /* 630 * Other Non ANSI wide functions 631 */ 632 _CRTIMP wint_t __cdecl __MINGW_NOTHROW _fgetwchar (void); 633 _CRTIMP wint_t __cdecl __MINGW_NOTHROW _fputwchar (wint_t); 634 _CRTIMP int __cdecl __MINGW_NOTHROW _getw (FILE*); 635 _CRTIMP int __cdecl __MINGW_NOTHROW _putw (int, FILE*); 636 637 #ifndef _NO_OLDNAMES 638 _CRTIMP wint_t __cdecl __MINGW_NOTHROW fgetwchar (void); 639 _CRTIMP wint_t __cdecl __MINGW_NOTHROW fputwchar (wint_t); 640 _CRTIMP int __cdecl __MINGW_NOTHROW getw (FILE*); 641 _CRTIMP int __cdecl __MINGW_NOTHROW putw (int, FILE*); 642 #endif /* Not _NO_OLDNAMES */ 643 644 #endif /* __STRICT_ANSI */ 645 646 #ifdef __cplusplus 647 } 648 #endif 649 650 #endif /* Not RC_INVOKED */ 651 652 #endif /* _STDIO_H_ */
第二个头文件是math.h
1 /* 2 * math.h 3 * This file has no copyright assigned and is placed in the Public Domain. 4 * This file is a part of the mingw-runtime package. 5 * No warranty is given; refer to the file DISCLAIMER within the package. 6 * 7 * Mathematical functions. 8 * 9 */ 10 11 12 #ifndef _MATH_H_ 13 #define _MATH_H_ 14 15 #if __GNUC__ >= 3 16 #pragma GCC system_header 17 #endif 18 19 /* All the headers include this file. */ 20 #include <_mingw.h> 21 22 /* 23 * Types for the _exception structure. 24 */ 25 26 #define _DOMAIN 1 /* domain error in argument */ 27 #define _SING 2 /* singularity */ 28 #define _OVERFLOW 3 /* range overflow */ 29 #define _UNDERFLOW 4 /* range underflow */ 30 #define _TLOSS 5 /* total loss of precision */ 31 #define _PLOSS 6 /* partial loss of precision */ 32 33 /* 34 * Exception types with non-ANSI names for compatibility. 35 */ 36 37 #ifndef __STRICT_ANSI__ 38 #ifndef _NO_OLDNAMES 39 40 #define DOMAIN _DOMAIN 41 #define SING _SING 42 #define OVERFLOW _OVERFLOW 43 #define UNDERFLOW _UNDERFLOW 44 #define TLOSS _TLOSS 45 #define PLOSS _PLOSS 46 47 #endif /* Not _NO_OLDNAMES */ 48 #endif /* Not __STRICT_ANSI__ */ 49 50 51 /* Traditional/XOPEN math constants (double precison) */ 52 #ifndef __STRICT_ANSI__ 53 #define M_E 2.7182818284590452354 54 #define M_LOG2E 1.4426950408889634074 55 #define M_LOG10E 0.43429448190325182765 56 #define M_LN2 0.69314718055994530942 57 #define M_LN10 2.30258509299404568402 58 #define M_PI 3.14159265358979323846 59 #define M_PI_2 1.57079632679489661923 60 #define M_PI_4 0.78539816339744830962 61 #define M_1_PI 0.31830988618379067154 62 #define M_2_PI 0.63661977236758134308 63 #define M_2_SQRTPI 1.12837916709551257390 64 #define M_SQRT2 1.41421356237309504880 65 #define M_SQRT1_2 0.70710678118654752440 66 #endif 67 68 /* These are also defined in Mingw float.h; needed here as well to work 69 around GCC build issues. */ 70 #ifndef __STRICT_ANSI__ 71 #ifndef __MINGW_FPCLASS_DEFINED 72 #define __MINGW_FPCLASS_DEFINED 1 73 /* IEEE 754 classication */ 74 #define _FPCLASS_SNAN 0x0001 /* Signaling "Not a Number" */ 75 #define _FPCLASS_QNAN 0x0002 /* Quiet "Not a Number" */ 76 #define _FPCLASS_NINF 0x0004 /* Negative Infinity */ 77 #define _FPCLASS_NN 0x0008 /* Negative Normal */ 78 #define _FPCLASS_ND 0x0010 /* Negative Denormal */ 79 #define _FPCLASS_NZ 0x0020 /* Negative Zero */ 80 #define _FPCLASS_PZ 0x0040 /* Positive Zero */ 81 #define _FPCLASS_PD 0x0080 /* Positive Denormal */ 82 #define _FPCLASS_PN 0x0100 /* Positive Normal */ 83 #define _FPCLASS_PINF 0x0200 /* Positive Infinity */ 84 #endif /* __MINGW_FPCLASS_DEFINED */ 85 #endif /* Not __STRICT_ANSI__ */ 86 87 #ifndef RC_INVOKED 88 89 #ifdef __cplusplus 90 extern "C" { 91 #endif 92 93 /* 94 * HUGE_VAL is returned by strtod when the value would overflow the 95 * representation of 'double'. There are other uses as well. 96 * 97 * __imp__HUGE is a pointer to the actual variable _HUGE in 98 * MSVCRT.DLL. If we used _HUGE directly we would get a pointer 99 * to a thunk function. 100 * 101 * NOTE: The CRTDLL version uses _HUGE_dll instead. 102 */ 103 104 #if __MINGW_GNUC_PREREQ(3, 3) 105 #define HUGE_VAL __builtin_huge_val() 106 #else 107 108 #ifndef __DECLSPEC_SUPPORTED 109 110 #ifdef __MSVCRT__ 111 extern double* _imp___HUGE; 112 #define HUGE_VAL (*_imp___HUGE) 113 #else 114 /* CRTDLL */ 115 extern double* _imp___HUGE_dll; 116 #define HUGE_VAL (*_imp___HUGE_dll) 117 #endif 118 119 #else /* __DECLSPEC_SUPPORTED */ 120 121 #ifdef __MSVCRT__ 122 __MINGW_IMPORT double _HUGE; 123 #define HUGE_VAL _HUGE 124 #else 125 /* CRTDLL */ 126 __MINGW_IMPORT double _HUGE_dll; 127 #define HUGE_VAL _HUGE_dll 128 #endif 129 130 #endif /* __DECLSPEC_SUPPORTED */ 131 #endif /* __MINGW_GNUC_PREREQ(3, 3) */ 132 133 134 struct _exception 135 { 136 int type; 137 char *name; 138 double arg1; 139 double arg2; 140 double retval; 141 }; 142 143 _CRTIMP double __cdecl sin (double); 144 _CRTIMP double __cdecl cos (double); 145 _CRTIMP double __cdecl tan (double); 146 _CRTIMP double __cdecl sinh (double); 147 _CRTIMP double __cdecl cosh (double); 148 _CRTIMP double __cdecl tanh (double); 149 _CRTIMP double __cdecl asin (double); 150 _CRTIMP double __cdecl acos (double); 151 _CRTIMP double __cdecl atan (double); 152 _CRTIMP double __cdecl atan2 (double, double); 153 _CRTIMP double __cdecl exp (double); 154 _CRTIMP double __cdecl log (double); 155 _CRTIMP double __cdecl log10 (double); 156 _CRTIMP double __cdecl pow (double, double); 157 _CRTIMP double __cdecl sqrt (double); 158 _CRTIMP double __cdecl ceil (double); 159 _CRTIMP double __cdecl floor (double); 160 _CRTIMP double __cdecl fabs (double); 161 _CRTIMP double __cdecl ldexp (double, int); 162 _CRTIMP double __cdecl frexp (double, int*); 163 _CRTIMP double __cdecl modf (double, double*); 164 _CRTIMP double __cdecl fmod (double, double); 165 166 /* Excess precision when using a 64-bit mantissa for FPU math ops can 167 cause unexpected results with some of the MSVCRT math functions. For 168 example, unless the function return value is stored (truncating to 169 53-bit mantissa), calls to pow with both x and y as integral values 170 sometimes produce a non-integral result. 171 One workaround is to reset the FPU env to 53-bit mantissa 172 by a call to fesetenv (FE_PC53_ENV). Amother is to force storage 173 of the return value of individual math functions using wrappers. 174 NB, using these wrappers will disable builtin math functions and 175 hence disable the folding of function results at compile time when 176 arguments are constant. */ 177 178 #if 0 179 #define __DEFINE_FLOAT_STORE_MATHFN_D1(fn1) \ 180 static __inline__ double \ 181 __float_store_ ## fn1 (double x) \ 182 { \ 183 __volatile__ double res = (fn1) (x); \ 184 return res; \ 185 } 186 187 #define __DEFINE_FLOAT_STORE_MATHFN_D2(fn2) \ 188 static __inline__ double \ 189 __float_store_ ## fn2 (double x, double y) \ 190 { \ 191 __volatile__ double res = (fn2) (x, y); \ 192 return res; \ 193 } 194 #endif 195 196 /* For example, here is how to force the result of the pow function 197 to be stored: */ 198 #if 0 199 #undef pow 200 /* Define the ___float_store_pow function and use it instead of pow(). */ 201 __DEFINE_FLOAT_STORE_MATHFN_D2 (pow) 202 #define pow __float_store_pow 203 #endif 204 205 #ifndef __STRICT_ANSI__ 206 207 /* Complex number (for _cabs). This is the MS version. The ISO 208 C99 counterpart _Complex is an intrinsic type in GCC and 209 'complex' is defined as a macro. See complex.h */ 210 struct _complex 211 { 212 double x; /* Real part */ 213 double y; /* Imaginary part */ 214 }; 215 216 _CRTIMP double __cdecl _cabs (struct _complex); 217 218 _CRTIMP double __cdecl _hypot (double, double); 219 _CRTIMP double __cdecl _j0 (double); 220 _CRTIMP double __cdecl _j1 (double); 221 _CRTIMP double __cdecl _jn (int, double); 222 _CRTIMP double __cdecl _y0 (double); 223 _CRTIMP double __cdecl _y1 (double); 224 _CRTIMP double __cdecl _yn (int, double); 225 _CRTIMP int __cdecl _matherr (struct _exception *); 226 227 /* These are also declared in Mingw float.h; needed here as well to work 228 around GCC build issues. */ 229 /* BEGIN FLOAT.H COPY */ 230 /* 231 * IEEE recommended functions 232 */ 233 234 _CRTIMP double __cdecl _chgsign (double); 235 _CRTIMP double __cdecl _copysign (double, double); 236 _CRTIMP double __cdecl _logb (double); 237 _CRTIMP double __cdecl _nextafter (double, double); 238 _CRTIMP double __cdecl _scalb (double, long); 239 240 _CRTIMP int __cdecl _finite (double); 241 _CRTIMP int __cdecl _fpclass (double); 242 _CRTIMP int __cdecl _isnan (double); 243 244 /* END FLOAT.H COPY */ 245 246 247 /* 248 * Non-underscored versions of non-ANSI functions. 249 * These reside in liboldnames.a. 250 */ 251 252 #if !defined (_NO_OLDNAMES) 253 254 _CRTIMP double __cdecl j0 (double); 255 _CRTIMP double __cdecl j1 (double); 256 _CRTIMP double __cdecl jn (int, double); 257 _CRTIMP double __cdecl y0 (double); 258 _CRTIMP double __cdecl y1 (double); 259 _CRTIMP double __cdecl yn (int, double); 260 261 _CRTIMP double __cdecl chgsign (double); 262 /* 263 * scalb() is a GCC built-in. 264 * Exclude this _scalb() stub; the semantics are incompatible 265 * with the built-in implementation. 266 * 267 _CRTIMP double __cdecl scalb (double, long); 268 * 269 */ 270 _CRTIMP int __cdecl finite (double); 271 _CRTIMP int __cdecl fpclass (double); 272 273 #define FP_SNAN _FPCLASS_SNAN 274 #define FP_QNAN _FPCLASS_QNAN 275 #define FP_NINF _FPCLASS_NINF 276 #define FP_PINF _FPCLASS_PINF 277 #define FP_NDENORM _FPCLASS_ND 278 #define FP_PDENORM _FPCLASS_PD 279 #define FP_NZERO _FPCLASS_NZ 280 #define FP_PZERO _FPCLASS_PZ 281 #define FP_NNORM _FPCLASS_NN 282 #define FP_PNORM _FPCLASS_PN 283 284 #endif /* Not _NO_OLDNAMES */ 285 286 /* This require msvcr70.dll or higher. */ 287 #if __MSVCRT_VERSION__ >= 0x0700 288 _CRTIMP int __cdecl _set_SSE2_enable (int); 289 #endif /* __MSVCRT_VERSION__ >= 0x0700 */ 290 291 292 #endif /* __STRICT_ANSI__ */ 293 294 295 #ifndef __NO_ISOCEXT 296 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \ 297 || !defined __STRICT_ANSI__ || defined __cplusplus 298 299 #if __MINGW_GNUC_PREREQ(3, 3) 300 #define HUGE_VALF __builtin_huge_valf() 301 #define HUGE_VALL __builtin_huge_vall() 302 #define INFINITY __builtin_inf() 303 #define NAN __builtin_nan("") 304 #else 305 extern const float __INFF; 306 #define HUGE_VALF __INFF 307 extern const long double __INFL; 308 #define HUGE_VALL __INFL 309 #define INFINITY HUGE_VALF 310 extern const double __QNAN; 311 #define NAN __QNAN 312 #endif /* __MINGW_GNUC_PREREQ(3, 3) */ 313 314 /* Use the compiler's builtin define for FLT_EVAL_METHOD to 315 set float_t and double_t. */ 316 #if defined(__FLT_EVAL_METHOD__) 317 # if ( __FLT_EVAL_METHOD__== 0) 318 typedef float float_t; 319 typedef double double_t; 320 # elif (__FLT_EVAL_METHOD__ == 1) 321 typedef double float_t; 322 typedef double double_t; 323 # elif (__FLT_EVAL_METHOD__ == 2) 324 typedef long double float_t; 325 typedef long double double_t; 326 #endif 327 #else /* ix87 FPU default */ 328 typedef long double float_t; 329 typedef long double double_t; 330 #endif 331 332 /* 7.12.3.1 */ 333 /* 334 Return values for fpclassify. 335 These are based on Intel x87 fpu condition codes 336 in the high byte of status word and differ from 337 the return values for MS IEEE 754 extension _fpclass() 338 */ 339 #define FP_NAN 0x0100 340 #define FP_NORMAL 0x0400 341 #define FP_INFINITE (FP_NAN | FP_NORMAL) 342 #define FP_ZERO 0x4000 343 #define FP_SUBNORMAL (FP_NORMAL | FP_ZERO) 344 /* 0x0200 is signbit mask */ 345 346 347 /* 348 We can't inline float or double, because we want to ensure truncation 349 to semantic type before classification. 350 (A normal long double value might become subnormal when 351 converted to double, and zero when converted to float.) 352 */ 353 354 extern int __cdecl __fpclassifyf (float); 355 extern int __cdecl __fpclassify (double); 356 extern int __cdecl __fpclassifyl (long double); 357 358 #ifndef __NO_INLINE__ 359 __CRT_INLINE int __cdecl __fpclassifyl (long double x){ 360 unsigned short sw; 361 __asm__ ("fxam; fstsw %%ax;" : "=a" (sw): "t" (x)); 362 return sw & (FP_NAN | FP_NORMAL | FP_ZERO ); 363 } 364 #endif 365 366 #define fpclassify(x) (sizeof (x) == sizeof (float) ? __fpclassifyf (x) \ 367 : sizeof (x) == sizeof (double) ? __fpclassify (x) \ 368 : __fpclassifyl (x)) 369 370 /* 7.12.3.2 */ 371 #define isfinite(x) ((fpclassify(x) & FP_NAN) == 0) 372 373 /* 7.12.3.3 */ 374 #define isinf(x) (fpclassify(x) == FP_INFINITE) 375 376 /* 7.12.3.4 */ 377 /* We don't need to worry about truncation here: 378 A NaN stays a NaN. */ 379 extern int __cdecl __isnan (double); 380 extern int __cdecl __isnanf (float); 381 extern int __cdecl __isnanl (long double); 382 #ifndef __NO_INLINE__ 383 __CRT_INLINE int __cdecl __isnan (double _x) 384 { 385 unsigned short sw; 386 __asm__ ("fxam;" 387 "fstsw %%ax": "=a" (sw) : "t" (_x)); 388 return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL)) 389 == FP_NAN; 390 } 391 392 __CRT_INLINE int __cdecl __isnanf (float _x) 393 { 394 unsigned short sw; 395 __asm__ ("fxam;" 396 "fstsw %%ax": "=a" (sw) : "t" (_x)); 397 return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL)) 398 == FP_NAN; 399 } 400 401 __CRT_INLINE int __cdecl __isnanl (long double _x) 402 { 403 unsigned short sw; 404 __asm__ ("fxam;" 405 "fstsw %%ax": "=a" (sw) : "t" (_x)); 406 return (sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL)) 407 == FP_NAN; 408 } 409 #endif 410 411 #define isnan(x) (sizeof (x) == sizeof (float) ? __isnanf (x) \ 412 : sizeof (x) == sizeof (double) ? __isnan (x) \ 413 : __isnanl (x)) 414 415 /* 7.12.3.5 */ 416 #define isnormal(x) (fpclassify(x) == FP_NORMAL) 417 418 /* 7.12.3.6 The signbit macro */ 419 extern int __cdecl __signbit (double); 420 extern int __cdecl __signbitf (float); 421 extern int __cdecl __signbitl (long double); 422 #ifndef __NO_INLINE__ 423 __CRT_INLINE int __cdecl __signbit (double x) { 424 unsigned short stw; 425 __asm__ ( "fxam; fstsw %%ax;": "=a" (stw) : "t" (x)); 426 return (stw & 0x0200) != 0; 427 } 428 429 __CRT_INLINE int __cdecl __signbitf (float x) { 430 unsigned short stw; 431 __asm__ ("fxam; fstsw %%ax;": "=a" (stw) : "t" (x)); 432 return (stw & 0x0200) != 0; 433 } 434 435 __CRT_INLINE int __cdecl __signbitl (long double x) { 436 unsigned short stw; 437 __asm__ ("fxam; fstsw %%ax;": "=a" (stw) : "t" (x)); 438 return (stw & 0x0200) != 0; 439 } 440 #endif 441 442 #define signbit(x) (sizeof (x) == sizeof (float) ? __signbitf (x) \ 443 : sizeof (x) == sizeof (double) ? __signbit (x) \ 444 : __signbitl (x)) 445 446 /* 7.12.4 Trigonometric functions: Double in C89 */ 447 extern float __cdecl sinf (float); 448 extern long double __cdecl sinl (long double); 449 450 extern float __cdecl cosf (float); 451 extern long double __cdecl cosl (long double); 452 453 extern float __cdecl tanf (float); 454 extern long double __cdecl tanl (long double); 455 456 extern float __cdecl asinf (float); 457 extern long double __cdecl asinl (long double); 458 459 extern float __cdecl acosf (float); 460 extern long double __cdecl acosl (long double); 461 462 extern float __cdecl atanf (float); 463 extern long double __cdecl atanl (long double); 464 465 extern float __cdecl atan2f (float, float); 466 extern long double __cdecl atan2l (long double, long double); 467 468 /* 7.12.5 Hyperbolic functions: Double in C89 */ 469 extern float __cdecl sinhf (float); 470 #ifndef __NO_INLINE__ 471 __CRT_INLINE float __cdecl sinhf (float x) 472 {return (float) sinh (x);} 473 #endif 474 extern long double __cdecl sinhl (long double); 475 476 extern float __cdecl coshf (float); 477 #ifndef __NO_INLINE__ 478 __CRT_INLINE float __cdecl coshf (float x) 479 {return (float) cosh (x);} 480 #endif 481 extern long double __cdecl coshl (long double); 482 483 extern float __cdecl tanhf (float); 484 #ifndef __NO_INLINE__ 485 __CRT_INLINE float __cdecl tanhf (float x) 486 {return (float) tanh (x);} 487 #endif 488 extern long double __cdecl tanhl (long double); 489 490 /* Inverse hyperbolic trig functions */ 491 /* 7.12.5.1 */ 492 extern double __cdecl acosh (double); 493 extern float __cdecl acoshf (float); 494 extern long double __cdecl acoshl (long double); 495 496 /* 7.12.5.2 */ 497 extern double __cdecl asinh (double); 498 extern float __cdecl asinhf (float); 499 extern long double __cdecl asinhl (long double); 500 501 /* 7.12.5.3 */ 502 extern double __cdecl atanh (double); 503 extern float __cdecl atanhf (float); 504 extern long double __cdecl atanhl (long double); 505 506 /* Exponentials and logarithms */ 507 /* 7.12.6.1 Double in C89 */ 508 extern float __cdecl expf (float); 509 #ifndef __NO_INLINE__ 510 __CRT_INLINE float __cdecl expf (float x) 511 {return (float) exp (x);} 512 #endif 513 extern long double __cdecl expl (long double); 514 515 /* 7.12.6.2 */ 516 extern double __cdecl exp2(double); 517 extern float __cdecl exp2f(float); 518 extern long double __cdecl exp2l(long double); 519 520 /* 7.12.6.3 The expm1 functions */ 521 /* TODO: These could be inlined */ 522 extern double __cdecl expm1(double); 523 extern float __cdecl expm1f(float); 524 extern long double __cdecl expm1l(long double); 525 526 /* 7.12.6.4 Double in C89 */ 527 extern float __cdecl frexpf (float, int*); 528 #ifndef __NO_INLINE__ 529 __CRT_INLINE float __cdecl frexpf (float x, int* expn) 530 {return (float) frexp (x, expn);} 531 #endif 532 extern long double __cdecl frexpl (long double, int*); 533 534 /* 7.12.6.5 */ 535 #define FP_ILOGB0 ((int)0x80000000) 536 #define FP_ILOGBNAN ((int)0x80000000) 537 extern int __cdecl ilogb (double); 538 extern int __cdecl ilogbf (float); 539 extern int __cdecl ilogbl (long double); 540 541 /* 7.12.6.6 Double in C89 */ 542 extern float __cdecl ldexpf (float, int); 543 #ifndef __NO_INLINE__ 544 __CRT_INLINE float __cdecl ldexpf (float x, int expn) 545 {return (float) ldexp (x, expn);} 546 #endif 547 extern long double __cdecl ldexpl (long double, int); 548 549 /* 7.12.6.7 Double in C89 */ 550 extern float __cdecl logf (float); 551 extern long double __cdecl logl (long double); 552 553 /* 7.12.6.8 Double in C89 */ 554 extern float __cdecl log10f (float); 555 extern long double __cdecl log10l (long double); 556 557 /* 7.12.6.9 */ 558 extern double __cdecl log1p(double); 559 extern float __cdecl log1pf(float); 560 extern long double __cdecl log1pl(long double); 561 562 /* 7.12.6.10 */ 563 extern double __cdecl log2 (double); 564 extern float __cdecl log2f (float); 565 extern long double __cdecl log2l (long double); 566 567 /* 7.12.6.11 */ 568 extern double __cdecl logb (double); 569 extern float __cdecl logbf (float); 570 extern long double __cdecl logbl (long double); 571 572 /* Inline versions. GCC-4.0+ can do a better fast-math optimization 573 with __builtins. */ 574 #ifndef __NO_INLINE__ 575 #if !(__MINGW_GNUC_PREREQ (4, 0) && defined __FAST_MATH__ ) 576 __CRT_INLINE double __cdecl logb (double x) 577 { 578 double res; 579 __asm__ ("fxtract\n\t" 580 "fstp %%st" : "=t" (res) : "0" (x)); 581 return res; 582 } 583 584 __CRT_INLINE float __cdecl logbf (float x) 585 { 586 float res; 587 __asm__ ("fxtract\n\t" 588 "fstp %%st" : "=t" (res) : "0" (x)); 589 return res; 590 } 591 592 __CRT_INLINE long double __cdecl logbl (long double x) 593 { 594 long double res; 595 __asm__ ("fxtract\n\t" 596 "fstp %%st" : "=t" (res) : "0" (x)); 597 return res; 598 } 599 #endif /* !defined __FAST_MATH__ || !__MINGW_GNUC_PREREQ (4, 0) */ 600 #endif /* !defined __NO_INLINE__ */ 601 602 /* 7.12.6.12 Double in C89 */ 603 extern float __cdecl modff (float, float*); 604 extern long double __cdecl modfl (long double, long double*); 605 606 /* 7.12.6.13 */ 607 extern double __cdecl scalbn (double, int); 608 extern float __cdecl scalbnf (float, int); 609 extern long double __cdecl scalbnl (long double, int); 610 611 extern double __cdecl scalbln (double, long); 612 extern float __cdecl scalblnf (float, long); 613 extern long double __cdecl scalblnl (long double, long); 614 615 /* 7.12.7.1 */ 616 /* Implementations adapted from Cephes versions */ 617 extern double __cdecl cbrt (double); 618 extern float __cdecl cbrtf (float); 619 extern long double __cdecl cbrtl (long double); 620 621 /* 7.12.7.2 The fabs functions: Double in C89 */ 622 extern float __cdecl fabsf (float x); 623 extern long double __cdecl fabsl (long double x); 624 625 /* 7.12.7.3 */ 626 extern double __cdecl hypot (double, double); /* in libmoldname.a */ 627 extern float __cdecl hypotf (float, float); 628 #ifndef __NO_INLINE__ 629 __CRT_INLINE float __cdecl hypotf (float x, float y) 630 { return (float) hypot (x, y);} 631 #endif 632 extern long double __cdecl hypotl (long double, long double); 633 634 /* 7.12.7.4 The pow functions. Double in C89 */ 635 extern float __cdecl powf (float, float); 636 #ifndef __NO_INLINE__ 637 __CRT_INLINE float __cdecl powf (float x, float y) 638 {return (float) pow (x, y);} 639 #endif 640 extern long double __cdecl powl (long double, long double); 641 642 /* 7.12.7.5 The sqrt functions. Double in C89. */ 643 extern float __cdecl sqrtf (float); 644 extern long double __cdecl sqrtl (long double); 645 646 /* 7.12.8.1 The erf functions */ 647 extern double __cdecl erf (double); 648 extern float __cdecl erff (float); 649 extern long double __cdecl erfl (long double); 650 651 /* 7.12.8.2 The erfc functions */ 652 extern double __cdecl erfc (double); 653 extern float __cdecl erfcf (float); 654 extern long double __cdecl erfcl (long double); 655 656 /* 7.12.8.3 The lgamma functions */ 657 extern double __cdecl lgamma (double); 658 extern float __cdecl lgammaf (float); 659 extern long double __cdecl lgammal (long double); 660 661 /* 7.12.8.4 The tgamma functions */ 662 extern double __cdecl tgamma (double); 663 extern float __cdecl tgammaf (float); 664 extern long double __cdecl tgammal (long double); 665 666 /* 7.12.9.1 Double in C89 */ 667 extern float __cdecl ceilf (float); 668 extern long double __cdecl ceill (long double); 669 670 /* 7.12.9.2 Double in C89 */ 671 extern float __cdecl floorf (float); 672 extern long double __cdecl floorl (long double); 673 674 /* 7.12.9.3 */ 675 extern double __cdecl nearbyint ( double); 676 extern float __cdecl nearbyintf (float); 677 extern long double __cdecl nearbyintl (long double); 678 679 /* 7.12.9.4 */ 680 /* round, using fpu control word settings */ 681 extern double __cdecl rint (double); 682 extern float __cdecl rintf (float); 683 extern long double __cdecl rintl (long double); 684 685 /* 7.12.9.5 */ 686 extern long __cdecl lrint (double); 687 extern long __cdecl lrintf (float); 688 extern long __cdecl lrintl (long double); 689 690 extern long long __cdecl llrint (double); 691 extern long long __cdecl llrintf (float); 692 extern long long __cdecl llrintl (long double); 693 694 /* Inline versions of above. 695 GCC 4.0+ can do a better fast-math job with __builtins. */ 696 #ifndef __NO_INLINE__ 697 #if !(__MINGW_GNUC_PREREQ (4, 0) && defined __FAST_MATH__ ) 698 __CRT_INLINE double __cdecl rint (double x) 699 { 700 double retval; 701 __asm__ ("frndint;": "=t" (retval) : "0" (x)); 702 return retval; 703 } 704 705 __CRT_INLINE float __cdecl rintf (float x) 706 { 707 float retval; 708 __asm__ ("frndint;" : "=t" (retval) : "0" (x) ); 709 return retval; 710 } 711 712 __CRT_INLINE long double __cdecl rintl (long double x) 713 { 714 long double retval; 715 __asm__ ("frndint;" : "=t" (retval) : "0" (x) ); 716 return retval; 717 } 718 719 __CRT_INLINE long __cdecl lrint (double x) 720 { 721 long retval; 722 __asm__ __volatile__ 723 ("fistpl %0" : "=m" (retval) : "t" (x) : "st"); 724 return retval; 725 } 726 727 __CRT_INLINE long __cdecl lrintf (float x) 728 { 729 long retval; 730 __asm__ __volatile__ 731 ("fistpl %0" : "=m" (retval) : "t" (x) : "st"); 732 return retval; 733 } 734 735 __CRT_INLINE long __cdecl lrintl (long double x) 736 { 737 long retval; 738 __asm__ __volatile__ 739 ("fistpl %0" : "=m" (retval) : "t" (x) : "st"); 740 return retval; 741 } 742 743 __CRT_INLINE long long __cdecl llrint (double x) 744 { 745 long long retval; 746 __asm__ __volatile__ 747 ("fistpll %0" : "=m" (retval) : "t" (x) : "st"); 748 return retval; 749 } 750 751 __CRT_INLINE long long __cdecl llrintf (float x) 752 { 753 long long retval; 754 __asm__ __volatile__ 755 ("fistpll %0" : "=m" (retval) : "t" (x) : "st"); 756 return retval; 757 } 758 759 __CRT_INLINE long long __cdecl llrintl (long double x) 760 { 761 long long retval; 762 __asm__ __volatile__ 763 ("fistpll %0" : "=m" (retval) : "t" (x) : "st"); 764 return retval; 765 } 766 #endif /* !__FAST_MATH__ || !__MINGW_GNUC_PREREQ (4,0) */ 767 #endif /* !defined __NO_INLINE */ 768 769 /* 7.12.9.6 */ 770 /* round away from zero, regardless of fpu control word settings */ 771 extern double __cdecl round (double); 772 extern float __cdecl roundf (float); 773 extern long double __cdecl roundl (long double); 774 775 /* 7.12.9.7 */ 776 extern long __cdecl lround (double); 777 extern long __cdecl lroundf (float); 778 extern long __cdecl lroundl (long double); 779 780 extern long long __cdecl llround (double); 781 extern long long __cdecl llroundf (float); 782 extern long long __cdecl llroundl (long double); 783 784 /* 7.12.9.8 */ 785 /* round towards zero, regardless of fpu control word settings */ 786 extern double __cdecl trunc (double); 787 extern float __cdecl truncf (float); 788 extern long double __cdecl truncl (long double); 789 790 /* 7.12.10.1 Double in C89 */ 791 extern float __cdecl fmodf (float, float); 792 extern long double __cdecl fmodl (long double, long double); 793 794 /* 7.12.10.2 */ 795 extern double __cdecl remainder (double, double); 796 extern float __cdecl remainderf (float, float); 797 extern long double __cdecl remainderl (long double, long double); 798 799 /* 7.12.10.3 */ 800 extern double __cdecl remquo(double, double, int *); 801 extern float __cdecl remquof(float, float, int *); 802 extern long double __cdecl remquol(long double, long double, int *); 803 804 /* 7.12.11.1 */ 805 extern double __cdecl copysign (double, double); /* in libmoldname.a */ 806 extern float __cdecl copysignf (float, float); 807 extern long double __cdecl copysignl (long double, long double); 808 809 /* 7.12.11.2 Return a NaN */ 810 extern double __cdecl nan(const char *tagp); 811 extern float __cdecl nanf(const char *tagp); 812 extern long double __cdecl nanl(const char *tagp); 813 814 #ifndef __STRICT_ANSI__ 815 #define _nan() nan("") 816 #define _nanf() nanf("") 817 #define _nanl() nanl("") 818 #endif 819 820 /* 7.12.11.3 */ 821 extern double __cdecl nextafter (double, double); /* in libmoldname.a */ 822 extern float __cdecl nextafterf (float, float); 823 extern long double __cdecl nextafterl (long double, long double); 824 825 /* 7.12.11.4 The nexttoward functions */ 826 extern double __cdecl nexttoward (double, long double); 827 extern float __cdecl nexttowardf (float, long double); 828 extern long double __cdecl nexttowardl (long double, long double); 829 830 /* 7.12.12.1 */ 831 /* x > y ? (x - y) : 0.0 */ 832 extern double __cdecl fdim (double x, double y); 833 extern float __cdecl fdimf (float x, float y); 834 extern long double __cdecl fdiml (long double x, long double y); 835 836 /* fmax and fmin. 837 NaN arguments are treated as missing data: if one argument is a NaN 838 and the other numeric, then these functions choose the numeric 839 value. */ 840 841 /* 7.12.12.2 */ 842 extern double __cdecl fmax (double, double); 843 extern float __cdecl fmaxf (float, float); 844 extern long double __cdecl fmaxl (long double, long double); 845 846 /* 7.12.12.3 */ 847 extern double __cdecl fmin (double, double); 848 extern float __cdecl fminf (float, float); 849 extern long double __cdecl fminl (long double, long double); 850 851 /* 7.12.13.1 */ 852 /* return x * y + z as a ternary op */ 853 extern double __cdecl fma (double, double, double); 854 extern float __cdecl fmaf (float, float, float); 855 extern long double __cdecl fmal (long double, long double, long double); 856 857 858 /* 7.12.14 */ 859 /* 860 * With these functions, comparisons involving quiet NaNs set the FP 861 * condition code to "unordered". The IEEE floating-point spec 862 * dictates that the result of floating-point comparisons should be 863 * false whenever a NaN is involved, with the exception of the != op, 864 * which always returns true: yes, (NaN != NaN) is true). 865 */ 866 867 #if __GNUC__ >= 3 868 869 #define isgreater(x, y) __builtin_isgreater(x, y) 870 #define isgreaterequal(x, y) __builtin_isgreaterequal(x, y) 871 #define isless(x, y) __builtin_isless(x, y) 872 #define islessequal(x, y) __builtin_islessequal(x, y) 873 #define islessgreater(x, y) __builtin_islessgreater(x, y) 874 #define isunordered(x, y) __builtin_isunordered(x, y) 875 876 #else 877 /* helper */ 878 extern int __cdecl __fp_unordered_compare (long double, long double); 879 #ifndef __NO_INLINE__ 880 __CRT_INLINE int __cdecl 881 __fp_unordered_compare (long double x, long double y){ 882 unsigned short retval; 883 __asm__ ("fucom %%st(1);" 884 "fnstsw;": "=a" (retval) : "t" (x), "u" (y)); 885 return retval; 886 } 887 #endif 888 889 #define isgreater(x, y) ((__fp_unordered_compare(x, y) \ 890 & 0x4500) == 0) 891 #define isless(x, y) ((__fp_unordered_compare (y, x) \ 892 & 0x4500) == 0) 893 #define isgreaterequal(x, y) ((__fp_unordered_compare (x, y) \ 894 & FP_INFINITE) == 0) 895 #define islessequal(x, y) ((__fp_unordered_compare(y, x) \ 896 & FP_INFINITE) == 0) 897 #define islessgreater(x, y) ((__fp_unordered_compare(x, y) \ 898 & FP_SUBNORMAL) == 0) 899 #define isunordered(x, y) ((__fp_unordered_compare(x, y) \ 900 & 0x4500) == 0x4500) 901 902 #endif 903 904 905 #endif /* __STDC_VERSION__ >= 199901L */ 906 #endif /* __NO_ISOCEXT */ 907 908 909 #ifdef __cplusplus 910 } 911 #endif 912 #endif /* Not RC_INVOKED */ 913 914 915 #endif /* Not _MATH_H_ */
CodeBlocks