chiark / gitweb /
@@@ wip
[mLib] / utils / maths.h
1 /* -*-c-*-
2  *
3  * Mathematical utilities
4  *
5  * (c) 2023 Straylight/Edgeware
6  */
7
8 /*----- Licensing notice --------------------------------------------------*
9  *
10  * This file is part of the mLib utilities library.
11  *
12  * mLib is free software: you can redistribute it and/or modify it under
13  * the terms of the GNU Library General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or (at
15  * your option) any later version.
16  *
17  * mLib is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
20  * License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public
23  * License along with mLib.  If not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25  * USA.
26  */
27
28 #ifndef MLIB_MATHS_H
29 #define MLIB_MATHS_H
30
31 #ifdef __cplusplus
32   extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #include <math.h>
38
39 /*----- Macros provided ---------------------------------------------------*/
40
41 /* --- @NANP@ --- *
42  *
43  * Arguments:   @floatish x@ = a floating-point number (evaluated multiple
44  *                      times)
45  *
46  * Returns:     Nonzero if @x@ is not-a-number.
47  */
48
49 #ifdef isnan
50 #  define NANP(x) isnan(x)
51 #else
52 #  define NANP(x) (!((x) == (x)))
53 #endif
54
55 /* --- @INFP@ --- *
56  *
57  * Arguments:   @floatish x@ = a floating-point number (evaluated multiple
58  *                      times)
59  *
60  * Returns:     Nonzero if @x@ is infinite.
61  */
62
63 #ifdef isinf
64 #  define INFP(x) isinf(x)
65 #else
66 #  define INFP(x) ((x) > LDBL_MAX || (x) < -LDBL_MAX)
67 #endif
68
69 /* --- @NEGP@ --- *
70  *
71  * Arguments:   @floatish x@ = a floating-point number (evaluated multiple
72  *                      times)
73  *
74  * Returns:     Nonzero if @x@ is negative.  This won't give the right answer
75  *              for negative zero unless the system provides explicit
76  *              support.
77  */
78
79 #ifdef signbit
80 #  define NEGP(x) signbit(x)
81 #else
82 #  define NEGP(x) ((x) < 0)
83 #endif
84
85 /*----- That's all, folks -------------------------------------------------*/
86
87 #ifdef __cplusplus
88   }
89 #endif
90
91 #endif