summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlain Frisch <alain@frisch.fr>2012-01-16 10:23:51 +0000
committerAlain Frisch <alain@frisch.fr>2012-01-16 10:23:51 +0000
commit55688836f4a4e4a76e8b3501ac6ccacf6df97603 (patch)
treea2dcc648def0b1f97cb5b5dc910e791d0b5eb19a
parentf814bc1fcd0dea0148a10bfce53578ef05ddf0e7 (diff)
downloadocaml-55688836f4a4e4a76e8b3501ac6ccacf6df97603.tar.gz
PR#4688: (Windows) special floating-point values aren't converted to strings correctly.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12030 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--Changes1
-rw-r--r--byterun/floats.c31
-rw-r--r--config/s-nt.h1
3 files changed, 32 insertions, 1 deletions
diff --git a/Changes b/Changes
index 2e139806cd..37e50cac89 100644
--- a/Changes
+++ b/Changes
@@ -56,6 +56,7 @@ Bug Fixes:
- PR#5453: configure doesn't find X11 under Ubuntu/MultiarchSpec
- PR#5469: private record type generated by functor loses abbreviation
- PR#5476: bug in native code compilation of let rec on float arrays
+- PR#4688: (Windows) special floating-point values aren't converted to strings correctly
- emacs mode: colorization of comments and strings now works correctly
Feature wishes:
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;
}
diff --git a/config/s-nt.h b/config/s-nt.h
index d3502401d4..b21b7158a9 100644
--- a/config/s-nt.h
+++ b/config/s-nt.h
@@ -27,3 +27,4 @@
#define HAS_MKTIME
#define HAS_PUTENV
#define HAS_LOCALE
+#define HAS_BROKEN_PRINTF