[seed] [mpfr] Split up mpfr module into multiple files



commit d7d77a8110245c8a083b4ab3169f2515ab989113
Author: Matt ARSENAULT <arsenm2 rpi edu>
Date:   Sun Jul 5 01:12:03 2009 -0400

    [mpfr] Split up mpfr module into multiple files

 modules/mpfr/Makefile.am            |    2 +
 modules/mpfr/seed-mpfr-arithmetic.c |   66 ++++++++++++++++++++++++
 modules/mpfr/seed-mpfr-trig.c       |   36 +++++++++++++
 modules/mpfr/seed-mpfr.c            |   96 +----------------------------------
 modules/mpfr/seed-mpfr.h            |   14 +++++
 5 files changed, 120 insertions(+), 94 deletions(-)
---
diff --git a/modules/mpfr/Makefile.am b/modules/mpfr/Makefile.am
index ae15fd7..55e2642 100644
--- a/modules/mpfr/Makefile.am
+++ b/modules/mpfr/Makefile.am
@@ -7,6 +7,8 @@ seedlib_LTLIBRARIES = \
 
 libseed_mpfr_la_SOURCES = \
 	seed-mpfr.c
+	seed-mpfr-trig.c
+	seed-mpfr-arithmetic.c
 
 AM_CPPFLAGS = \
 	-I top_srcdir@/libseed/ \
diff --git a/modules/mpfr/seed-mpfr-arithmetic.c b/modules/mpfr/seed-mpfr-arithmetic.c
new file mode 100644
index 0000000..eccc98d
--- /dev/null
+++ b/modules/mpfr/seed-mpfr-arithmetic.c
@@ -0,0 +1,66 @@
+
+#include <mpfr.h>
+#include "seed-mpfr.h"
+
+/* This is a bit disgusting. Oh well. */
+SeedValue seed_mpfr_add (SeedContext ctx,
+                         SeedObject function,
+                         SeedObject this_object,
+                         gsize argument_count,
+                         const SeedValue args[],
+                         SeedException * exception)
+{
+    mpfr_rnd_t rnd;
+    mpfr_ptr rop, op1, op2;
+    gdouble dop1, dop2;
+    SeedObject obj;
+    gint ret;
+    seed_mpfr_t argt1, argt2;
+    /* only want 1 double argument. alternatively, could accept 2,
+       add those, and set from the result*/
+
+    CHECK_ARG_COUNT("mpfr.add", 3);
+
+    rop = seed_object_get_private(this_object);
+    rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
+
+    argt1 = seed_mpfr_arg_type(ctx, args[0], exception);
+    argt2 = seed_mpfr_arg_type(ctx, args[1], exception);
+
+    if ( (argt1 & argt2) == SEED_MPFR_MPFR )
+    {
+        /* both mpfr_t */
+        op1 = seed_object_get_private(args[0]);
+        op2 = seed_object_get_private(args[1]);
+        ret = mpfr_add(rop, op1, op2, rnd);
+    }
+    else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
+    {
+        /* a double and an mpfr_t. Figure out the order */
+        if ( argt1 == SEED_MPFR_MPFR )
+        {
+            op1 = seed_object_get_private(args[0]);
+            dop2 = seed_value_to_double(ctx, args[1], exception);
+            mpfr_add_d(rop, op1, dop2, rnd);
+        }
+        else
+        {
+            dop2 = seed_value_to_double(ctx, args[0], exception);
+            op1 = seed_object_get_private(args[1]);
+            mpfr_add_d(rop, op1, dop2, rnd);
+        }
+    }
+    else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
+    {
+        /* 2 doubles. hopefully doesn't happen */
+        dop1 = seed_value_to_double(ctx, args[0], exception);
+        dop2 = seed_value_to_double(ctx, args[1], exception);
+        ret = mpfr_set_d(rop, dop1 + dop2, rnd);
+    }
+    else
+    {
+        TYPE_EXCEPTION("mpfr.add", "double or mpfr_t");
+    }
+
+    return seed_value_from_int(ctx, ret, exception);
+}
diff --git a/modules/mpfr/seed-mpfr-trig.c b/modules/mpfr/seed-mpfr-trig.c
new file mode 100644
index 0000000..94c5e5c
--- /dev/null
+++ b/modules/mpfr/seed-mpfr-trig.c
@@ -0,0 +1,36 @@
+
+#include <mpfr.h>
+
+#include "seed-mpfr.h"
+
+SeedValue seed_mpfr_sin (SeedContext ctx,
+                         SeedObject function,
+                         SeedObject this_object,
+                         gsize argument_count,
+                         const SeedValue args[],
+                         SeedException * exception)
+{
+    mpfr_rnd_t rnd;
+    mpfr_ptr rop, op;
+    gint ret;
+
+    CHECK_ARG_COUNT("mpfr.sin", 2);
+
+    rop = seed_object_get_private(this_object);
+    rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
+
+    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
+    {
+        op = seed_object_get_private(args[0]);
+    }
+    else
+    {
+        TYPE_EXCEPTION("mpfr.sin", "mpfr_t");
+    }
+
+    ret = mpfr_sin(rop, op, rnd);
+
+    return seed_value_from_int(ctx, ret, exception);
+}
+
+
diff --git a/modules/mpfr/seed-mpfr.c b/modules/mpfr/seed-mpfr.c
index f5be0a5..90fa80f 100644
--- a/modules/mpfr/seed-mpfr.c
+++ b/modules/mpfr/seed-mpfr.c
@@ -3,6 +3,8 @@
 #include <stdio.h>
 #include <mpfr.h>
 
+#include "seed-mpfr.h"
+
 SeedObject ns_ref;
 SeedClass mpfr_class;
 
@@ -91,36 +93,6 @@ seed_mpfr_out_str (SeedContext ctx,
                                 exception);
 }
 
-static SeedValue
-seed_mpfr_sin (SeedContext ctx,
-               SeedObject function,
-               SeedObject this_object,
-               gsize argument_count,
-               const SeedValue args[],
-               SeedException * exception)
-{
-    mpfr_rnd_t rnd;
-    mpfr_ptr rop, op;
-    gint ret;
-
-    CHECK_ARG_COUNT("mpfr.sin", 2);
-
-    rop = seed_object_get_private(this_object);
-    rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
-
-    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
-    {
-        op = seed_object_get_private(args[0]);
-    }
-    else
-    {
-        TYPE_EXCEPTION("mpfr.sin", "mpfr_t");
-    }
-
-    ret = mpfr_sin(rop, op, rnd);
-
-    return seed_value_from_int(ctx, ret, exception);
-}
 
 static SeedValue
 seed_mpfr_const_pi (SeedContext ctx,
@@ -188,70 +160,6 @@ seed_mpfr_const_catalan (SeedContext ctx,
     return seed_value_from_int(ctx, ret, exception);
 }
 
-/* This is a bit disgusting. Oh well. */
-static SeedValue
-seed_mpfr_add (SeedContext ctx,
-               SeedObject function,
-               SeedObject this_object,
-               gsize argument_count,
-               const SeedValue args[],
-               SeedException * exception)
-{
-    mpfr_rnd_t rnd;
-    mpfr_ptr rop, op1, op2;
-    gdouble dop1, dop2;
-    SeedObject obj;
-    gint ret;
-    seed_mpfr_t argt1, argt2;
-    /* only want 1 double argument. alternatively, could accept 2,
-       add those, and set from the result*/
-
-    CHECK_ARG_COUNT("mpfr.add", 3);
-
-    rop = seed_object_get_private(this_object);
-    rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
-
-    argt1 = seed_mpfr_arg_type(ctx, args[0], exception);
-    argt2 = seed_mpfr_arg_type(ctx, args[1], exception);
-
-    if ( (argt1 & argt2) == SEED_MPFR_MPFR )
-    {
-        /* both mpfr_t */
-        op1 = seed_object_get_private(args[0]);
-        op2 = seed_object_get_private(args[1]);
-        ret = mpfr_add(rop, op1, op2, rnd);
-    }
-    else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
-    {
-        /* a double and an mpfr_t. Figure out the order */
-        if ( argt1 == SEED_MPFR_MPFR )
-        {
-            op1 = seed_object_get_private(args[0]);
-            dop2 = seed_value_to_double(ctx, args[1], exception);
-            mpfr_add_d(rop, op1, dop2, rnd);
-        }
-        else
-        {
-            dop2 = seed_value_to_double(ctx, args[0], exception);
-            op1 = seed_object_get_private(args[1]);
-            mpfr_add_d(rop, op1, dop2, rnd);
-        }
-    }
-    else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
-    {
-        /* 2 doubles. hopefully doesn't happen */
-        dop1 = seed_value_to_double(ctx, args[0], exception);
-        dop2 = seed_value_to_double(ctx, args[1], exception);
-        ret = mpfr_set_d(rop, dop1 + dop2, rnd);
-    }
-    else
-    {
-        TYPE_EXCEPTION("mpfr.add", "double or mpfr_t");
-    }
-
-    return seed_value_from_int(ctx, ret, exception);
-}
-
 static SeedValue
 seed_mpfr_get_exp (SeedContext ctx,
                    SeedObject this_object,
diff --git a/modules/mpfr/seed-mpfr.h b/modules/mpfr/seed-mpfr.h
new file mode 100644
index 0000000..eee749c
--- /dev/null
+++ b/modules/mpfr/seed-mpfr.h
@@ -0,0 +1,14 @@
+#ifndef _SEED_MPFR_H_
+#define _SEED_MPFR_H_
+
+#include <seed-module.h>
+#include <seed.h>
+
+#define DEF_SEED_MPFR_FUNC(name) SeedValue name( SeedContext,SeedObject,\
+SeedObject, gsize, const SeedValue[], SeedException*)
+
+DEF_SEED_MPFR_FUNC(seed_mpfr_add);
+DEF_SEED_MPFR_FUNC(seed_mpfr_sin);
+
+#endif      /* _SEED_MFPR_H_ */
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]