diff options
author | Alain Frisch <alain@frisch.fr> | 2012-01-18 08:31:11 +0000 |
---|---|---|
committer | Alain Frisch <alain@frisch.fr> | 2012-01-18 08:31:11 +0000 |
commit | c45bcb892d78f3182acb2805aef7ec6e23cce42a (patch) | |
tree | b92b5d6becb9e67a198bc2e070d748eeef62bc3d /byterun/floats.c | |
parent | cdbb84ec682704379bac21a633cbd2b9e93b35a8 (diff) | |
parent | 869feeb00704e0640c45ffe6aee6cc13e4077f79 (diff) | |
download | ocaml-unused_declarations.tar.gz |
Synchronize with trunk.unused_declarations
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/unused_declarations@12034 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun/floats.c')
-rw-r--r-- | byterun/floats.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/byterun/floats.c b/byterun/floats.c index 51cfb23f18..f708d70f70 100644 --- a/byterun/floats.c +++ b/byterun/floats.c @@ -28,6 +28,12 @@ #include "reverse.h" #include "stacks.h" +#ifdef _MSC_VER +#include <float.h> +#define isnan _isnan +#define isfinite _finite +#endif + #ifdef ARCH_ALIGN_DOUBLE CAMLexport double caml_Double_val(value val) @@ -77,7 +83,11 @@ CAMLprim value caml_format_float(value fmt, value arg) char * p; char * dest; value res; + double d = Double_val(arg); +#ifdef HAS_BROKEN_PRINTF + if (isfinite(d)) { +#endif prec = MAX_DIGITS; for (p = String_val(fmt); *p != 0; p++) { if (*p >= '0' && *p <= '9') { @@ -98,11 +108,30 @@ CAMLprim value caml_format_float(value fmt, value arg) } else { dest = caml_stat_alloc(prec); } - sprintf(dest, String_val(fmt), Double_val(arg)); + sprintf(dest, String_val(fmt), d); res = caml_copy_string(dest); if (dest != format_buffer) { caml_stat_free(dest); } +#ifdef HAS_BROKEN_PRINTF + } else { + if (isnan(d)) + { + res = caml_copy_string("nan"); + } + else + { + if (d > 0) + { + res = caml_copy_string("inf"); + } + else + { + res = caml_copy_string("-inf"); + } + } + } +#endif return res; } |