[seed] Added rounding functions



commit 986c52b0841740882b3310088c8203ba38a54a9f
Author: Matt ARSENAULT <arsenm2 rpi edu>
Date:   Sun Jul 5 18:08:40 2009 -0400

    Added rounding functions

 modules/mpfr/seed-mpfr-arithmetic.c |  145 +++++++++++++++++++++++++++++++++++
 modules/mpfr/seed-mpfr.c            |    5 +
 modules/mpfr/seed-mpfr.h            |    6 ++
 3 files changed, 156 insertions(+), 0 deletions(-)
---
diff --git a/modules/mpfr/seed-mpfr-arithmetic.c b/modules/mpfr/seed-mpfr-arithmetic.c
index 4e747c3..9486d15 100644
--- a/modules/mpfr/seed-mpfr-arithmetic.c
+++ b/modules/mpfr/seed-mpfr-arithmetic.c
@@ -246,3 +246,148 @@ SeedValue seed_mpfr_dim (SeedContext ctx,
     return seed_value_from_int(ctx, ret, exception);
 }
 
+
+/* Rounding functions */
+
+SeedValue seed_mpfr_rint (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.rint", 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.rint", "mpfr_t");
+    }
+
+    ret = mpfr_rint(rop, op, rnd);
+
+    return seed_value_from_int(ctx, ret, exception);
+}
+
+SeedValue seed_mpfr_ceil (SeedContext ctx,
+                          SeedObject function,
+                          SeedObject this_object,
+                          gsize argument_count,
+                          const SeedValue args[],
+                          SeedException * exception)
+{
+    mpfr_ptr rop, op;
+    gint ret;
+
+    CHECK_ARG_COUNT("mpfr.ceil", 1);
+
+    rop = seed_object_get_private(this_object);
+
+    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
+    {
+        op = seed_object_get_private(args[0]);
+    }
+    else
+    {
+        TYPE_EXCEPTION("mpfr.ceil", "mpfr_t");
+    }
+
+    ret = mpfr_ceil(rop, op);
+
+    return seed_value_from_int(ctx, ret, exception);
+}
+
+SeedValue seed_mpfr_floor (SeedContext ctx,
+                           SeedObject function,
+                           SeedObject this_object,
+                           gsize argument_count,
+                           const SeedValue args[],
+                           SeedException * exception)
+{
+    mpfr_ptr rop, op;
+    gint ret;
+
+    CHECK_ARG_COUNT("mpfr.floor", 1);
+
+    rop = seed_object_get_private(this_object);
+
+    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
+    {
+        op = seed_object_get_private(args[0]);
+    }
+    else
+    {
+        TYPE_EXCEPTION("mpfr.floor", "mpfr_t");
+    }
+
+    ret = mpfr_floor(rop, op);
+
+    return seed_value_from_int(ctx, ret, exception);
+}
+
+SeedValue seed_mpfr_round (SeedContext ctx,
+                           SeedObject function,
+                           SeedObject this_object,
+                           gsize argument_count,
+                           const SeedValue args[],
+                           SeedException * exception)
+{
+    mpfr_ptr rop, op;
+    gint ret;
+
+    CHECK_ARG_COUNT("mpfr.round", 1);
+
+    rop = seed_object_get_private(this_object);
+
+    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
+    {
+        op = seed_object_get_private(args[0]);
+    }
+    else
+    {
+        TYPE_EXCEPTION("mpfr.round", "mpfr_t");
+    }
+
+    ret = mpfr_round(rop, op);
+
+    return seed_value_from_int(ctx, ret, exception);
+}
+
+SeedValue seed_mpfr_trunc (SeedContext ctx,
+                           SeedObject function,
+                           SeedObject this_object,
+                           gsize argument_count,
+                           const SeedValue args[],
+                           SeedException * exception)
+{
+    mpfr_ptr rop, op;
+    gint ret;
+
+    CHECK_ARG_COUNT("mpfr.trunc", 1);
+
+    rop = seed_object_get_private(this_object);
+
+    if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
+    {
+        op = seed_object_get_private(args[0]);
+    }
+    else
+    {
+        TYPE_EXCEPTION("mpfr.trunc", "mpfr_t");
+    }
+
+    ret = mpfr_trunc(rop, op);
+
+    return seed_value_from_int(ctx, ret, exception);
+}
+
diff --git a/modules/mpfr/seed-mpfr.c b/modules/mpfr/seed-mpfr.c
index 2166564..194ecd0 100644
--- a/modules/mpfr/seed-mpfr.c
+++ b/modules/mpfr/seed-mpfr.c
@@ -631,6 +631,11 @@ seed_static_function mpfr_funcs[] =
     {"cbrt", seed_mpfr_cbrt, 0},
     {"neg", seed_mpfr_neg, 0},
     {"abs", seed_mpfr_abs, 0},
+    {"rint", seed_mpfr_rint, 0},
+    {"ceil", seed_mpfr_ceil, 0},
+    {"floor", seed_mpfr_floor, 0},
+    {"round", seed_mpfr_round, 0},
+    {"trunc", seed_mpfr_trunc, 0},
     {"dim", seed_mpfr_dim, 0},
     {"sin", seed_mpfr_sin, 0},
     {"cos", seed_mpfr_cos, 0},
diff --git a/modules/mpfr/seed-mpfr.h b/modules/mpfr/seed-mpfr.h
index ea0316c..e96aa6d 100644
--- a/modules/mpfr/seed-mpfr.h
+++ b/modules/mpfr/seed-mpfr.h
@@ -58,6 +58,12 @@ DEF_SEED_MPFR_FUNC(seed_mpfr_neg);
 DEF_SEED_MPFR_FUNC(seed_mpfr_abs);
 DEF_SEED_MPFR_FUNC(seed_mpfr_dim);
 
+DEF_SEED_MPFR_FUNC(seed_mpfr_rint);
+DEF_SEED_MPFR_FUNC(seed_mpfr_ceil);
+DEF_SEED_MPFR_FUNC(seed_mpfr_floor);
+DEF_SEED_MPFR_FUNC(seed_mpfr_round);
+DEF_SEED_MPFR_FUNC(seed_mpfr_trunc);
+
 DEF_SEED_MPFR_FUNC(seed_mpfr_add);
 DEF_SEED_MPFR_FUNC(seed_mpfr_sin);
 DEF_SEED_MPFR_FUNC(seed_mpfr_cos);



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