Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_number.h
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Number Header
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 #ifndef __AFW_NUMBER_H__
10 #define __AFW_NUMBER_H__
11 
12 #include "afw_common.h"
13 #include <float.h>
14 
30 
31 #define AFW_NUMBER_Q_INF "INF"
32 #define AFW_NUMBER_Q_INFINITY "Infinity"
33 #define AFW_NUMBER_Q_NEGATIVE_INF "-INF"
34 #define AFW_NUMBER_Q_NEGATIVE_INFINITY "-Infinity"
35 #define AFW_NUMBER_Q_NAN "NaN"
36 #define AFW_NUMBER_Q_NEGATIVE_NAN "-NaN"
37 #define AFW_NUMBER_Q_EXPONENT_ZERO "E0"
38 
44 AFW_DEFINE_STATIC_INLINE(afw_boolean_t)
46 {
47  return (d <= DBL_MAX && d >= -DBL_MAX);
48 }
49 
50 
56 AFW_DEFINE_STATIC_INLINE(afw_boolean_t)
58 {
59  return (d > DBL_MAX);
60 }
61 
62 
68 AFW_DEFINE_STATIC_INLINE(afw_boolean_t)
70 {
71  return (d < -DBL_MAX);
72 }
73 
74 
83 AFW_DEFINE_STATIC_INLINE(afw_boolean_t)
85 {
86  return !(d == d);
87 }
88 
89 
104  const afw_utf8_octet_t *cursor, afw_size_t len,
105  afw_integer_t *i, afw_double_t *d, afw_boolean_t *is_double,
106  const afw_pool_t *p, afw_xctx_t *xctx);
107 
108 
118 #define afw_number_parse_integer(cursor, len, i, p, xctx) \
119  afw_number_parse(cursor, len, i, NULL, NULL, p, xctx)
120 
121 
131 #define afw_number_parse_double(cursor, len, d, p, xctx) \
132  afw_number_parse(cursor, len, NULL, d, NULL, p, xctx)
133 
134 
155 AFW_DECLARE(const afw_utf8_t *)
157  afw_double_t d,
158  const afw_pool_t *p, afw_xctx_t *xctx);
159 
160 
168 AFW_DEFINE_STATIC_INLINE(afw_double_t)
170  const afw_utf8_t *s, const afw_pool_t *p, afw_xctx_t *xctx)
171 {
172  afw_double_t d;
173  afw_boolean_t is_double;
174  afw_size_t len;
175 
176  len = afw_number_parse(s->s, s->len, NULL, &d, &is_double, p, xctx);
177  if (!is_double || len != s->len) {
178  AFW_THROW_ERROR_Z(general, "Invalid double", xctx);
179  }
180  return d;
181 }
182 
183 
184 
192 AFW_DECLARE(const afw_utf8_t *)
194  afw_integer_t i,
195  const afw_pool_t *p, afw_xctx_t *xctx);
196 
197 
198 
211 
212 
220 AFW_DEFINE_STATIC_INLINE(afw_integer_t)
222  const afw_utf8_t *s, const afw_pool_t *p, afw_xctx_t *xctx)
223 {
224  afw_integer_t i;
225  afw_boolean_t is_double;
226  afw_size_t len;
227 
228  len = afw_number_parse(s->s, s->len, &i, NULL, &is_double, p, xctx);
229  if (is_double || len != s->len) {
230  AFW_THROW_ERROR_Z(general, "Invalid integer", xctx);
231  }
232  return i;
233 }
234 
235 
236 
242 AFW_DECLARE(int)
244 
245 
246 
252 AFW_DEFINE(int)
254 
255 
256 AFW_END_DECLARES
257 
260 #endif /* __AFW_NUMBER_H__ */
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Common Header.
#define AFW_BEGIN_DECLARES
#define AFW_DECLARE(type)
Declare a public afw function.
double afw_double_t
Normal AFW number is double.
Definition: afw_common.h:202
_Bool afw_boolean_t
Definition: afw_common.h:373
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
Definition: afw_common.h:236
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
apr_int64_t afw_integer_t
typedef for big signed int.
Definition: afw_common.h:321
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:283
int afw_number_bytes_needed_size_t(afw_size_t i)
Determine bytes needed to hold printable size_t.
Definition: afw_number.c:425
afw_double_t afw_number_utf8_to_double(const afw_utf8_t *s, const afw_pool_t *p, afw_xctx_t *xctx)
Convert a utf8 string to double in specified pool.
Definition: afw_number.h:169
afw_integer_t afw_number_utf8_to_integer(const afw_utf8_t *s, const afw_pool_t *p, afw_xctx_t *xctx)
Convert a utf8 string to integer in specified pool.
Definition: afw_number.h:221
afw_boolean_t afw_number_is_negative_infinity(double d)
Determine if double is negative infinity.
Definition: afw_number.h:69
afw_boolean_t afw_number_is_NaN(double d)
Determine if double is not a number.
Definition: afw_number.h:84
afw_boolean_t afw_number_is_finite(double d)
Determine if double is finite.
Definition: afw_number.h:45
afw_size_t afw_number_parse(const afw_utf8_octet_t *cursor, afw_size_t len, afw_integer_t *i, afw_double_t *d, afw_boolean_t *is_double, const afw_pool_t *p, afw_xctx_t *xctx)
Parse an integer or double using specified pool for work area.
Definition: afw_number.c:203
afw_size_t afw_number_integer_set_u8(afw_integer_t i, afw_utf8_octet_t *s, afw_size_t len, afw_xctx_t *xctx)
Convert an integer to u8 in supplied buffer.
Definition: afw_number.c:187
const afw_utf8_t * afw_number_double_to_utf8(afw_double_t d, const afw_pool_t *p, afw_xctx_t *xctx)
Convert a double to utf8 in specified pool.
Definition: afw_number.c:19
afw_number_bytes_needed_integer(afw_integer_t i)
Determine bytes needed to hold printable afw_integer_t.
Definition: afw_number.c:437
afw_boolean_t afw_number_is_positive_infinity(double d)
Determine if double is positive infinity.
Definition: afw_number.h:57
const afw_utf8_t * afw_number_integer_to_utf8(afw_integer_t i, const afw_pool_t *p, afw_xctx_t *xctx)
Convert an integer to utf8 in specified pool.
Definition: afw_number.c:168
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_xctx public struct.