[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master fe81ab19: Library (arithmetic): more clear war
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master fe81ab19: Library (arithmetic): more clear warning on integer sanity check |
Date: |
Sat, 2 Apr 2022 11:11:22 -0400 (EDT) |
branch: master
commit fe81ab192c0654a71b3b57054c4464af66c2ff0e
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Library (arithmetic): more clear warning on integer sanity check
Until now, the warning message that is printed for binary operators (when
they are given integers of the same width as input), would simply say
"first/second popped operand". By "first" we mean the operand that is
closer to the operator. For example, in "2 3 gt", the first popped operand
is '3' and the second is '2'. But this could be confusing for some users
(who may confuse with the infix notation).
With this commit, some extra explanation is given in the warning message to
help clarify which one is "first" and which one is "second".
This was done with the help of Pedram Ashofte Ardakani.
---
lib/arithmetic.c | 34 ++++++++++++++++++----------------
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/lib/arithmetic.c b/lib/arithmetic.c
index 31b2aa1c..2285fe7d 100644
--- a/lib/arithmetic.c
+++ b/lib/arithmetic.c
@@ -1794,22 +1794,24 @@ arithmetic_binary_int_sanity_check(gal_data_t *l,
gal_data_t *r,
if( l_is_signed!=r_is_signed )
error(EXIT_SUCCESS, 0, "warning: the two integer operands "
"given to '%s' have the same width (number of bits), "
- "but a different sign: the first popped operand has "
- "type '%s' and the second has type '%s'. This may "
- "create wrong results, for example if the signed "
- "input contains negative values. To address this "
- "problem there are two options: 1) if you know that "
- "the signed input can only have positive values, use "
- "Arithmetic's type conversion operators to convert "
- "it to an un-signed type of the same width (e.g., "
- "'uint8', 'uint16', 'uint32' or 'uint64'). 2) Convert "
- "the unsigned input to a signed one of the next "
- "largest width with the type conversion operators "
- "(e.g., 'int16', 'int32' or 'int64'). For more, see "
- "the \"Integer benefits and pitfalls\" section of "
- "Gnuastro's manual with this command: 'info gnuastro "
- "integer'. This warning can be removed with '--quiet' "
- "(or '-q')", gal_arithmetic_operator_string(operator),
+ "but a different sign: the first popped operand (that "
+ "is closer to the operator, or the \"right\" operand) "
+ "has type '%s' and the second (or \"left\" operand) "
+ "has type '%s'. This may create wrong results, for "
+ "example when the signed input contains negative "
+ "values. To address this problem there are two "
+ "options: 1) if you know that the signed input can "
+ "only have positive values, use Arithmetic's type "
+ "conversion operators to convert it to an un-signed "
+ "type of the same width (e.g., 'uint8', 'uint16', "
+ "'uint32' or 'uint64'). 2) Convert the unsigned "
+ "input to a signed one of the next largest width "
+ "using the type conversion operators (e.g., 'int16', "
+ "'int32' or 'int64'). For more, see the \"Integer "
+ "benefits and pitfalls\" section of Gnuastro's "
+ "manual with this command: 'info gnuastro integer'. "
+ "This warning can be removed with '--quiet' (or "
+ "'-q')", gal_arithmetic_operator_string(operator),
gal_type_name(r->type, 1), gal_type_name(l->type, 1));
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master fe81ab19: Library (arithmetic): more clear warning on integer sanity check,
Mohammad Akhlaghi <=