PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ rt_util_dbl_trunc_warning()

int rt_util_dbl_trunc_warning ( double  initialvalue,
int32_t  checkvalint,
uint32_t  checkvaluint,
float  checkvalfloat,
double  checkvaldouble,
rt_pixtype  pixtype 
)

Definition at line 681 of file rt_util.c.

686  {
687  int result = 0;
688 
689  switch (pixtype) {
690  case PT_1BB:
691  case PT_2BUI:
692  case PT_4BUI:
693  case PT_8BSI:
694  case PT_8BUI:
695  case PT_16BSI:
696  case PT_16BUI:
697  case PT_32BSI: {
698  if (fabs(checkvalint - initialvalue) >= 1) {
699 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
700  rtwarn("Value set for %s band got clamped from %f to %d",
701  rt_pixtype_name(pixtype),
702  initialvalue, checkvalint
703  );
704 #endif
705  result = 1;
706  }
707  else if (checkvalint != initialvalue)
708  {
709 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
710  rtwarn("Value set for %s band got truncated from %f to %d",
711  rt_pixtype_name(pixtype),
712  initialvalue, checkvalint
713  );
714 #endif
715  result = 1;
716  }
717  break;
718  }
719  case PT_32BUI: {
720  if (fabs(checkvaluint - initialvalue) >= 1) {
721 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
722  rtwarn("Value set for %s band got clamped from %f to %u",
723  rt_pixtype_name(pixtype),
724  initialvalue, checkvaluint
725  );
726 #endif
727  result = 1;
728  }
729  else if (checkvaluint != initialvalue)
730  {
731 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
732  rtwarn("Value set for %s band got truncated from %f to %u",
733  rt_pixtype_name(pixtype),
734  initialvalue, checkvaluint
735  );
736 #endif
737  result = 1;
738  }
739  break;
740  }
741  case PT_32BF: {
742  /*
743  For float, because the initial value is a double,
744  there is very often a difference between the desired value and the obtained one
745  */
746  if (FLT_NEQ(checkvalfloat, initialvalue)) {
747 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
748  rtwarn("Value set for %s band got converted from %f to %f",
749  rt_pixtype_name(pixtype),
750  initialvalue, checkvalfloat
751  );
752 #endif
753  result = 1;
754  }
755  break;
756  }
757  case PT_64BF: {
758  if (FLT_NEQ(checkvaldouble, initialvalue)) {
759 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
760  rtwarn("Value set for %s band got converted from %f to %f",
761  rt_pixtype_name(pixtype),
762  initialvalue, checkvaldouble
763  );
764 #endif
765  result = 1;
766  }
767  break;
768  }
769  case PT_END:
770  break;
771  }
772 
773  return result;
774 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
#define FLT_NEQ(x, y)
Definition: librtcore.h:2423
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
@ PT_32BUI
Definition: librtcore.h:196
@ PT_2BUI
Definition: librtcore.h:189
@ PT_32BSI
Definition: librtcore.h:195
@ PT_END
Definition: librtcore.h:199
@ PT_4BUI
Definition: librtcore.h:190
@ PT_32BF
Definition: librtcore.h:197
@ PT_1BB
Definition: librtcore.h:188
@ PT_16BUI
Definition: librtcore.h:194
@ PT_8BSI
Definition: librtcore.h:191
@ PT_16BSI
Definition: librtcore.h:193
@ PT_64BF
Definition: librtcore.h:198
@ PT_8BUI
Definition: librtcore.h:192
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110

References FLT_NEQ, PT_16BSI, PT_16BUI, PT_1BB, PT_2BUI, PT_32BF, PT_32BSI, PT_32BUI, PT_4BUI, PT_64BF, PT_8BSI, PT_8BUI, PT_END, result, rt_pixtype_name(), and rtwarn().

Referenced by rt_band_init_value(), rt_band_set_nodata(), and rt_band_set_pixel().

Here is the call graph for this function:
Here is the caller graph for this function: