PostGIS  3.3.9dev-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 673 of file rt_util.c.

678  {
679  int result = 0;
680 
681  switch (pixtype) {
682  case PT_1BB:
683  case PT_2BUI:
684  case PT_4BUI:
685  case PT_8BSI:
686  case PT_8BUI:
687  case PT_16BSI:
688  case PT_16BUI:
689  case PT_32BSI: {
690  if (fabs(checkvalint - initialvalue) >= 1) {
691 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
692  rtwarn("Value set for %s band got clamped from %f to %d",
693  rt_pixtype_name(pixtype),
694  initialvalue, checkvalint
695  );
696 #endif
697  result = 1;
698  }
699  else if (checkvalint != initialvalue)
700  {
701 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
702  rtwarn("Value set for %s band got truncated from %f to %d",
703  rt_pixtype_name(pixtype),
704  initialvalue, checkvalint
705  );
706 #endif
707  result = 1;
708  }
709  break;
710  }
711  case PT_32BUI: {
712  if (fabs(checkvaluint - initialvalue) >= 1) {
713 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
714  rtwarn("Value set for %s band got clamped from %f to %u",
715  rt_pixtype_name(pixtype),
716  initialvalue, checkvaluint
717  );
718 #endif
719  result = 1;
720  }
721  else if (checkvaluint != initialvalue)
722  {
723 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
724  rtwarn("Value set for %s band got truncated from %f to %u",
725  rt_pixtype_name(pixtype),
726  initialvalue, checkvaluint
727  );
728 #endif
729  result = 1;
730  }
731  break;
732  }
733  case PT_32BF: {
734  /*
735  For float, because the initial value is a double,
736  there is very often a difference between the desired value and the obtained one
737  */
738  if (FLT_NEQ(checkvalfloat, initialvalue)) {
739 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
740  rtwarn("Value set for %s band got converted from %f to %f",
741  rt_pixtype_name(pixtype),
742  initialvalue, checkvalfloat
743  );
744 #endif
745  result = 1;
746  }
747  break;
748  }
749  case PT_64BF: {
750  if (FLT_NEQ(checkvaldouble, initialvalue)) {
751 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
752  rtwarn("Value set for %s band got converted from %f to %f",
753  rt_pixtype_name(pixtype),
754  initialvalue, checkvaldouble
755  );
756 #endif
757  result = 1;
758  }
759  break;
760  }
761  case PT_END:
762  break;
763  }
764 
765  return result;
766 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
#define FLT_NEQ(x, y)
Definition: librtcore.h:2379
@ 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
void rtwarn(const char *fmt,...)
Definition: rt_context.c:244
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_reclass(), rt_band_set_nodata(), rt_band_set_pixel(), and rt_raster_generate_new_band().

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