This commit is contained in:
Fredrik Høisæther Rasch 2017-10-27 11:34:57 +02:00 • committed by Andreas Rumpf
commit 8c94a00e02
2 changed files with 28 additions and 1 deletions

View file

@ -396,8 +396,13 @@ typedef struct TStringDesc* string;
#define GenericSeqSize sizeof(TGenericSeq) #define GenericSeqSize sizeof(TGenericSeq)
#define paramCount() cmdCount #define paramCount() cmdCount
// NAN definition copied from math.h included in the Windows SDK version 10.0.14393.0
#ifndef NAN #ifndef NAN
# define NAN (0.0 / 0.0) #ifndef _HUGE_ENUF
#define _HUGE_ENUF 1e+300 // _HUGE_ENUF*_HUGE_ENUF must overflow
#endif
#define NAN_INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF))
#define NAN ((float)(NAN_INFINITY * 0.0F))
#endif #endif
#ifndef INF #ifndef INF

22
tests/float/tfloatnan.nim Normal file
View file

@ -0,0 +1,22 @@
discard """
file: "tfloatnan.nim"
output: '''Nim: nan
Nim: nan (float)
C: nan (float)
Nim: nan (double)
C: nan (double)
'''
"""
proc printf(formatstr: cstring): int {.importc: "printf", varargs, header: "<stdio.h>".}
let f = NaN
echo "Nim: ", f
let f32: float32 = NaN
echo "Nim: ", f32, " (float)"
discard printf("C: %f (float)\n", f32)
let f64: float64 = NaN
echo "Nim: ", f64, " (double)"
discard printf("C: %lf (double)\n", f64)