2003-11-12 Zoltan Varga <vargaz@freemail.hu>
authorZoltan Varga <vargaz@gmail.com>
Wed, 12 Nov 2003 13:11:05 +0000 (13:11 -0000)
committerZoltan Varga <vargaz@gmail.com>
Wed, 12 Nov 2003 13:11:05 +0000 (13:11 -0000)
* mono-math.h mono-math.c: New file which contains implementations of
math functions/macros which are missing on some platforms.

svn path=/trunk/mono/; revision=19870

mono/utils/ChangeLog
mono/utils/Makefile.am
mono/utils/mono-math.c [new file with mode: 0644]
mono/utils/mono-math.h [new file with mode: 0644]

index 221704b043b1fcf197dce0372216e40df6d2f120..dc977e7b2e83cf234c750a620b5ceacc442674c3 100644 (file)
@@ -1,3 +1,8 @@
+2003-11-12  Zoltan Varga  <vargaz@freemail.hu>
+
+       * mono-math.h mono-math.c: New file which contains implementations of
+       math functions/macros which are missing on some platforms.
+
 2003-11-10  Dick Porter  <dick@ximian.com>
 
        * strenc.c: Use platform-endian UTF16
index 8cc86242eac7a04e75c4db1506fa1369b0b536a5..e7958ff2896f1194778893e0469e952f1028a1be 100644 (file)
@@ -8,6 +8,7 @@ libmonoutils_la_SOURCES = \
        mono-sha1.c     \
        mono-logger.c   \
        monobitset.c    \
+       mono-math.c  \
        strtod.h        \
        strtod.c        \
        strenc.h        \
@@ -19,7 +20,8 @@ libmonoutilsinclude_HEADERS = \
        monobitset.h    \
        mono-digest.h   \
        mono-logger.h   \
-       mono-hash.h
+       mono-hash.h             \
+       mono-math.h
 
 EXTRA_DIST = ChangeLog
 
diff --git a/mono/utils/mono-math.c b/mono/utils/mono-math.c
new file mode 100644 (file)
index 0000000..ccff08c
--- /dev/null
@@ -0,0 +1,22 @@
+
+#include "mono-math.h"
+
+#ifndef HAVE_SIGNBIT
+
+int
+mono_signbit_float (float x)
+{
+       union { float f; int i; } u = { f: x };
+
+       return u.i < 0;
+}
+
+int
+mono_signbit_double (double x)
+{
+       union { double d; int i[2]; } u = { d: x };
+
+       return u.i [1] < 0;
+}
+
+#endif
diff --git a/mono/utils/mono-math.h b/mono/utils/mono-math.h
new file mode 100644 (file)
index 0000000..90d14b6
--- /dev/null
@@ -0,0 +1,20 @@
+
+#ifndef __MONO_SIGNBIT_H__
+#define __MONO_SIGNBIT_H__
+
+#include <math.h>
+
+#ifdef HAVE_SIGNBIT
+#define mono_signbit signbit
+#else
+#define mono_signbit(x) (sizeof (x) == sizeof (float) ? mono_signbit_float (x) : mono_signbit_double (x))
+
+int
+mono_signbit_double (double x);
+
+int
+mono_signbit_float (float x);
+
+#endif
+
+#endif