From 668b5415efff623fdc483ef621a3a3a642a996ac Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 21 Nov 2024 11:09:25 +0800 Subject: [PATCH 1/2] Improve the patch for NaN with MSVC --- src/gmt_notposix.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gmt_notposix.h b/src/gmt_notposix.h index 570bdb9f612..bdc9a006fc1 100644 --- a/src/gmt_notposix.h +++ b/src/gmt_notposix.h @@ -331,11 +331,9 @@ #ifndef NAN # ifdef _MSC_VER - static const double _NAN = (-(float)(((float)(1e+300 * 1e+300)) * 0.0F)); -# define NAN _NAN +# define NAN (-(float)(((float)(1e+300 * 1e+300)) * 0.0F)); # else /* _MSC_VER */ - static const double _NAN = (HUGE_VAL-HUGE_VAL); -# define NAN _NAN +# define NAN (HUGE_VAL-HUGE_VAL); # endif /* _MSC_VER */ #endif /* !NAN */ From 03b6044b3e5c2b6b639ff6c588c864690ab42c6b Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 22 Nov 2024 10:17:06 +0800 Subject: [PATCH 2/2] Try the new patch --- src/gmt_notposix.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gmt_notposix.h b/src/gmt_notposix.h index bdc9a006fc1..8e170df709d 100644 --- a/src/gmt_notposix.h +++ b/src/gmt_notposix.h @@ -331,9 +331,16 @@ #ifndef NAN # ifdef _MSC_VER -# define NAN (-(float)(((float)(1e+300 * 1e+300)) * 0.0F)); +# ifndef INFINITY +# ifndef _HUGE_ENUF +# define _HUGE_ENUF 1e+300 // _HUGE_ENUF*_HUGE_ENUF must overflow +# endif +# define INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF)) +# endif +# define NAN (-(float)(INFINITY * 0.0F)) # else /* _MSC_VER */ -# define NAN (HUGE_VAL-HUGE_VAL); + static const double _NAN = (HUGE_VAL-HUGE_VAL); +# define NAN _NAN # endif /* _MSC_VER */ #endif /* !NAN */