# HG changeset patch # User Jaroslav Hajek # Date 1235717480 -3600 # Node ID 8633ae24a89231f5d379a9e44fd9df74eab1bef2 # Parent 8ed42c679af5ddc224865fd6b2cee03111b5e204 gripe when dividing a diagonal matrix by zero diff -r 8ed42c679af5 -r 8633ae24a892 src/ChangeLog --- a/src/ChangeLog Thu Feb 26 13:58:47 2009 -0500 +++ b/src/ChangeLog Fri Feb 27 07:51:20 2009 +0100 @@ -1,3 +1,9 @@ +2009-02-27 Jaroslav Hajek + + * OPERATORS/op-dms-template.cc (gripe_if_zero): New template static + function. + (dmsdiv, sdmldiv): Call it. + 2009-02-26 John W. Eaton * symtab.h (symbol_table::symbol_record::symbol_record_rep::forced): diff -r 8ed42c679af5 -r 8633ae24a892 src/OPERATORS/op-dms-template.cc --- a/src/OPERATORS/op-dms-template.cc Thu Feb 26 13:58:47 2009 -0500 +++ b/src/OPERATORS/op-dms-template.cc Fri Feb 27 07:51:20 2009 +0100 @@ -25,6 +25,7 @@ #endif #include "ops.h" +#include "gripes.h" #include "xpow.h" #include SINCLUDE #include MINCLUDE @@ -45,18 +46,33 @@ DEFNDBINOP_OP (dmsadd, MATRIX, SCALAR, MATRIXV, SCALARV, +) DEFNDBINOP_OP (dmssub, MATRIX, SCALAR, MATRIXV, SCALARV, -) DEFNDBINOP_OP (dmsmul, MATRIX, SCALAR, MATRIXV, SCALARV, *) -DEFNDBINOP_OP (dmsdiv, MATRIX, SCALAR, MATRIXV, SCALARV, /) #define OCTAVE_MATRIX CONCAT2(octave_, MATRIX) #define OCTAVE_SCALAR CONCAT2(octave_, SCALAR) #define MATRIX_VALUE CONCAT2(MATRIXV, _value) #define SCALAR_VALUE CONCAT2(SCALARV, _value) +template +static T +gripe_if_zero (T x) +{ + if (x == T ()) + gripe_divide_by_zero (); + return x; +} + +DEFBINOP (dmsdiv, MATRIX, SCALAR) +{ + CAST_BINOP_ARGS (const OCTAVE_MATRIX&, const OCTAVE_SCALAR&); + + return v1.MATRIX_VALUE () / gripe_if_zero (v2.SCALAR_VALUE ()); +} + DEFBINOP (sdmldiv, SCALAR, MATRIX) { CAST_BINOP_ARGS (const OCTAVE_SCALAR&, const OCTAVE_MATRIX&); - return v2.MATRIX_VALUE () / v1.SCALAR_VALUE (); + return v2.MATRIX_VALUE () / gripe_if_zero (v1.SCALAR_VALUE ()); } DEFBINOP (dmspow, MATRIX, SCALAR)