[seed] [mpfr] Redid mpfr with set constructor to be better. Don't use the init with set functions as they a
- From: Tim Horton <hortont src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] [mpfr] Redid mpfr with set constructor to be better. Don't use the init with set functions as they a
- Date: Sat, 4 Jul 2009 06:20:23 +0000 (UTC)
commit b55b77184e5aa920e782d39e0aa24018c948ee76
Author: Matt ARSENAULT <arsenm2 rpi edu>
Date: Sat Jul 4 00:38:30 2009 -0400
[mpfr] Redid mpfr with set constructor to be better. Don't use the init with set functions as they always use default precision
modules/mpfr/mpfr.c | 90 ++++++++++++++++++++++++++------------------------
1 files changed, 47 insertions(+), 43 deletions(-)
---
diff --git a/modules/mpfr/mpfr.c b/modules/mpfr/mpfr.c
index fa9ba0a..f284640 100644
--- a/modules/mpfr/mpfr.c
+++ b/modules/mpfr/mpfr.c
@@ -259,33 +259,36 @@ seed_mpfr_construct_with_set(SeedContext ctx,
gdouble dbl;
gchar* str;
SeedObject obj;
+ seed_mpfr_t argt;
/* TODO: Precision range check */
- if ( arg_count == 2 )
- prec = mpfr_get_default_prec();
- else if ( arg_count == 3 )
- {
- if ( seed_value_is_number(ctx, args[1]) )
- prec = seed_value_to_int(ctx, args[1], exception);
- else
- {
- seed_make_exception (ctx, exception, "TypeError",
- "mpfr constructor with set expected number as precision");
- return seed_make_null(ctx);
- }
- }
- else
+ switch ( arg_count )
{
- seed_make_exception (ctx, exception, "ArgumentError",
- "mpfr constructor with init expected 2 or 3 arguments, got %zd",
- arg_count);
- return seed_make_null (ctx);
+ case 2:
+ prec = mpfr_get_default_prec();
+ break;
+ case 3:
+ if ( seed_value_is_number(ctx, args[1]) )
+ {
+ prec = seed_value_to_mpfr_prec_t(ctx, args[1], exception);
+ }
+ else
+ {
+ seed_make_exception (ctx, exception, "TypeError",
+ "mpfr constructor with set expected number as precision");
+ return seed_make_null(ctx);
+ }
+ break;
+ default:
+ seed_make_exception (ctx, exception, "ArgumentError",
+ "mpfr constructor with init expected 2 or 3 arguments, got %zd",
+ arg_count);
+ return seed_make_null (ctx);
}
/* last argument is always rnd */
- /* TODO: Right size for mpfr_rnd_t */
if ( seed_value_is_number(ctx, args[arg_count - 1]) )
- rnd = seed_value_to_int(ctx, args[arg_count - 1], exception);
+ rnd = seed_value_to_mpfr_rnd_t(ctx, args[arg_count - 1], exception);
else
{
seed_make_exception (ctx, exception, "TypeError",
@@ -294,31 +297,32 @@ seed_mpfr_construct_with_set(SeedContext ctx,
}
newmp = (mpfr_ptr) g_malloc(sizeof(mpfr_t));
+ mpfr_init2(newmp, prec);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
- obj = seed_value_to_object(ctx, args[0], exception);
- op = seed_object_get_private(obj);
- mpfr_init_set(newmp, op, rnd);
- }
- else if ( seed_value_is_number(ctx, args[0]) )
- {
- dbl = seed_value_to_double(ctx, args[0], exception);
- mpfr_init_set_d(newmp, dbl, rnd);
- }
- else if ( seed_value_is_string(ctx, args[0]) )
- {
- /* TODO: Assuming base 10 is bad */
- str = seed_value_to_string(ctx, args[0], exception);
- mpfr_init_set_str(newmp, str, 10, rnd);
- }
- else
+ argt = seed_mpfr_arg_type(ctx, args[0], exception);
+
+ switch ( argt )
{
- seed_make_exception (ctx, exception, "TypeError",
- "mpfr constructor with set expected initializer as mpfr, number, or string");
- mpfr_clear( newmp );
- g_free( newmp );
- return seed_make_null(ctx);
+ case SEED_MPFR_MPFR:
+ obj = seed_value_to_object(ctx, args[0], exception);
+ op = seed_object_get_private(obj);
+ mpfr_set(newmp, op, rnd);
+ break;
+ case SEED_MPFR_DOUBLE:
+ dbl = seed_value_to_double(ctx, args[0], exception);
+ mpfr_set_d(newmp, dbl, rnd);
+ break;
+ case SEED_MPFR_STRING:
+ /* TODO: Assuming base 10 is bad */
+ str = seed_value_to_string(ctx, args[0], exception);
+ mpfr_set_str(newmp, str, 10, rnd);
+ break;
+ default:
+ seed_make_exception (ctx, exception, "TypeError",
+ "mpfr constructor with set expected initializer as mpfr, number, or string");
+ mpfr_clear( newmp );
+ g_free( newmp );
+ return seed_make_null(ctx);
}
return seed_make_object(ctx, mpfr_class, newmp);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]