PostGIS  3.1.6dev-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 630 of file rt_util.c.

635  {
636  int result = 0;
637 
638  switch (pixtype) {
639  case PT_1BB:
640  case PT_2BUI:
641  case PT_4BUI:
642  case PT_8BSI:
643  case PT_8BUI:
644  case PT_16BSI:
645  case PT_16BUI:
646  case PT_32BSI: {
647  if (fabs(checkvalint - initialvalue) >= 1) {
648 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
649  rtwarn("Value set for %s band got clamped from %f to %d",
650  rt_pixtype_name(pixtype),
651  initialvalue, checkvalint
652  );
653 #endif
654  result = 1;
655  }
656  else if (checkvalint != initialvalue)
657  {
658 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
659  rtwarn("Value set for %s band got truncated from %f to %d",
660  rt_pixtype_name(pixtype),
661  initialvalue, checkvalint
662  );
663 #endif
664  result = 1;
665  }
666  break;
667  }
668  case PT_32BUI: {
669  if (fabs(checkvaluint - initialvalue) >= 1) {
670 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
671  rtwarn("Value set for %s band got clamped from %f to %u",
672  rt_pixtype_name(pixtype),
673  initialvalue, checkvaluint
674  );
675 #endif
676  result = 1;
677  }
678  else if (checkvaluint != initialvalue)
679  {
680 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
681  rtwarn("Value set for %s band got truncated from %f to %u",
682  rt_pixtype_name(pixtype),
683  initialvalue, checkvaluint
684  );
685 #endif
686  result = 1;
687  }
688  break;
689  }
690  case PT_32BF: {
691  /*
692  For float, because the initial value is a double,
693  there is very often a difference between the desired value and the obtained one
694  */
695  if (FLT_NEQ(checkvalfloat, initialvalue)) {
696 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
697  rtwarn("Value set for %s band got converted from %f to %f",
698  rt_pixtype_name(pixtype),
699  initialvalue, checkvalfloat
700  );
701 #endif
702  result = 1;
703  }
704  break;
705  }
706  case PT_64BF: {
707  if (FLT_NEQ(checkvaldouble, initialvalue)) {
708 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
709  rtwarn("Value set for %s band got converted from %f to %f",
710  rt_pixtype_name(pixtype),
711  initialvalue, checkvaldouble
712  );
713 #endif
714  result = 1;
715  }
716  break;
717  }
718  case PT_END:
719  break;
720  }
721 
722  return result;
723 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
#define FLT_NEQ(x, y)
Definition: librtcore.h:2234
@ PT_32BUI
Definition: librtcore.h:194
@ PT_2BUI
Definition: librtcore.h:187
@ PT_32BSI
Definition: librtcore.h:193
@ PT_END
Definition: librtcore.h:197
@ PT_4BUI
Definition: librtcore.h:188
@ PT_32BF
Definition: librtcore.h:195
@ PT_1BB
Definition: librtcore.h:186
@ PT_16BUI
Definition: librtcore.h:192
@ PT_8BSI
Definition: librtcore.h:189
@ PT_16BSI
Definition: librtcore.h:191
@ PT_64BF
Definition: librtcore.h:196
@ PT_8BUI
Definition: librtcore.h:190
void rtwarn(const char *fmt,...)
Definition: rt_context.c:224
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: