[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master e63b42a 1/2: Arithmetic: numbers printed with
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master e63b42a 1/2: Arithmetic: numbers printed with custom print format based on type |
Date: |
Thu, 28 Feb 2019 12:52:53 -0500 (EST) |
branch: master
commit e63b42a9707437cc9fbd9d9b5ca4c71a6ae3e98b
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Arithmetic: numbers printed with custom print format based on type
Until now, when printing a single number, Arithmetic would simply convert
the dataset to 64-bit floating point, then use `%g' to print it to standard
output. But that would make unreasonable results (for example a large
integer would be written in scientific notation which discards some of the
decimals).
This feature of Arithmetic pre-dates the `gal_type_to_string', so with this
commit we are using this function to print the value with the proper printf
formating in its native type.
---
bin/arithmetic/arithmetic.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index 46ca143..b221ce9 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -905,9 +905,9 @@ void
reversepolish(struct arithmeticparams *p)
{
int op=0, nop=0;
- char *filename, *hdu;
unsigned int numop, i;
gal_list_str_t *token;
+ char *hdu, *filename, *printnum;
gal_data_t *d1=NULL, *d2=NULL, *d3=NULL;
int flags = ( GAL_ARITHMETIC_INPLACE | GAL_ARITHMETIC_FREE
| GAL_ARITHMETIC_NUMOK );
@@ -1256,11 +1256,12 @@ reversepolish(struct arithmeticparams *p)
d1=p->operands->data;
if(d1->size==1)
{
- /* To simplify the printing process, we will first change it to
- double, then use printf's `%g' to print it, so integers will be
- printed as an integer. */
- d2=gal_data_copy_to_new_type(d1, GAL_TYPE_FLOAT64);
- printf("%g\n", *(double *)d2->array);
+ /* Make the string to print the number. */
+ printnum=gal_type_to_string(d1->array, d1->type, 0);
+ printf("%s\n", printnum);
+
+ /* Clean up. */
+ free(printnum);
if(d2!=d1) gal_data_free(d2);
}
else