Skip to content

Commit 6aeec11

Browse files
committedJun 28, 2024
MAINT: Avoid type punning by copying (grrr...)
1 parent 13ff866 commit 6aeec11

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed
 

‎src/vnorm/vnorm_gufunc.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,22 @@
2222
static inline float
2323
my_cabs(npy_cfloat z)
2424
{
25-
return std::abs(*(reinterpret_cast<std::complex<float> *>(&z)));
25+
std::complex<float> zs{npy_crealf(z), npy_cimagf(z)};
26+
return std::abs(zs);
2627
}
2728

2829
static inline double
2930
my_cabs(npy_cdouble z)
3031
{
31-
return std::abs(*(reinterpret_cast<std::complex<double> *>(&z)));
32+
std::complex<double> zs{npy_creal(z), npy_cimag(z)};
33+
return std::abs(zs);
3234
}
3335

3436
static inline long double
3537
my_cabs(npy_clongdouble z)
3638
{
37-
return std::abs(*(reinterpret_cast<std::complex<long double> *>(&z)));
39+
std::complex<long double> zs{npy_creall(z), npy_cimagl(z)};
40+
return std::abs(zs);
3841
}
3942

4043
//

0 commit comments

Comments
 (0)