forked from petervaro/cutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcref.h
2080 lines (1847 loc) · 60.6 KB
/
cref.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* INFO ************************************************************************
** **
** cutils **
** ====== **
** **
** Modern and Lightweight C Utilities **
** Version: 0.8.96.247 (20141023) **
** **
** File: cref.h **
** **
** For more information about the project, visit <http://www.cutils.org>. **
** Copyright (C) 2014 Peter Varo **
** **
** This program is free software: you can redistribute it and/or modify it **
** under the terms of the GNU General Public License as published by the **
** Free Software Foundation, either version 3 of the License, or **
** (at your option) any later version. **
** **
** This program is distributed in the hope that it will be useful, but **
** WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. **
** See the GNU General Public License for more details. **
** **
** You should have received a copy of the GNU General Public License **
** along with this program, most likely a file in the root directory, **
** called 'LICENSE'. If not, see <http://www.gnu.org/licenses>. **
** **
************************************************************************ INFO */
/* Inspired by:
Jospeh H. Silverman
http://www.tutorialspoint.com
http://www.stackoverflow.com
http://en.cppreference.com
http://en.wikipedia.org */
/*----------------------------------------------------------------------------*/
// The macro language
#ifdef __CREF_NEVER_DEFINE_THIS_OR_CUTE_LITTLE_KITTENS_WILL_DIE__
#error "Variable '__CREF_NEVER_DEFINE_THIS_OR_CUTE_LITTLE_KITTENS_WILL_DIE__'"\
"should never be defined, because 'cref.c' is not a valid C file!"
#define NDEBUG
#undef NDEBUG
#ifndef NDEBUG
#if defined NDEBUG
int i = 0;
#elif 10
int i = 1;
#else
int i = -1;
#endif // defined NDEBUG
#endif // NDEBUG
/*----------------------------------------------------------------------------*/
#include <assert.h>
// Makes assert to be ignored if defined before header is included
#define NDEBUG
// Issues a compile-time diagnostic if the
// value of a constant expression is false
#define static_assert _Static_assert
// If expression is false, writes info and terminate program
void
assert(int expr);
/*----------------------------------------------------------------------------*/
#include <errno.h>
#define EDOM // Mathematics argument out of domain of function
#define EILSEQ // Illegal byte sequence
#define ERANGE // Result too large
// the type of errno value
typedef int errno_t;
// Global variable error number is readable and writeable
extern errno_t errno;
/*----------------------------------------------------------------------------*/
#include <ctype.h>
/* Character classes
* -----------------
* Digits [0-9]
* Hexadecimal digits <Digits> + [A-Fa-f]
* Lowercase letters [a-z]
* Uppercase letters [A-Z]
* Letters <Lowercase letters> + <Uppercase letters>
* Alphanumeric characters <Digits> + <Letters>
* Punctuation characters [!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]
* Graphical characters <Alphanumeric characters> + <Punctuation characters>
* Space characters [\t\n\v\f\r\s]
* Printable characters <Graphical characters> + <Space characters>
* Control characters [\0\a\b\t\n\v\f\r\e^?]
* Blank characters [\s\t]
* Alphabetic characters <Lowercase letters> + <Uppercase letters>
*/
// Checks whether chr is alphanumeric
int
isalnum(int chr);
// Checks whether chr is alphabetic
int
isalpha(int chr);
// Checks whether chr is control character
int
iscntrl(int chr);
// Checks whether chr is decimal digit
int
isdigit(int chr);
// Checks whether chr has graphical representation using locale
int
isgraph(int chr);
// Checks whether chr is lowercase letter
int
islower(int chr);
// Checks whether chr is printable
int
isprint(int chr);
// Checks whether chr is punctuation character
int
ispunct(int chr);
// Checks whether chr is white-space
int
isspace(int chr);
// Checks whether chr is uppercase letter
int
isupper(int chr);
// Checks whether chr is a blank character in the current C locale
// In the default C locale this is only \s (0x20) \t (0x09)
int
isblank(int chr);
// Checks whether chr is hexadecimal digit
int
isxdigit(int chr);
// Converts uppercase letter to lowercase
int
tolower(int chr);
// Converts lowercase letter to uppercase
int
toupper(int chr);
/*----------------------------------------------------------------------------*/
#include <string.h>
// Searches for the first occurrence of the chr in the first n bytes of the str
void *
memchr(const void *str,
int chr,
size_t n);
// Compares the first n bytes of str1 and str2, returns negative if str1 is
// lesser than, 0 if equal to and positive if str1 is greater than str2
int
memcmp(const void *str1,
const void *str2,
size_t n);
// Copies n characters from src to dst
void *
memcpy(void *dst,
const void *src,
size_t n);
// Checks for overlapping and copy n characters from src to dst
void *
memmove(void *dst,
const void *src,
size_t n);
// Copies the chr to the first n characters of str
void *
memset(void *str,
int chr,
size_t n);
// Copies src to dst.
char *
strcpy(char *dst,
const char *src);
// Copies up to n characters from src to dst
char *
strncpy(char *dst,
const char *src,
size_t n);
// Appends src to the end of dst
// Copies no more than s1max bytes to s1
errno_t
strcat_s(char *restrict dst,
rsize_t dstmax,
const char *restrict src);
// Appends the src to the end of dst up to n characters long
char *
strncat(char *dst,
const char *src,
size_t n);
// Searches for the first occurrence of chr in str
char *
strchr(const char *str,
int chr);
// Searches for the last occurrence of the character in str
char *
strrchr(const char *str,
int chr);
// Compares str1 to str2
int
strcmp(const char *str1,
const char *str2);
// Compares at most the first n bytes of str1 and str2
int
strncmp(const char *str1,
const char *str2,
size_t n);
// Compares str1 to str2, the result depends on the <location.h>'s LC_COLLATE
int
strcoll(const char *str1,
const char *str2);
size_t
// calculates the length of the initial segment of
// str1 which consists entirely of characters in str2
strspn(const char *str1,
const char *str2);
// Calculates the length of the initial segment of
// str1 which consists entirely of characters not in str2
size_t
strcspn(const char *str1,
const char *str2);
// Computes the length of str up to but not including the '\0' character
size_t
strlen(const char *str);
// Finds the first character in str1 that matches any character specified in str2
char *
strpbrk(const char *str1,
const char *str2);
// Finds the first occurrence of the entire string needle
// (not including '\0') which appears in the string haystack
char *
strstr(const char *haystack,
const char *needle);
// Breaks str into a series of tokens separated by delim
char *
strtok(char *str,
const char *delim);
// Transforms src according to the current locale and copies the first n
// characters of the transformed string to dst, returning its length
size_t
strxfrm(char *dst,
const char *src,
size_t n);
// Searches an internal array for the error number errno
// and returns a pointer to an error message string.
char *
strerror(int errno);
/*----------------------------------------------------------------------------*/
#include <stdio.h>
// file handle, this is a structure containing the information about a
// file or text stream needed to perform input or output operations on it
typedef struct {} FILE;
typedef unsigned int size_t;
typedef /* non array */ fpos_t;
// a pointer to a FILE which refers to the standard input stream
FILE *stdin;
// a pointer to a FILE which refers to the standard output stream
FILE *stdout;
// a pointer to a FILE which refers to the standard error stream
FILE *stderr;
// a negative integer of type int used to indicate end-of-file conditions
#define EOF (-1)
// an integer which is the size of the buffer used by the setbuf() function
#define BUFSIZ
// the size of a char array which is large enough to
// store the name of any file that can be opened
#define FILENAME_MAX
// the number of files that may be open simultaneously; will be at least 8
#define FOPEN_MAX
// an abbreviation for "input/output fully buffered"; it is an integer
// which may be passed to the setvbuf() function to request block
// buffered input and output for an open stream
#define _IOFBF
// an abbreviation for "input/output line buffered"; it is an integer
// which may be passed to the setvbuf() function to request line
// buffered input and output for an open stream
#define _IOLBF
// an abbreviation for "input/output not buffered"; it is an integer
// which may be passed to the setvbuf() function to request
// unbuffered input and output for an open stream
#define _IONBF
// the size of a char array which is large enough to store a
// temporary filename generated by the tmpnam() function
#define L_tmpnam
// a macro expanding to the null pointer constant; that is, a
// constant representing a pointer value which is guaranteed
// not to be a valid address of an object in memory
#define NULL
// an integer which may be passed to the fseek() function to
// request positioning relative to the current file position
#define SEEK_CUR
// an integer which may be passed to the fseek() function to
// request positioning relative to the end of the file
#define SEEK_END
// an integer which may be passed to the fseek() function to
//request positioning relative to the beginning of the file
#define SEEK_SET
// the maximum number of unique filenames generable
// by the tmpnam() function; will be at least 25
#define TMP_MAX
char *format =
"%%" /* escape percent sign */
"%-+ 0w.pmc" /* prefixes: - left justify
+ print with sign
print space if no sign
0 pad with leading zero
w minimum field width
.p precision
m conversion character: h short,
l long,
L long double
c conversion character: */
"%d or %i" /* integer */
"%ld or %li" /* long integer */
"%lld or %lli" /* long long integer */
"%u" /* unsigned integer */
"%lu" /* unsigned long integer */
"%llu" /* unsigned long long integer */
"%c" /* single character */
"%s" /* string */
"%f" /* double */
"%Lf" /* long double */
"%a" /* hexadecimal floating point */
"%e or %E" /* expontial */
"%o" /* octal */
"%x or %X" /* hexadecimal */
"%p" /* pointer */
"%n" /* number of characters written */
"%g or %G" /* same as f or e, E depending exponent */
"\n";
// TODO: %ju and %lf and %td and %hd and %hu
// http://www.mekong.net/tech/printf.htm
// Closes the stream. All buffers are flushed
int
fclose(FILE *stream);
// Clears the end-of-file and error indicators for the given stream
void
clearerr(FILE *stream);
// Tests the end-of-file indicator for the given stream
int
feof(FILE *stream);
// Tests the error indicator for the given stream
int
ferror(FILE *stream);
// Flushes the output buffer of a stream
int
fflush(FILE *stream);
// Gets the current file position of the stream and writes it to pos
int
fgetpos(FILE *stream,
fpos_t *pos);
// Opens the filename using the given mode
FILE *
fopen(const char *fname,
const char *mode);
// Reads data from the given stream into the array pointed to by ptr
size_t
fread(void *ptr, /* output buffer */
size_t size, /* size of items */
size_t nmemb, /* number of items */
FILE *stream); /* input stream */
// Associates a new filename with the given open stream and
// same time closing the old file in stream
FILE *
freopen(const char *fname,
const char *mode,
FILE *stream);
// Sets the file position of the stream to the given offset. The argument
// offset signifies the number of bytes to seek from the given whence position
int
fseek(FILE *stream,
long int offset,
int whence);
// Sets the file position of the given stream to the given position. The
// argument pos is a position given by the function fgetpos
int
fsetpos(FILE *stream,
const fpos_t *pos);
// Returns the current file position of the given stream
long int
ftell(FILE *stream);
// Writes data from the array pointed to by ptr to the given stream
size_t
fwrite(const void *ptr, /* input data */
size_t size, /* size of items */
size_t nmemb, /* number of items */
FILE *stream); /* output stream */
// Deletes the given filename so that it is no longer accessible
int
remove(const char *fname);
// Causes the filename referred to by old_fname to be changed to new_fname
int
rename(const char *old_fname,
const char *new_fname);
// Sets the file position to the beginning of the file of the given stream
void
rewind(FILE *stream);
// Defines how a stream should be buffered
void
setbuf(FILE *stream,
char *buffer);
// Another function to define how a stream should be buffered
int
setvbuf(FILE *stream,
char *buffer,
int mode,
size_t size);
// Creates a temporary file in binary update mode (wb+)
FILE *
tmpfile(void);
// Generates and returns a valid temporary filename which does not exist
char *
tmpnam(char *str);
// Sends formatted output to a stream
int
fprintf(FILE *stream,
const char *format,
...);
// Sends formatted output to stdout
int
printf(const char *format,
...);
// Sends formatted output to a string
int
sprintf(char *str,
const char *format,
...);
// Sends formatted output to a stream using an argument list
int
vfprintf(FILE *stream,
const char *format,
va_list arg);
// Sends formatted output to stdout using an argument list
int
vprintf(const char *format,
va_list arg);
// Sends formatted output to a string using an argument list
int
vsprintf(char *str,
const char *format,
va_list arg);
// Composes a string with the same text that would be printed if format was used
// on printf, but instead of being printed, the content is stored as a C string
// in the buffer pointed by s (taking n as the maximum buffer capacity to fill)
int
snprintf(char *str,
size_t n,
const char *format,
...);
// Reads formatted input from a stream
int
fscanf(FILE *stream,
const char *format,
...);
// Reads formatted input from stdin
int
scanf(const char *format,
...);
// Reads formatted input from a string
int
sscanf(const char *str,
const char *format,
...);
// Gets the next character from the specified stream
// and advances the position indicator for the stream
int
fgetc(FILE *stream);
// Reads a line from the specified stream and stores it into str. It stops when
// either (n-1) characters are read, the \n character is read, or the
// end-of-file is reached, whichever comes first
char *
fgets(char *str,
int n,
FILE *stream);
// Writes a character to the specified stream and
// advances the position indicator for the stream
int
fputc(int chr,
FILE *stream);
// Writes a string to the specified stream up to but not including '\0'
int
fputs(const char *str,
FILE *stream);
// Gets the next character from the specified stream and
// advances the position indicator for the stream
int
getc(FILE *stream);
// Gets a character from stdin
int
getchar(void);
// Reads a line from stdin and stores it into str. It stops when either the
// \n is read or when the end-of-file is reached, whichever comes first but
// at most n characters
char *
gets_s(char *restrict buffer,
size_t n);
// Writes a character to the specified stream and
// advances the position indicator for the stream
int
putc(int char,
FILE *stream);
// Writes a character to stdout
int
putchar(int char);
// Writes a string to stdout up to but not including '\0'.
// A \n character is appended to the output
int
puts(const char *str);
// Pushes the character onto the specified stream
// so that the this is the next character read
int
ungetc(int char,
FILE *stream);
// Prints a descriptive error message to stderr.
// First str is printed followed by a colon then a space
void
perror(const char *str);
/*----------------------------------------------------------------------------*/
#include <stdarg.h>
// Declaration of pointer to arguments
typedef void* va_list;
// Initialization of argument pointer, lastarg is last named argument
void va_start(va_list name,
lastarg);
// Access next unamed arg, update pointer
type va_arg(va_list name,
type);
// Call before exiting function
void va_end(va_list name);
// Copies the (previously initialized) variable argument list src to dst
void va_copy(va_list dst,
va_list src);
/*----------------------------------------------------------------------------*/
#include <stddef.h>
// Integer constant expression of type size_t, the value of
// which is the offset in bytes to the structure member
// (member-designator), from the beginning of its structure (type)
#define offsetof(type, member)
#define size_t
#define ptrdiff_t
/*----------------------------------------------------------------------------*/
#include <stdbool.h>
typedef int _Bool;
#define bool _Bool
#define true 1
#define false 0
/*----------------------------------------------------------------------------*/
#include <stdlib.h>
#define EXIT_FAILURE
#define EXIT_SUCCESS
/* Terminates program */
_Noreturn void exit(int exit_code);
// Converts s to double
double
atof(const char *str);
// Converts str to int
int
atoi(const char *str);
// Converts str to long integer
long int
atol(const char *str);
// Converts str to double from its start to end pointer
double
strtod(const char *str,
char **end);
// Converts str to long integer with base (binary, octal, hexa, decimal)
long int
strtol(const char *str,
char **end,
int base);
// Converts str to unsigned long integer with base (binary, octal, hexa, decimal)
unsigned long int
strtoul(const char *str,
char **end,
int base);
// Allocates the requested memory and returns a pointer to it
void *
malloc(size_t size);
// Allocates the requested memory, initializes it, and returns a pointer to it
void *
calloc(size_t nitems,
size_t size);
// Attempts to resize the previously allocated memory block at ptr,
// if succeseded returns the new memory address, else a NULL ptr
void *
realloc(void *ptr,
size_t size);
// Deallocates the previously allocated memory
void
free(void *ptr);
// Causes an abnormal program termination.
void
abort(void);
// Causes the function to be called when the program terminates normally
int
atexit(void (*func)(void));
// Causes the program to terminate normally with cleaning up
void
exit(int code);
// Causes the program to terminate normally without cleaning up
void
_Exit(int code);
// Causes the program to terminate normally without cleaning up
// but with IO buffers flushed
void
quick_exit(int code);
// Registers a function to be called on quick_exit() invocation
int
at_quick_exit(void (*func)());
// Searches for name in the environment string and returns the associated value
char *
getenv(const char *name);
// The command is passed to the host environment to be executed
int
system(const char *cmd);
// Performs a binary search
void *
bsearch(const void *key,
const void *base,
size_t nitems,
size_t size,
int (*compar)(const void *, const void *));
// Sorts an array
void
qsort(void *base,
size_t nitems,
size_t size,
int (*compar)(const void *, const void*));
// Returns the absolute value of x
int
abs(int x);
// Divides numer (numerator) by denom (denominator)
div_t
div(int numer,
int denom);
// Returns the absolute value of x
long int
labs(long int x);
// Divides numer (numerator) by denom (denominator)
ldiv_t
ldiv(long int numer,
long int denom);
// Returns a pseudo-random number in the range of 0 to RAND_MAX
int
rand(void);
// This function seeds the random number generator used by rand()
void
srand(unsigned int seed);
// Returns the length of a multibyte character str
int
mblen(const char *str,
size_t n);
// Converts the multibyte character str to the pwcs array
size_t
mbstowcs(wchar_t *pwcs,
const char *str,
size_t n);
// Examines the multibyte str
int
mbtowc(wchar_t *pwc,
const char *str,
size_t n);
// Converts the codes stored in the array pwcs to multibyte character str
size_t
wcstombs(char *str,
const wchar_t *pwcs,
size_t n);
// Examines the code which corresponds to a multibyte character wchar
int
wctomb(char *str,
wchar_t wchar);
/*----------------------------------------------------------------------------*/
#include <time.h>
#define CLOCKS_PER_SEC
struct tm {
int tm_sec; /* seconds, range 0 to 59 */
int tm_min; /* minutes, range 0 to 59 */
int tm_hour; /* hours, range 0 to 23 */
int tm_mday; /* day of the month, range 1 to 31 */
int tm_mon; /* month, range 0 to 11 */
int tm_year; /* The number of years since 1900 */
int tm_wday; /* day of the week, range 0 to 6 */
int tm_yday; /* day in the year, range 0 to 365 */
int tm_isdst; /* daylight saving time */
};
// Returns a pointer to a string which represents
// the day and time of the structure timeptr
char *
asctime(const struct tm *timeptr);
// Returns the processor clock time used since the beginning of
// an implementation-defined era (normally the beginning of the program)
clock_t
clock(void);
// Returns a string representing the localtime based on the argument timer
char *
ctime(const time_t *timer);
// Returns the difference of seconds between time1 and time2 (time1-time2)
double
difftime(time_t time1,
time_t time2);
// The value of timer is broken up into the structure tm and expressed in
// Coordinated Universal Time (UTC) also known as Greenwich Mean Time (GMT)
struct tm *
gmtime(const time_t *timer);
// The value of timer is broken up into the structure tm
// and expressed in the local time zone
struct tm *
localtime(const time_t *timer);
// Converts the structure pointed to by timeptr into
// a time_t value according to the local time zone
time_t
mktime(struct tm *timeptr);
// Formats the time represented in the structure timeptr according
// to the formatting rules defined in format and stored into str
size_t
strftime(char *str,
size_t maxsize,
const char *format,
const struct tm *timeptr);
// Calculates the current calender time and encodes it into time_t format
time_t
time(time_t *timer);
/*----------------------------------------------------------------------------*/
#include <math.h>
#define FP_ILOGB0
#define FP_ILOGBNAN
// Computes the absolute value of an integer number
int
abs(int x);
long
labs(long x);
long long
llabs(long long x);
intmax_t
imaxabs(intmax_t x);
// Returns the absolute value of a float number
float
fabsf(float x);
double
fabs(double x);
long double
fabsl(long double x);
// Return values of div functions
struct div_t { int quot; int rem; };
struct ldiv_t { long quot; long rem; };
struct lldiv_t { long long quot; long long rem; };
struct imaxdiv_t { intmax_t quot; intmax_t rem; };
// Computes the quotient (the result of the expression x/y) and
// remainder (the result of the expression x%y) simultaneously
div_t
div(int x,
int y);
ldiv_t
ldiv(long x,
long y);
lldiv_t
lldiv(long long x,
long long y);
imaxdiv_t
imaxdiv(intmax_t x,
intmax_t y);
// Computes the remainder of the division operation x/y
float
fmodf(float x,
float y);
double
fmod(double x,
double y);
long double
fmodl(long double x,
long double y);
// Computes the signed remainder of the floating point division
// operation x/y. In contrast to fmod(), the returned value is
// not guaranteed to have the same sign as x
float
remainderf(float x,
float y);
double
remainder(double x,
double y);
long double
remainderl(long double x,
long double y);
// Computes the remainder of the floating point division operation
// x/y as the remainder() function does. Additionally, the sign and
// at least the three of the last bits of x/y will be stored in quo
float
remquof(float x,
float y,
int *quo);
double
remquo(double x,
double y,
int *quo);
long double
remquol(long double x,
long double y,
int *quo);
// The fma functions compute (x*y) + z, rounded as one ternary operation,
// according to the rounding mode characterized by the value of FLT_ROUNDS
float
fmaf(float x,
float y,
float z);
double
fma(double x,
double y,
double z);
long double
fmal(long double x,
long double y,
long double z);
// Returns the larger of two floating point arguments. If one of the arguments
// is NaN, this function returns the other argument. If both arguments are NaNs,
// the function returns NaN
float
fmaxf(float x,
float y);
double
fmax(double x,
double y);
long double
fmaxl(long double x,
long double y);
// Returns the smaller of two floating point arguments. If one of the arguments
// is NaN, this function returns the other argument. If both arguments are NaNs,
// the function returns NaN
float
fminf(float x,
float y);
double
fmin(double x,
double y);
long double
fminl(long double x,
long double y);
// Returns the positive difference between x and y. This could be
// implemented as fmax (x - y, 0), so if x ≤ y, the result is always
// equals to 0, otherwise it is x - y.
float
fdimf(float x,
float y);
double
fdim(double x,
double y);
long double
fdiml(long double x,
long double y);
// Converts the implementation-defined character string str into the
// corresponding quiet NaN value. The call nan("string") is equivalent to the
// call strtod("NAN(string)", (char**)NULL);
float
nanf(const char* str);
double
nan(const char* str);
long double
nanl(const char* str);
// Computes the e (Euler's number, 2.7182818) raised to the given power x
float
expf(float x);
double
exp(double x);
long double
expl(long double x);
// Computes 2 raised to the given power x
float
exp2f(float x);
double
exp2(double x);
long double
exp2l(long double x);
// Computes the e (Euler's number, 2.7182818) raised to the
// given power x, minus 1. This function is more accurate
// than the expression exp(x)-1 if x is close to zero
float
expm1f(float x);
double
expm1(double x);
long double
expm1l(long double x);
// Computes the natural (base e) logarithm of x
float
logf(float x);
double
log(double x);
long double
logl(long double x);
// Computes the base 2 logarithm of x
float
log2f(float x);
double
log2(double x);
long double
log2l(long double x);
// Computes the common (base 10) logarithm of x
float
log10f(float x);
double
log10(double x);
long double
log10l(long double x);
// Computes the natural (base e) logarithm of 1+x. This function is more
// precise than the expression log(1+x) if x is close to zero
float
log1pf(float x);
double
log1p(double x);
long double
log1pl(long double x);
// Extracts the value of the exponent from the floating-point
// argument x, and returns it as a signed integer value. Formally,
// the result is the integral part of log r|x| as a signed integral
// value, for non-zero x, where r is FLT_RADIX