[Pkg-octave-commit] [SCM] octave-symbolic branch, master, updated. a718b53403d9f164f8c2a3df521385a01d28a11b
bensapp
bensapp at 416fae20-06d0-4450-9b69-c6c34d4b5f03
Mon Jan 3 03:40:10 UTC 2011
The following commit has been merged in the master branch:
commit 3ee223681982879a1ac51fd70501ae93b466246f
Author: bensapp <bensapp at 416fae20-06d0-4450-9b69-c6c34d4b5f03>
Date: Tue Jan 15 22:14:29 2002 +0000
Added some exception handling.
git-svn-id: https://octave.svn.sourceforge.net/svnroot/octave/trunk/octave-forge/main/symbolic@121 416fae20-06d0-4450-9b69-c6c34d4b5f03
diff --git a/ov-ex.cc b/ov-ex.cc
index daa0675..bae6176 100644
--- a/ov-ex.cc
+++ b/ov-ex.cc
@@ -56,8 +56,16 @@ class octave_sym;
#define DEFUNOP_OP(name, t, op) \
UNOPDECL (name, a) \
{ \
- CAST_UNOP_ARG (const octave_ ## t&); \
- return octave_value (new octave_ex (op v.t ## _value ())); \
+ try \
+ { \
+ CAST_UNOP_ARG (const octave_ ## t&); \
+ return octave_value (new octave_ex (op v.t ## _value ())); \
+ } \
+ catch (exception &e) \
+ { \
+ error(e.what()); \
+ return octave_value (); \
+ } \
}
DEFUNOP_OP (uminus, ex, -)
@@ -72,9 +80,17 @@ DEFNCUNOP_METHOD (decr, ex, decrement)
#define DEFBINOP_OP(name, t1, t2, op) \
BINOPDECL (name, a1, a2) \
{ \
- CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
- return octave_value \
- (new octave_ex (v1.t1 ## _value () op v2.t2 ## _value ())); \
+ try \
+ { \
+ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
+ return octave_value \
+ (new octave_ex (v1.t1 ## _value () op v2.t2 ## _value ())); \
+ } \
+ catch (exception &e) \
+ { \
+ error(e.what()); \
+ return octave_value (); \
+ } \
}
#ifdef DEFBINOP_POW
@@ -84,9 +100,17 @@ DEFNCUNOP_METHOD (decr, ex, decrement)
#define DEFBINOP_POW(name, t1, t2) \
BINOPDECL(name, a1, a2) \
{ \
- CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
- return octave_value \
- (new octave_ex (pow(v1.t1 ## _value (), v2.t2 ## _value ()))); \
+ try \
+ { \
+ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
+ return octave_value \
+ (new octave_ex (pow(v1.t1 ## _value (), v2.t2 ## _value ()))); \
+ } \
+ catch (exception &e) \
+ { \
+ error(e.what()); \
+ return octave_value (); \
+ } \
}
// Addition operations
diff --git a/ov-sym.cc b/ov-sym.cc
index 2ec1d9a..a814ad4 100644
--- a/ov-sym.cc
+++ b/ov-sym.cc
@@ -52,8 +52,16 @@ class ostream;
#define DEFUNOP_OP(name, t, op) \
UNOPDECL (name, a) \
{ \
- CAST_UNOP_ARG (const octave_ ## t&); \
- return octave_value (new octave_ex (op v.t ## _value ())); \
+ try \
+ { \
+ CAST_UNOP_ARG (const octave_ ## t&); \
+ return octave_value (new octave_ex (op v.t ## _value ())); \
+ } \
+ catch (exception &e) \
+ { \
+ error(e.what()); \
+ return octave_value (); \
+ } \
}
DEFUNOP_OP (uminus, sym, -)
@@ -66,9 +74,17 @@ DEFUNOP_OP (uminus, sym, -)
#define DEFBINOP_OP(name, t1, t2, op) \
BINOPDECL (name, a1, a2) \
{ \
- CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
- return octave_value \
- (new octave_ex (v1.t1 ## _value () op v2.t2 ## _value ())); \
+ try \
+ { \
+ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
+ return octave_value \
+ (new octave_ex (v1.t1 ## _value () op v2.t2 ## _value ())); \
+ } \
+ catch (exception &e) \
+ { \
+ error(e.what()); \
+ return octave_value (); \
+ } \
}
#ifdef DEFBINOP_POW
@@ -78,9 +94,17 @@ DEFUNOP_OP (uminus, sym, -)
#define DEFBINOP_POW(name, t1, t2) \
BINOPDECL(name, a1, a2) \
{ \
- CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
- return octave_value \
- (new octave_ex (pow(v1.t1 ## _value (), v2.t2 ## _value ()))); \
+ try \
+ { \
+ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
+ return octave_value \
+ (new octave_ex (pow(v1.t1 ## _value (), v2.t2 ## _value ()))); \
+ } \
+ catch (exception &e) \
+ { \
+ error(e.what()); \
+ return octave_value (); \
+ } \
}
// Addition operations
@@ -126,9 +150,9 @@ GiNaC::symbol octave_sym::sym_value() const
void
install_sym_type()
-{
+{
octave_sym::register_type();
-
+
cerr << "installing sym type at type-id = "
<< octave_sym::static_type_id() << "\n";
}
diff --git a/ov-vpa.cc b/ov-vpa.cc
index a785408..ea046eb 100644
--- a/ov-vpa.cc
+++ b/ov-vpa.cc
@@ -61,9 +61,19 @@ octave_vpa::print (ostream& os, bool pr_as_read_syntax) const
#define DEFUNOP_OP(name, t, op) \
UNOPDECL (name, a) \
{ \
- CAST_UNOP_ARG (const octave_ ## t&); \
- return octave_value (new octave_vpa (op v.t ## _value ())); \
- }
+ try \
+ { \
+ CAST_UNOP_ARG (const octave_ ## t&); \
+ return octave_value (new octave_vpa (op v.t ## _value ())); \
+ } \
+ catch(exception &e) \
+ { \
+ error(e.what()); \
+ return octave_value (); \
+ } \
+ }
+
+
// DEFUNOP_OP (not, vpa, !)
DEFUNOP_OP (uminus, vpa, -)
@@ -80,25 +90,49 @@ DEFNCUNOP_METHOD (decr, vpa, decrement)
#define DEFBINOP_OP(name, t1, t2, op) \
BINOPDECL (name, a1, a2) \
{ \
- CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
- return octave_value \
- (new octave_vpa (v1.t1 ## _value () op v2.t2 ## _value ())); \
+ try \
+ { \
+ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
+ return octave_value \
+ (new octave_vpa (v1.t1 ## _value () op v2.t2 ## _value ())); \
+ } \
+ catch(exception &e) \
+ { \
+ error(e.what()); \
+ return octave_value (); \
+ } \
}
#define DEFBINOP_OP_NUM(name, t1, t2, op) \
BINOPDECL (name, a1, a2) \
{ \
- CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
- return octave_value \
- (new octave_vpa (v1.t1 ## _value () op v2.t2 ## _value ())); \
+ try \
+ { \
+ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
+ return octave_value \
+ (new octave_vpa (v1.t1 ## _value () op v2.t2 ## _value ())); \
+ } \
+ catch (exception &e) \
+ { \
+ error(e.what()); \
+ return octave_value (); \
+ } \
}
#define DEFBINOP_OP_EX(name, t1, t2, op) \
BINOPDECL (name, a1, a2) \
{ \
- CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
- return octave_value \
- (new octave_ex (v1.t1 ## _value () op v2.t2 ## _value ())); \
+ try \
+ { \
+ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
+ return octave_value \
+ (new octave_ex (v1.t1 ## _value () op v2.t2 ## _value ())); \
+ } \
+ catch (exception &e) \
+ { \
+ error(e.what()); \
+ return octave_value (); \
+ } \
}
@@ -109,9 +143,18 @@ DEFNCUNOP_METHOD (decr, vpa, decrement)
#define DEFBINOP_POW(name, t1, t2) \
BINOPDECL(name, a1, a2) \
{ \
- CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
- return octave_value \
- (new octave_ex (pow(v1.t1 ## _value (), v2.t2 ## _value ()))); \
+ try \
+ { \
+ CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
+ return octave_value \
+ (new octave_ex (pow(v1.t1 ## _value (), v2.t2 ## _value ()))); \
+ } \
+ catch (exception &e) \
+ { \
+ octave_value_list empty; \
+ error(e.what()); \
+ return empty; \
+ } \
}
// relational ops.
diff --git a/symbols.cc b/symbols.cc
index 44fad0d..06c7d12 100644
--- a/symbols.cc
+++ b/symbols.cc
@@ -42,7 +42,7 @@ class octave_sym;
bool get_expression(const octave_value arg, GiNaC::ex& expression)
{
const octave_value& rep = (arg).get_rep();
-
+
if (arg.type_id () == octave_vpa::static_type_id ())
{
GiNaC::numeric x = ((octave_vpa& ) rep).vpa_value();
@@ -141,22 +141,30 @@ is a number.\n\
GiNaC::numeric d;
int nargin = args.length();
- if (nargin == 1)
+ try
{
- if (!get_numeric (args(0), d))
+ if (nargin == 1)
+ {
+ if (!get_numeric (args(0), d))
+ {
+ gripe_wrong_type_arg ("vpa", args(0));
+ return retval;
+ }
+ }
+ else
{
- gripe_wrong_type_arg ("vpa", args(0));
+ print_usage("vpa");
return retval;
- }
- }
- else
- {
- print_usage("vpa");
- return retval;
- }
-
- retval = octave_value(new octave_vpa(d));
+ }
+ retval = octave_value(new octave_vpa(d));
+ }
+ catch (exception &e)
+ {
+ error(e.what());
+ retval = octave_value ();
+ }
+
return retval;
}
@@ -179,13 +187,21 @@ Convert a vpa, string, ex or string type to a double.\n\
return retval;
}
- if (!get_numeric (args(0), num))
+ try
{
- print_usage("to_double");
- return retval;
+ if (!get_numeric (args(0), num))
+ {
+ print_usage("to_double");
+ return retval;
+ }
+
+ retval = octave_value(num.to_double ());
}
-
- retval = octave_value(num.to_double ());
+ catch (exception &e)
+ {
+ error(e.what());
+ retval = octave_value ();
+ }
return retval;
}
@@ -205,21 +221,31 @@ Change the precision for the vpa type
error("you must supply 0 or 1 arguments\n");
return(retval);
}
-
- if(nargin == 1)
- {
- if(args(0).is_real_scalar())
- {
- GiNaC::Digits = int(args(0).double_value());
- }
- else
+
+ try
+ {
+ if(nargin == 1)
{
- print_usage("digits");
+ if(args(0).is_real_scalar())
+ {
+ GiNaC::Digits = int(args(0).double_value());
+ }
+ else
+ {
+ print_usage("digits");
+ }
}
+
+ double dig = double(GiNaC::Digits);
+ retval = octave_value(dig);
+
}
+ catch (exception &e)
+ {
+ error(e.what());
+ retval = octave_value ();
+ }
- double dig = double(GiNaC::Digits);
- retval = octave_value(dig);
return(retval);
}
@@ -229,7 +255,18 @@ Pi evaluated to the current value of Digits\n\
\n\
@seealso{digits}")
{
- return octave_value(new octave_vpa(GiNaC::ex_to<GiNaC::numeric>(GiNaC::Pi.evalf())));
+ octave_value retval;
+ try
+ {
+ retval = octave_value(new octave_vpa(GiNaC::ex_to<GiNaC::numeric>(GiNaC::Pi.evalf())));
+ }
+ catch(exception &e)
+ {
+ error(e.what());
+ retval = octave_value ();
+ }
+
+ return retval;
}
DEFUN_DLD(is_vpa, args, ,
@@ -244,6 +281,7 @@ DEFUN_DLD (sym,args, ,
"-*- texinfo -*-\n\
Create an object of type symbol\n")
{
+ octave_value retval;
int nargin = args.length ();
if (nargin != 1)
@@ -251,10 +289,19 @@ Create an object of type symbol\n")
error("one argument expected\n");
return octave_value ();
}
+ try
+ {
+ GiNaC::symbol xtmp(args(0).string_value());
+ octave_sym x(xtmp);
+ retval = octave_value(new octave_sym(x));
+ }
+ catch (exception &e)
+ {
+ error(e.what());
+ retval = octave_value ();
+ }
- GiNaC::symbol xtmp(args(0).string_value());
- octave_sym x(xtmp);
- return octave_value(new octave_sym(x));
+ return retval;
}
DEFUN_DLD(is_sym,args, ,"Return true if an object is of type sym false otherwise.\n")
@@ -284,37 +331,46 @@ supplied then a default value of 1 is used.\n\
print_usage ("differentiate");
return retval;
}
-
- if (!get_expression (args(0), expression))
- {
- print_usage ("differentiate");
- return retval;
- }
-
- if (!get_symbol (args(1), variable))
- {
- print_usage ("differentiate");
- return retval;
- }
-
- if (nargin == 3)
- {
- if (!get_numeric (args(2), num))
+ try
+ {
+ if (!get_expression (args(0), expression))
{
print_usage ("differentiate");
return retval;
}
- order = int(num.to_double ());
- if (order < 0)
+
+ if (!get_symbol (args(1), variable))
{
- error("must supply an integer greater than zero\n");
+ print_usage ("differentiate");
return retval;
}
+
+ if (nargin == 3)
+ {
+ if (!get_numeric (args(2), num))
+ {
+ print_usage ("differentiate");
+ return retval;
+ }
+ order = int(num.to_double ());
+ if (order < 0)
+ {
+ error("must supply an integer greater than zero\n");
+ return retval;
+ }
+ }
+ else
+ order = 1;
+
+ retval = octave_value(new octave_ex(expression.diff(variable,order)));
+ }
+ catch(exception &e)
+ {
+ error(e.what ());
+ retval = octave_value ();
}
- else
- order = 1;
- return octave_value(new octave_ex(expression.diff(variable,order)));
+ return retval;
}
DEFINE_EX_GINAC_FUNCTION(Cos,cos,"cosine");
@@ -410,7 +466,7 @@ Substitute a number for a variables in an expression\n\
catch (exception e)
{
e.what ();
- return octave_value ();
+ retval = octave_value ();
}
return retval;
@@ -439,20 +495,33 @@ Expand an expression\n\
print_usage("expand");
return retval;
}
- if(args(0).type_id() == octave_ex::static_type_id())
+
+ try
{
- const octave_value& rep1 = args(0).get_rep();
- expression = ((const octave_ex& ) rep1).ex_value();
+
+ if(args(0).type_id() == octave_ex::static_type_id())
+ {
+ const octave_value& rep1 = args(0).get_rep();
+ expression = ((const octave_ex& ) rep1).ex_value();
+ }
+ else
+ {
+ gripe_wrong_type_arg("expand",args(0));
+ }
+
+ result = expression.expand();
+ retval = octave_value(new octave_ex(result));
}
- else
+ catch (exception &e)
{
- gripe_wrong_type_arg("expand",args(0));
+ error(e.what ());
+ retval = octave_value ();
}
-
- result = expression.expand();
- return octave_value(new octave_ex(result));
+
+ return retval;
}
+
DEFUN_DLD(coeff,args,,
"-*- texinfo -*-
@deftypefn {Loadable Function} {b =} coeff(@var{a}, at var{x}, at var{n})\n\
@@ -473,44 +542,111 @@ Obtain the @var{n}th coefficient of the variable @var{x} in @var{a}.
return retval;
}
- if(args(0).type_id() == octave_ex::static_type_id())
+ try
{
- const octave_value& rep0 = args(0).get_rep();
- expression = ((const octave_ex& ) rep0).ex_value();
+ if(args(0).type_id() == octave_ex::static_type_id())
+ {
+ const octave_value& rep0 = args(0).get_rep();
+ expression = ((const octave_ex& ) rep0).ex_value();
+ }
+ else
+ {
+ gripe_wrong_type_arg("coeff",args(0));
+ return retval;
+ }
+
+ if(args(1).type_id() == octave_sym::static_type_id())
+ {
+ const octave_value& rep1 = args(1).get_rep();
+ sym = ((const octave_sym& ) rep1).sym_value();
+ }
+ else
+ {
+ gripe_wrong_type_arg("coeff",args(1));
+ return retval;
+ }
+
+ if(args(2).is_real_scalar())
+ {
+ n = (int )args(2).double_value();
+ }
+ else
+ {
+ gripe_wrong_type_arg("coeff",args(2));
+ return retval;
+ }
+
+ retval = octave_value (new octave_ex (expression.coeff(sym,n)));
}
- else
+ catch(exception &e)
{
- gripe_wrong_type_arg("coeff",args(0));
- return retval;
- }
+ error(e.what ());
+ retval = octave_value ();
+ }
- if(args(1).type_id() == octave_sym::static_type_id())
- {
- const octave_value& rep1 = args(1).get_rep();
- sym = ((const octave_sym& ) rep1).sym_value();
- }
- else
+ return retval;
+}
+
+DEFUN_DLD(collect,args,,
+"-*- texinfo -*-\n\
+ at deftypefn Loadable Function {b =} collect(@var{a}, at var{x})\n\
+\n\
+collect the terms in @var{a} as a univariate polynomial in @var{x}\n\
+ at table @var\n\
+ at item a\n\
+ The expresion in which the collection will occur.\n\
+ at item x\n\
+ The variable that will be collected.\n\
+ at end table\n\
+\n\
+ at end deftypefn\n\
+")
+{
+ octave_value retval;
+ GiNaC::ex expression;
+ GiNaC::symbol the_sym;
+
+ if(args.length() != 2)
{
- gripe_wrong_type_arg("coeff",args(1));
+ print_usage("collect");
return retval;
}
- if(args(2).is_real_scalar())
+ try
{
- n = (int )args(2).double_value();
+ if(args(0).type_id() == octave_ex::static_type_id())
+ {
+ const octave_value& rep1 = args(0).get_rep();
+ expression = ((const octave_ex& ) rep1).ex_value();
+ }
+ else
+ {
+ gripe_wrong_type_arg("collect",args(0));
+ }
+
+ if(args(1).type_id() == octave_sym::static_type_id())
+ {
+ const octave_value& rep2 = args(1).get_rep();
+ the_sym = ((octave_sym& ) rep2).sym_value();
+ }
+ else
+ {
+ gripe_wrong_type_arg("collect",args(1));
+ }
+
+ retval = new octave_ex(expression.collect(the_sym));
+
}
- else
+ catch(exception &e)
{
- gripe_wrong_type_arg("coeff",args(2));
- return retval;
+ error(e.what());
+ retval = octave_value ();
}
- retval = octave_value (new octave_ex (expression.coeff(sym,n)));
-
return retval;
}
-DEFUN_DLD(collect,args,,
+DEFUN_DLD(Gcd,args,,
"-*- texinfo -*-\n\
@deftypefn Loadable Function {b =} collect(@var{a}, at var{x})\n\
\n\
@@ -559,5 +695,3 @@ collect the terms in @var{a} as a univariate polynomial in @var{x}\n\
return retval;
}
-
-
diff --git a/symbols.h b/symbols.h
index e040e51..ee996bd 100644
--- a/symbols.h
+++ b/symbols.h
@@ -1,4 +1,3 @@
-
bool get_expression(const octave_value arg, GiNaC::ex& expression);
bool get_symbol(const octave_value arg, GiNaC::symbol& sym);
bool get_numeric(const octave_value arg, GiNaC::numeric& number);
@@ -31,15 +30,15 @@ Return the " description " of a symbolic expression.\n\
} \
\
r = new octave_ex(GiNaC::ginac_name (expression)); \
- \
+ retval = octave_value (r); \
} \
- catch (exception e) \
+ catch (exception &e) \
{ \
e.what (); \
- return octave_value (); \
+ retval = octave_value (); \
} \
\
- return octave_value(r); \
+ return retval; \
}
#define DEFINE_EX_SYM_GINAC_FUNCTION(oct_name,ginac_name,description) \
@@ -62,20 +61,30 @@ Return the " description " of a symbolic expression.\n\
return retval; \
} \
\
- if(!get_expression(args(0), expression)) \
+ try \
{ \
- print_usage(# oct_name); \
- return retval; \
- } \
+ if(!get_expression(args(0), expression)) \
+ { \
+ print_usage(# oct_name); \
+ return retval; \
+ } \
\
- if (!get_symbol(args(1), sym)) \
+ if (!get_symbol(args(1), sym)) \
+ { \
+ print_usage(# oct_name); \
+ return retval; \
+ } \
+ \
+ r = new octave_ex(expression.ginac_name(sym)); \
+ \
+ } \
+ catch(exception &e) \
{ \
- print_usage(# oct_name); \
- return retval; \
+ octave_value_list empty; \
+ error(e.what()); \
+ return empty; \
} \
\
- r = new octave_ex(expression.ginac_name(sym)); \
- \
return octave_value(r); \
}
@@ -100,28 +109,38 @@ Return the " description " of a symbolic expression.\n\
return retval; \
} \
\
- if(!get_expression(args(0), expression0)) \
+ try \
{ \
- gripe_wrong_type_arg(# oct_name, args(0)); \
- print_usage(# oct_name); \
- return retval; \
- } \
+ if(!get_expression(args(0), expression0)) \
+ { \
+ gripe_wrong_type_arg(# oct_name, args(0)); \
+ print_usage(# oct_name); \
+ return retval; \
+ } \
\
- if(!get_expression(args(1), expression1)) \
- { \
- gripe_wrong_type_arg(# oct_name, args(1)); \
- print_usage(# oct_name); \
- return retval; \
- } \
+ if(!get_expression(args(1), expression1)) \
+ { \
+ gripe_wrong_type_arg(# oct_name, args(1)); \
+ print_usage(# oct_name); \
+ return retval; \
+ } \
\
- if (!get_symbol(args(2), sym)) \
- { \
- gripe_wrong_type_arg(# oct_name, args(2)); \
- print_usage(# oct_name); \
- return retval; \
- } \
+ if (!get_symbol(args(2), sym)) \
+ { \
+ gripe_wrong_type_arg(# oct_name, args(2)); \
+ print_usage(# oct_name); \
+ return retval; \
+ } \
\
- r = new octave_ex(ginac_name (expression0, expression1, sym)); \
+ r = new octave_ex(ginac_name (expression0, expression1, sym)); \
+ \
+ } \
+ catch(exception &e) \
+ { \
+ octave_value_list empty; \
+ error(e.what()); \
+ return empty; \
+ }\
\
return octave_value(r); \
}
--
octave-symbolic
More information about the Pkg-octave-commit
mailing list