PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ trim_preserve_decimal_digits()

static double trim_preserve_decimal_digits ( double  d,
int32_t  decimal_digits 
)
static

Definition at line 2501 of file lwgeom.c.

2502 {
2503  if (d == 0)
2504  return 0;
2505 
2506  int digits_left_of_decimal = (int) (1 + log10(fabs(d)));
2507  uint8_t bits_needed = bits_for_precision(decimal_digits + digits_left_of_decimal);
2508  uint64_t mask = 0xffffffffffffffffULL << (52 - bits_needed);
2509  uint64_t dint = 0;
2510  size_t dsz = sizeof(d) < sizeof(dint) ? sizeof(d) : sizeof(dint);
2511 
2512  memcpy(&dint, &d, dsz);
2513  dint &= mask;
2514  memcpy(&d, &dint, dsz);
2515  return d;
2516 }
static uint8_t bits_for_precision(int32_t significant_digits)
Definition: lwgeom.c:2485
unsigned char uint8_t
Definition: uthash.h:79

References bits_for_precision().

Referenced by lwgeom_trim_bits_in_place().

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