Commit | Line | Data |
---|---|---|
67b5031e MW |
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 | ||
b1a20bee MW |
39 | #ifndef MLIB_BITS_H |
40 | # include "bits.h" | |
41 | #endif | |
42 | ||
67b5031e MW |
43 | /*----- Macros provided ---------------------------------------------------*/ |
44 | ||
45 | /* --- @NANP@ --- * | |
46 | * | |
47 | * Arguments: @floatish x@ = a floating-point number (evaluated multiple | |
48 | * times) | |
49 | * | |
50 | * Returns: Nonzero if @x@ is not-a-number. | |
51 | */ | |
52 | ||
53 | #ifdef isnan | |
54 | # define NANP(x) isnan(x) | |
55 | #else | |
56 | # define NANP(x) (!((x) == (x))) | |
57 | #endif | |
58 | ||
59 | /* --- @INFP@ --- * | |
60 | * | |
61 | * Arguments: @floatish x@ = a floating-point number (evaluated multiple | |
62 | * times) | |
63 | * | |
64 | * Returns: Nonzero if @x@ is infinite. | |
65 | */ | |
66 | ||
67 | #ifdef isinf | |
68 | # define INFP(x) isinf(x) | |
69 | #else | |
70 | # define INFP(x) ((x) > LDBL_MAX || (x) < -LDBL_MAX) | |
71 | #endif | |
72 | ||
73 | /* --- @NEGP@ --- * | |
74 | * | |
75 | * Arguments: @floatish x@ = a floating-point number (evaluated multiple | |
76 | * times) | |
77 | * | |
78 | * Returns: Nonzero if @x@ is negative. This won't give the right answer | |
79 | * for negative zero unless the system provides explicit | |
80 | * support. | |
81 | */ | |
82 | ||
83 | #ifdef signbit | |
84 | # define NEGP(x) signbit(x) | |
85 | #else | |
86 | # define NEGP(x) ((x) < 0) | |
87 | #endif | |
88 | ||
b1a20bee MW |
89 | /*----- Floating-point encoding and decoding ------------------------------*/ |
90 | ||
67b5031e MW |
91 | /*----- That's all, folks -------------------------------------------------*/ |
92 | ||
93 | #ifdef __cplusplus | |
94 | } | |
95 | #endif | |
96 | ||
97 | #endif |