gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 2b9217b 1/2: Not-equal operator in Arithmetic


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 2b9217b 1/2: Not-equal operator in Arithmetic
Date: Tue, 6 Sep 2016 12:03:25 +0000 (UTC)

branch: master
commit 2b9217bbc323e362add759f382728fa5854bfb65
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Not-equal operator in Arithmetic
    
    The conditional operators of Arithmetic where not complete! The not-equal
    operator was missing. So it has been added now.
    
    The ordering of the operators in the book and within the
    `src/arithmetic/arithmetic.c' were also chaged so the lower/greater-equal
    operators are now immediately after the lower/greater-than operators and
    the equal and not-equal operators are also following each other.
    
    The explanation in Arithmetic's `args.h' also didn't have the conditional
    operators, so they were added.
---
 doc/gnuastro.texi           |   23 ++++++++++++++---------
 src/arithmetic/args.h       |    8 +++++---
 src/arithmetic/arithmetic.c |   26 ++++++++++++++++----------
 3 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 89b7703..b7794bb 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -6966,23 +6966,28 @@ is an image, then all the pixels will be compared with 
the the single value
 (number) of the other operand. Finally if both are numbers, then the output
 is also just one number (0 or 1).
 
address@hidden gt
-Greater than: similar to @code{lt} (`less than' operator), but
-returning 1 when the second popped operand is greater than the first.
-
address@hidden eq
-Equality: similar to @code{lt} (`less than' operator), but returning 1
-when the second popped operand is equal (to double precison floating point
-accuracy) to the first.
-
 @item le
 Less or equal: similar to @code{lt} (`less than' operator), but returning 1
 when the second popped operand is smaller or equal to the first.
 
address@hidden gt
+Greater than: similar to @code{lt} (`less than' operator), but
+returning 1 when the second popped operand is greater than the first.
+
 @item ge
 Greater or equal: similar to @code{lt} (`less than' operator), but
 returning 1 when the second popped operand is larger or equal to the first.
 
address@hidden eq
+Equality: similar to @code{lt} (`less than' operator), but returning 1 when
+the two popped operands are equal (to double precison floating point
+accuracy).
+
address@hidden neq
+Non-Equality: similar to @code{lt} (`less than' operator), but returning 1
+when the two popped operands are @emph{not} equal (to double precison
+floating point accuracy).
+
 @item where
 Change the pixel values `where' a certain condition holds. The conditional
 operators above can be used to define the condition. This operator requires
diff --git a/src/arithmetic/args.h b/src/arithmetic/args.h
index d352413..fcc8975 100644
--- a/src/arithmetic/args.h
+++ b/src/arithmetic/args.h
@@ -67,9 +67,11 @@ const char doc[] =
   "write `a.fits b.fits + 2 /' (or more simply a.fits b.fits average). "
   "Please see the manual for more information. "
   "\n\nThe operators/functions recognized by "SPACK_NAME" are: +, -, *, /, "
-  "abs, pow, sqrt, log, log10, minvalue, maxvalue, min, max, average and "
-  "median. Note that multiplication should be quoted like \"*\" to avoid "
-  "shell expansion.\n"
+  "abs, pow, sqrt, log, log10, minvalue, maxvalue, min, max, average, median, "
+  "lt, le, gt, ge, eq, neq. Please run `info gnuastro \"Arithmetic "
+  "operators\"' for detailed information on each operator. Note that "
+  "multiplication should be quoted (like \"*\", or '*') to avoid shell "
+  "expansion.\n"
   GAL_STRINGS_MORE_HELP_INFO
   /* After the list of options: */
   "\v"
diff --git a/src/arithmetic/arithmetic.c b/src/arithmetic/arithmetic.c
index dcb2166..a99f7db 100644
--- a/src/arithmetic/arithmetic.c
+++ b/src/arithmetic/arithmetic.c
@@ -748,20 +748,24 @@ lessthan(double left, double right)
 { return left<right; }
 
 int
+lessequal(double left, double right)
+{ return left<=right; }
+
+int
 greaterthan(double left, double right)
 { return left>right; }
 
 int
-equal(double left, double right)
-{ return left==right; }
+greaterequal(double left, double right)
+{ return left>=right; }
 
 int
-lessequal(double left, double right)
-{ return left<=right; }
+equal(double left, double right)
+{ return left==right; }
 
 int
-greaterequal(double left, double right)
-{ return left>=right; }
+notequal(double left, double right)
+{ return left!=right; }
 
 
 
@@ -786,10 +790,11 @@ conditionals(struct imgarithparams *p, char *operator)
   size=p->s0*p->s1;
 
   if(!strcmp(operator, "lt"))       thisfunction = &lessthan;
-  else if(!strcmp(operator, "gt"))  thisfunction = &greaterthan;
-  else if(!strcmp(operator, "eq"))  thisfunction = &equal;
   else if(!strcmp(operator, "le"))  thisfunction = &lessequal;
+  else if(!strcmp(operator, "gt"))  thisfunction = &greaterthan;
   else if(!strcmp(operator, "ge"))  thisfunction = &greaterequal;
+  else if(!strcmp(operator, "eq"))  thisfunction = &equal;
+  else if(!strcmp(operator, "neq")) thisfunction = &notequal;
   else
     error(EXIT_FAILURE, 0, "a bug! Please contact us at %s so we "
           "can address the problem. The value of `operator' in "
@@ -954,10 +959,11 @@ reversepolish(struct imgarithparams *p)
                   || !strcmp(token->v, "average")
                   || !strcmp(token->v, "median")) alloppixs(p, token->v);
           else if(!strcmp(token->v, "lt")
+                  || !strcmp(token->v, "le")
                   || !strcmp(token->v, "gt")
+                  || !strcmp(token->v, "ge")
                   || !strcmp(token->v, "eq")
-                  || !strcmp(token->v, "le")
-                  || !strcmp(token->v, "ge")) conditionals(p, token->v);
+                  || !strcmp(token->v, "neq")) conditionals(p, token->v);
           else if(!strcmp(token->v, "where")) where(p);
           else
             error(EXIT_FAILURE, 0, "the argument \"%s\" could not be "



reply via email to

[Prev in Thread] Current Thread [Next in Thread]