[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 87ab805 014/113: Identifiers for integer const
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 87ab805 014/113: Identifiers for integer constants in BZERO comparisons |
Date: |
Fri, 16 Apr 2021 10:33:33 -0400 (EDT) |
branch: master
commit 87ab80524f95339958dbf38abf789f61762cf6f1
Author: Mohammad Akhlaghi <akhlaghi@gnu.org>
Commit: Mohammad Akhlaghi <akhlaghi@gnu.org>
Identifiers for integer constants in BZERO comparisons
For each integer width, the FITS standard only defines one type: unsigned
8-bit, signed 16-bit and so on. So to allow other types (for example signed
8-bit or unsigned 16-bit), it defines constant values for BZERO. The
constants for 8-bit and 16-bit integers have no particular problem, but for
the 32-bit and 64-bit integers, if there is no identifiers, the compilers
may produce warnings (on 32-bit and 64-bit systems).
Until now, only the 64-bit value was given an identifier of `.0f' to read
it as float. But floats (even double precision), don't have the necessary
resolution for such large integers (`double' can only accurately keep an
integer until 15 significant decimal digits). For the 32-bit value, I got a
compiler warning on a 32-bit `armv81' GCC ("Warning, this decimal constatn
is unsigned only in ISO C90").
To fix the problem, the `LU' and `LLU' identifiers were added for the
32-bit and 64-bit constants of `fits_type_correct'. However, this doesn't
fix another problem with comparing a floating point to the 64-bit integer
constant. In a check, I noticed that after defining `a' and `b' as: `double
a=9223372036854775808LLU, b=9223372036854775807LLU;' (note that `a=b+1'),
the condition `a==b' succeeds (because of limited floating point
precision). So I just sent a mail to William Pence (author of CFITSIO)
about the issue to get his comments.
---
lib/fits.c | 44 +++++++++++++++++++++-----------------------
1 file changed, 21 insertions(+), 23 deletions(-)
diff --git a/lib/fits.c b/lib/fits.c
index 4cddcc6..2f3860d 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -470,42 +470,40 @@ gal_fits_datatype_to_type(int datatype, int
is_table_column)
type that must be used to store the actual values of the pixels may be
different from the type from BITPIX. This function does the necessary
corrections.*/
-void
+static void
fits_type_correct(int *type, double bscale, double bzero)
{
int tofloat=1;
- /* Work based on type, for the default conversions defined by CFITSIO,
- make the proper correction, otherwise set the type to float. */
+ /* Work based on type. For the default conversions defined by the FITS
+ standard to change the signs of integers, make the proper correction,
+ otherwise set the type to float. */
if(bscale==1.0f)
switch(*type)
{
case GAL_TYPE_UINT8:
- if(bzero == -128.0f) { *type = GAL_TYPE_INT8; tofloat=0; }
+ if(bzero == -128) { *type = GAL_TYPE_INT8; tofloat=0; }
break;
- case GAL_TYPE_INT16:
- /* Defined by the FITS standard: */
- if(bzero == 32768) { *type = GAL_TYPE_UINT16; tofloat=0; }
- break;
+ case GAL_TYPE_INT16:
+ if(bzero == 32768) { *type = GAL_TYPE_UINT16; tofloat=0; }
+ break;
- case GAL_TYPE_INT32:
- /* Defined by the FITS standard: */
- if(bzero == 2147483648) { *type = GAL_TYPE_UINT32; tofloat=0; }
- break;
+ case GAL_TYPE_INT32:
+ if(bzero == 2147483648LU) { *type = GAL_TYPE_UINT32; tofloat=0; }
+ break;
- case GAL_TYPE_INT64:
- /* Defined by the FITS standard: */
- if(bzero == 9223372036854775808.0f)
- {*type = GAL_TYPE_UINT64; tofloat=0;}
- break;
+ case GAL_TYPE_INT64:
+ if(bzero == 9223372036854775808LLU)
+ {*type = GAL_TYPE_UINT64; tofloat=0;}
+ break;
- /* For the other types (when `BSCALE=1.0f'), currently no correction is
- necessary, maybe later we can check if the scales are integers and
- set the integer output type to the smallest type that can allow the
- scaled values. */
- default: tofloat=0;
- }
+ /* For the other types (when `BSCALE=1.0f'), currently no correction is
+ necessary, maybe later we can check if the scales are integers and
+ set the integer output type to the smallest type that can allow the
+ scaled values. */
+ default: tofloat=0;
+ }
/* If the type must be a float, then do the conversion. */
if(tofloat) *type=GAL_TYPE_FLOAT32;
- [gnuastro-commits] master 40f0a56 013/113: Minor corrections to MakeProfiles continued, (continued)
- [gnuastro-commits] master 40f0a56 013/113: Minor corrections to MakeProfiles continued, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 8372486 020/113: NoiseChisel's detection complete in 3D, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 6cc3d25 027/113: No 3D projections in function to inspect NoiseChisel outputs, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master e990860 029/113: Merged recent updates in master, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 6bdc5d6 030/113: Oversegmentation connectivity one less for 3D, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master be3bfd8 033/113: NoiseChisel configuration file in 3D updated, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 3b6c15d 036/113: Merged with recent work in master, no conflicts, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master fb3660f 037/113: MakeCatalog works in 3D, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 73fdf0c 006/113: MakeProfiles builds 3D ellipsoids, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 03d73fe 011/113: Some minor corrections in code and comments, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 87ab805 014/113: Identifiers for integer constants in BZERO comparisons,
Mohammad Akhlaghi <=
- [gnuastro-commits] master 1483201 009/113: Noised cube created in make check, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master bdeaba9 012/113: Corrected name of 3D catalog for tarball inclusion, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 6b53c5e 015/113: Bug fixes in master: commits 1ff1c25 and 540af65, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master adeb1c6 016/113: NoiseChisel's convolution step in 3D completed, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master ace4160 017/113: New --mcolisbrightness option for MakeProfiles, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master f06acc5 018/113: Merged recent work from master, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 61aec7b 019/113: Convolve name and dimensionality checks, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 4627ddf 021/113: NoiseChisel segmentation working in 3D, test added, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 1560a54 022/113: Default NoiseChisel kernel in 3D changed to 1.5 pixels, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 4d2508f 028/113: Fixed NoiseChisel opening and dilation and merged with master, Mohammad Akhlaghi, 2021/04/16