[seed] [mpfr] Added mpfr.pow



commit bf1f335aeb7dd36ff5cc05b891530bfff5e2775d
Author: Matt ARSENAULT <arsenm2 rpi edu>
Date:   Wed Jul 8 18:50:13 2009 -0400

    [mpfr] Added mpfr.pow

 modules/mpfr/seed-mpfr-arithmetic.c |   65 +++++++++++++++++++++++++++++++++++
 modules/mpfr/seed-mpfr.c            |    1 +
 modules/mpfr/seed-mpfr.h            |    1 +
 3 files changed, 67 insertions(+), 0 deletions(-)
---
diff --git a/modules/mpfr/seed-mpfr-arithmetic.c b/modules/mpfr/seed-mpfr-arithmetic.c
index fba6205..f06758c 100644
--- a/modules/mpfr/seed-mpfr-arithmetic.c
+++ b/modules/mpfr/seed-mpfr-arithmetic.c
@@ -247,6 +247,71 @@ SeedValue seed_mpfr_div (SeedContext ctx,
     return seed_value_from_int(ctx, ret, exception);
 }
 
+
+SeedValue seed_mpfr_pow (SeedContext ctx,
+                         SeedObject function,
+                         SeedObject this_object,
+                         gsize argument_count,
+                         const SeedValue args[],
+                         SeedException * exception)
+{
+    mpfr_rnd_t rnd;
+    mpfr_ptr rop, op1, op2;
+    gint ret;
+    glong iop;
+    gulong uiop1, uiop2;
+    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.pow", 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_pow(rop, op1, op2, rnd);
+    }
+    else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
+    {
+        /* a double and an mpfr_t. Figure out the order */
+        /* FIXME: is this switching ui and si bad? si_pow doesn't exist,
+           and it's all from double anyway */
+        if ( argt1 == SEED_MPFR_MPFR )
+        {
+            op1 = seed_object_get_private(args[0]);
+            iop = seed_value_to_long(ctx, args[1], exception);
+            ret = mpfr_pow_si(rop, op1, iop, rnd);
+        }
+        else
+        {
+            uiop1 = seed_value_to_ulong(ctx, args[0], exception);
+            op2 = seed_object_get_private(args[1]);
+            ret = mpfr_ui_pow(rop, uiop1, op2, rnd);
+        }
+    }
+    else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
+    {
+        /* pretend both ui */
+        uiop1 = seed_value_to_ulong(ctx, args[0], exception);
+        uiop2 = seed_value_to_ulong(ctx, args[1], exception);
+        ret = mpfr_ui_pow_ui(rop, uiop1, uiop2, rnd);
+    }
+    else
+    {
+        TYPE_EXCEPTION("mpfr.pow", "int or unsigned int and 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 dd9eba9..02adc97 100644
--- a/modules/mpfr/seed-mpfr.c
+++ b/modules/mpfr/seed-mpfr.c
@@ -992,6 +992,7 @@ seed_static_function mpfr_funcs[] =
     {"div", seed_mpfr_div, 0},
     {"sqrt", seed_mpfr_sqrt, 0},
     {"sqr", seed_mpfr_sqr, 0},
+    {"pow", seed_mpfr_pow, 0},
     {"root", seed_mpfr_root, 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 2ea3c4b..b66a3ef 100644
--- a/modules/mpfr/seed-mpfr.h
+++ b/modules/mpfr/seed-mpfr.h
@@ -121,6 +121,7 @@ DEF_SEED_MPFR_FUNC(seed_mpfr_atanh);
 
 DEF_SEED_MPFR_FUNC(seed_mpfr_sqrt);
 DEF_SEED_MPFR_FUNC(seed_mpfr_sqr);
+DEF_SEED_MPFR_FUNC(seed_mpfr_pow);
 DEF_SEED_MPFR_FUNC(seed_mpfr_root);
 DEF_SEED_MPFR_FUNC(seed_mpfr_rec_sqrt);
 DEF_SEED_MPFR_FUNC(seed_mpfr_cbrt);



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