Skip to content

Commit faf2b6e

Browse files
committed
Avoid using complex number literal extension, instead relying on
standard-defined memory layout.
1 parent fbf3902 commit faf2b6e

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

include/binsparse/detail/declamp_values.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ static inline void bsp_matrix_declamp_values(bsp_matrix_t matrix) {
4242
real_value = bsp_suitesparse_declamp_impl_(real_value);
4343
imaginary_value = bsp_suitesparse_declamp_impl_(imaginary_value);
4444

45-
values[i] = real_value + 1j * imaginary_value;
45+
double _Complex complex_value;
46+
47+
((double*) &complex_value)[0] = real_value;
48+
((double*) &complex_value)[1] = imaginary_value;
49+
50+
values[i] = complex_value;
4651
}
4752
}
4853
}

include/binsparse/matrix_market/matrix_market_read.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ static inline bsp_matrix_t bsp_mmread_explicit_array(const char* file_path,
8989
double real_value, imaginary_value;
9090
sscanf(buf, "%lf %lf", &real_value, &imaginary_value);
9191

92-
double _Complex value = real_value + 1j * imaginary_value;
92+
double _Complex value;
93+
94+
((double*) &value)[0] = real_value;
95+
((double*) &value)[1] = imaginary_value;
9396

9497
size_t i = count % matrix.ncols;
9598
size_t j = count / matrix.ncols;
@@ -203,12 +206,15 @@ bsp_mmread_explicit_coordinate(const char* file_path, bsp_type_t value_type,
203206
bsp_array_write(matrix.indices_1, count, j);
204207
} else if (mm_type == BSP_MM_COMPLEX) {
205208
unsigned long long i, j;
206-
double real_value, complex_value;
207-
sscanf(buf, "%llu %llu %lf %lf", &i, &j, &real_value, &complex_value);
209+
double real_value, imaginary_value;
210+
sscanf(buf, "%llu %llu %lf %lf", &i, &j, &real_value, &imaginary_value);
208211
i--;
209212
j--;
210213

211-
double _Complex value = real_value + 1j * complex_value;
214+
double _Complex value;
215+
216+
((double*) &value)[0] = real_value;
217+
((double*) &value)[1] = imaginary_value;
212218

213219
bsp_array_write(matrix.values, count, value);
214220
bsp_array_write(matrix.indices_0, count, i);

0 commit comments

Comments
 (0)