[seed] [mpfr] Added test mpfr_add binding. Fixed backwards from/to seed type functions



commit d3a75783ac03281c8408cd1f9037a86127f1e891
Author: Matt ARSENAULT <arsenm2 rpi edu>
Date:   Thu Jul 2 17:08:10 2009 -0400

    [mpfr] Added test mpfr_add binding. Fixed backwards from/to seed type functions

 modules/mpfr/mpfr.c |   37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/modules/mpfr/mpfr.c b/modules/mpfr/mpfr.c
index 9aaa6e4..41a6857 100644
--- a/modules/mpfr/mpfr.c
+++ b/modules/mpfr/mpfr.c
@@ -26,11 +26,11 @@ seed_mpfr_init2 (SeedContext ctx,
     ptr = seed_pointer_get_pointer(ctx, args[0]);
 
     #if _MPFR_PREC_FORMAT == 1
-    prec = seed_value_from_ushort(ctx, args[1], exception);
+    prec = seed_value_to_ushort(ctx, args[1], exception);
     #elif _MPFR_PREC_FORMAT == 2
-    prec = seed_value_from_uint(ctx, args[1], exception);
+    prec = seed_value_to_uint(ctx, args[1], exception);
     #elif _MPFR_PREC_FORMAT == 3
-    prec = seed_value_from_ulong(ctx, args[1], exception);
+    prec = seed_value_to_ulong(ctx, args[1], exception);
     #else
     #error "Invalid MPFR Prec format"
     #endif
@@ -40,6 +40,34 @@ seed_mpfr_init2 (SeedContext ctx,
     return seed_make_null(ctx);
 }
 
+
+static SeedValue
+seed_mpfr_add (SeedContext ctx,
+               SeedObject function,
+               SeedObject this_object,
+               gsize arg_count,
+               const SeedValue args[],
+               SeedException * exception)
+{
+    mpfr_rnd_t rnd;
+    mpfr_ptr rop, op1, op2;
+
+    if ( arg_count != 4 )
+    {
+        seed_make_exception (ctx, exception, "ArgumentError",
+                             "mpfr.add expected 4 arguments, got %zd",
+                             arg_count);
+        return seed_make_null (ctx);
+    }
+
+    rop = seed_pointer_get_pointer(ctx, args[0]);
+    op1 = seed_pointer_get_pointer(ctx, args[1]);
+    op2 = seed_pointer_get_pointer(ctx, args[2]);
+    rnd = seed_value_to_char(ctx, args[3], exception);
+
+    return seed_value_from_int(ctx, mpfr_add(rop, op1, op2, rnd), exception);
+}
+
 SeedObject
 seed_module_init(SeedEngine *local_eng)
 {
@@ -50,6 +78,9 @@ seed_module_init(SeedEngine *local_eng)
     seed_create_function(ctx, "init2",
                          (SeedFunctionCallback) seed_mpfr_init2,
                          ns_ref);
+    seed_create_function(ctx, "add",
+                         (SeedFunctionCallback) seed_mpfr_add,
+                         ns_ref);
 
     return ns_ref;
 }



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