Skip to content

Commit 6c42775

Browse files
authored
Merge pull request #28915 from charris/backport-28892
MAINT: Avoid dereferencing/strict aliasing warnings
2 parents 4277e7c + 87d1d8a commit 6c42775

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

numpy/_core/include/numpy/npy_math.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ NPY_INPLACE npy_longdouble npy_heavisidel(npy_longdouble x, npy_longdouble h0);
363363
static inline double npy_creal(const npy_cdouble z)
364364
{
365365
#if defined(__cplusplus)
366-
return ((double *) &z)[0];
366+
return z._Val[0];
367367
#else
368368
return creal(z);
369369
#endif
@@ -377,7 +377,7 @@ static inline void npy_csetreal(npy_cdouble *z, const double r)
377377
static inline double npy_cimag(const npy_cdouble z)
378378
{
379379
#if defined(__cplusplus)
380-
return ((double *) &z)[1];
380+
return z._Val[1];
381381
#else
382382
return cimag(z);
383383
#endif
@@ -391,7 +391,7 @@ static inline void npy_csetimag(npy_cdouble *z, const double i)
391391
static inline float npy_crealf(const npy_cfloat z)
392392
{
393393
#if defined(__cplusplus)
394-
return ((float *) &z)[0];
394+
return z._Val[0];
395395
#else
396396
return crealf(z);
397397
#endif
@@ -405,7 +405,7 @@ static inline void npy_csetrealf(npy_cfloat *z, const float r)
405405
static inline float npy_cimagf(const npy_cfloat z)
406406
{
407407
#if defined(__cplusplus)
408-
return ((float *) &z)[1];
408+
return z._Val[1];
409409
#else
410410
return cimagf(z);
411411
#endif
@@ -419,7 +419,7 @@ static inline void npy_csetimagf(npy_cfloat *z, const float i)
419419
static inline npy_longdouble npy_creall(const npy_clongdouble z)
420420
{
421421
#if defined(__cplusplus)
422-
return ((longdouble_t *) &z)[0];
422+
return (npy_longdouble)z._Val[0];
423423
#else
424424
return creall(z);
425425
#endif
@@ -433,7 +433,7 @@ static inline void npy_csetreall(npy_clongdouble *z, const longdouble_t r)
433433
static inline npy_longdouble npy_cimagl(const npy_clongdouble z)
434434
{
435435
#if defined(__cplusplus)
436-
return ((longdouble_t *) &z)[1];
436+
return (npy_longdouble)z._Val[1];
437437
#else
438438
return cimagl(z);
439439
#endif

0 commit comments

Comments
 (0)