Skip to content

Commit 758856a

Browse files
author
Micah Scott
committed
Use INFINITY and NAN for float but not double
1 parent 150d9c2 commit 758856a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/libbson/src/bson/bson-vector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ BSON_EXPORT (bool)
195195
bson_append_vector_int8_uninit (
196196
bson_t *bson, const char *key, int key_length, size_t element_count, bson_vector_int8_view_t *view_out);
197197

198-
#define BSON_APPEND_VECTOR_INT8_UNINIT(b, key, count, view) bson_append_vector_int8_uninit (b, key, (int) strlen (key), count, view)
198+
#define BSON_APPEND_VECTOR_INT8_UNINIT(b, key, count, view) \
199+
bson_append_vector_int8_uninit (b, key, (int) strlen (key), count, view)
199200

200201
BSON_EXPORT (bool)
201202
bson_append_vector_float32_uninit (

src/libbson/tests/test-bson-vector.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ typedef struct vector_json_test_case_t {
5858
bool *test_valid;
5959
} vector_json_test_case_t;
6060

61+
static BSON_INLINE double
62+
double_inf (void)
63+
{
64+
return 1.0 / 0.0;
65+
}
66+
6167
static void
6268
translate_json_test_vector (bson_t *array_in, bson_t *array_out)
6369
{
@@ -70,9 +76,9 @@ translate_json_test_vector (bson_t *array_in, bson_t *array_out)
7076
bson_array_builder_t *builder = bson_array_builder_new ();
7177
while (bson_iter_next (&iter_in)) {
7278
if (BSON_ITER_HOLDS_UTF8 (&iter_in) && 0 == strcmp ("inf", bson_iter_utf8 (&iter_in, NULL))) {
73-
BSON_ASSERT (bson_array_builder_append_double (builder, INFINITY));
79+
BSON_ASSERT (bson_array_builder_append_double (builder, double_inf ()));
7480
} else if (BSON_ITER_HOLDS_UTF8 (&iter_in) && 0 == strcmp ("-inf", bson_iter_utf8 (&iter_in, NULL))) {
75-
BSON_ASSERT (bson_array_builder_append_double (builder, -INFINITY));
81+
BSON_ASSERT (bson_array_builder_append_double (builder, -double_inf ()));
7682
} else {
7783
BSON_ASSERT (bson_array_builder_append_iter (builder, &iter_in));
7884
}
@@ -315,10 +321,10 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
315321

316322
double expected_double;
317323
if (BSON_ITER_HOLDS_UTF8 (&expected_iter) && 0 == strcmp ("inf", bson_iter_utf8 (&expected_iter, NULL))) {
318-
expected_double = INFINITY;
324+
expected_double = double_inf ();
319325
} else if (BSON_ITER_HOLDS_UTF8 (&expected_iter) &&
320326
0 == strcmp ("-inf", bson_iter_utf8 (&expected_iter, NULL))) {
321-
expected_double = -INFINITY;
327+
expected_double = -double_inf ();
322328
} else if (BSON_ITER_HOLDS_DOUBLE (&expected_iter)) {
323329
expected_double = bson_iter_double (&expected_iter);
324330
} else {
@@ -1235,7 +1241,7 @@ test_bson_vector_example_float32_const_view (void)
12351241
// setup: construct a sample document
12361242
bson_t doc = BSON_INITIALIZER;
12371243
{
1238-
static const float values[] = {5.0f, -1e10f, (float) INFINITY, (float) NAN, -1.0f};
1244+
static const float values[] = {5.0f, -1e10f, INFINITY, NAN, -1.0f};
12391245
bson_vector_float32_view_t view;
12401246
BSON_ASSERT (BSON_APPEND_VECTOR_FLOAT32_UNINIT (&doc, "vector", sizeof values / sizeof values[0], &view));
12411247
BSON_ASSERT (bson_vector_float32_view_write (view, values, sizeof values / sizeof values[0], 0));

0 commit comments

Comments
 (0)