[seed] [mpfr] Added mpfr.mul



commit 404d588cd8beb3743a1427e3e34d27409e217548
Author: Matt ARSENAULT <arsenm2 rpi edu>
Date:   Wed Jul 8 18:19:19 2009 -0400

    [mpfr] Added mpfr.mul

 modules/mpfr/seed-mpfr-arithmetic.c |   61 +++++++++++++++++++++++++++++++++++
 modules/mpfr/seed-mpfr.c            |    1 +
 modules/mpfr/seed-mpfr.h            |    2 +
 3 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/modules/mpfr/seed-mpfr-arithmetic.c b/modules/mpfr/seed-mpfr-arithmetic.c
index 5d5755d..7db5216 100644
--- a/modules/mpfr/seed-mpfr-arithmetic.c
+++ b/modules/mpfr/seed-mpfr-arithmetic.c
@@ -64,6 +64,67 @@ SeedValue seed_mpfr_add (SeedContext ctx,
     return seed_value_from_int(ctx, ret, exception);
 }
 
+SeedValue seed_mpfr_mul (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;
+    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.mul", 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_mul(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_mul_d(rop, op1, dop2, rnd);
+        }
+        else
+        {
+            dop2 = seed_value_to_double(ctx, args[0], exception);
+            op1 = seed_object_get_private(args[1]);
+            mpfr_mul_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.mul", "double or mpfr_t");
+    }
+
+    return seed_value_from_int(ctx, ret, exception);
+}
+
 SeedValue seed_mpfr_sqrt (SeedContext ctx,
                           SeedObject function,
                           SeedObject this_object,
diff --git a/modules/mpfr/seed-mpfr.c b/modules/mpfr/seed-mpfr.c
index bbcb7c2..2ca61c1 100644
--- a/modules/mpfr/seed-mpfr.c
+++ b/modules/mpfr/seed-mpfr.c
@@ -987,6 +987,7 @@ seed_static_function mpfr_ns_funcs[] =
 seed_static_function mpfr_funcs[] =
 {
     {"add", seed_mpfr_add, 0},
+    {"mul", seed_mpfr_mul, 0},
     {"sqrt", seed_mpfr_sqrt, 0},
     {"rec_sqrt", seed_mpfr_rec_sqrt, 0},
     {"cbrt", seed_mpfr_cbrt, 0},
diff --git a/modules/mpfr/seed-mpfr.h b/modules/mpfr/seed-mpfr.h
index 858123e..782ff7e 100644
--- a/modules/mpfr/seed-mpfr.h
+++ b/modules/mpfr/seed-mpfr.h
@@ -87,6 +87,8 @@ DEF_SEED_MPFR_FUNC(seed_mpfr_rint_round);
 DEF_SEED_MPFR_FUNC(seed_mpfr_rint_trunc);
 
 DEF_SEED_MPFR_FUNC(seed_mpfr_add);
+DEF_SEED_MPFR_FUNC(seed_mpfr_mul);
+
 DEF_SEED_MPFR_FUNC(seed_mpfr_sin);
 DEF_SEED_MPFR_FUNC(seed_mpfr_cos);
 DEF_SEED_MPFR_FUNC(seed_mpfr_tan);



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