Skip to content

Commit 41190cc

Browse files
committed
refactor: add IGRAPH_I_STRINGIFY
1 parent 7c4c690 commit 41190cc

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

include/igraph_decls.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
# define IGRAPH_ASSUME(expr) /* empty */
4141
#endif
4242

43+
/* IGRAPH_I_STRINGIFY(X) evaluates X and converts the result to a string. */
44+
#define IGRAPH_I_STRINGIFY_I(X) #X
45+
#define IGRAPH_I_STRINGIFY(X) IGRAPH_I_STRINGIFY_I(X)
46+
4347
/* Include the definition of macros controlling symbol visibility */
4448
#include "igraph_export.h"
4549

src/core/printing.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@
5252
*/
5353
#ifdef DBL_DIG
5454
/* Use DBL_DIG to determine the maximum precision used for %g */
55-
#define STRINGIFY_HELPER(x) #x
56-
#define STRINGIFY(x) STRINGIFY_HELPER(x)
57-
#define IGRAPH_REAL_PRINTF_PRECISE_FORMAT "%." STRINGIFY(DBL_DIG) "g"
55+
#define IGRAPH_REAL_PRINTF_PRECISE_FORMAT "%." IGRAPH_I_STRINGIFY(DBL_DIG) "g"
5856
#else
5957
/* Assume a precision of 15 digits for %g, which is what IEEE-754 doubles require. */
6058
#define IGRAPH_REAL_PRINTF_PRECISE_FORMAT "%.15g"

tests/benchmarks/igraph_qsort.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
/* This program benchmarks igraph_qsort() indirectly through vector_sort() */
66

7-
#define STRINGIFY(x) #x
8-
#define TOSTRING(x) STRINGIFY(x)
9-
107
int main(void) {
118
igraph_vector_int_t vec;
129

@@ -24,7 +21,7 @@ int main(void) {
2421
for (igraph_integer_t i=0; i < N; i++) {
2522
VECTOR(vec)[i] = RNG_INTEGER(0, N-1);
2623
}
27-
BENCH("Sort vector of length " TOSTRING(N), igraph_vector_int_sort(&vec));
24+
BENCH("Sort vector of length " IGRAPH_I_STRINGIFY(N), igraph_vector_int_sort(&vec));
2825

2926
#undef N
3027
#define N 1000000
@@ -33,7 +30,7 @@ int main(void) {
3330
for (igraph_integer_t i=0; i < N; i++) {
3431
VECTOR(vec)[i] = RNG_INTEGER(0, N-1);
3532
}
36-
BENCH("Sort vector of length " TOSTRING(N), igraph_vector_int_sort(&vec));
33+
BENCH("Sort vector of length " IGRAPH_I_STRINGIFY(N), igraph_vector_int_sort(&vec));
3734

3835
#undef N
3936
#define N 100000
@@ -42,7 +39,7 @@ int main(void) {
4239
for (igraph_integer_t i=0; i < N; i++) {
4340
VECTOR(vec)[i] = RNG_INTEGER(0, N-1);
4441
}
45-
BENCH("Sort vector of length " TOSTRING(N), igraph_vector_int_sort(&vec));
42+
BENCH("Sort vector of length " IGRAPH_I_STRINGIFY(N), igraph_vector_int_sort(&vec));
4643

4744
RNG_END();
4845

0 commit comments

Comments
 (0)