PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ trim_preserve_decimal_digits()

static double trim_preserve_decimal_digits ( double  d,
int32_t  decimal_digits 
)
static

Definition at line 2491 of file lwgeom.c.

2492 {
2493  if (d == 0)
2494  return 0;
2495 
2496  int digits_left_of_decimal = (int) (1 + log10(fabs(d)));
2497  uint8_t bits_needed = bits_for_precision(decimal_digits + digits_left_of_decimal);
2498  uint64_t mask = 0xffffffffffffffffULL << (52 - bits_needed);
2499  uint64_t dint = 0;
2500  size_t dsz = sizeof(d) < sizeof(dint) ? sizeof(d) : sizeof(dint);
2501 
2502  memcpy(&dint, &d, dsz);
2503  dint &= mask;
2504  memcpy(&d, &dint, dsz);
2505  return d;
2506 }
static uint8_t bits_for_precision(int32_t significant_digits)
Definition: lwgeom.c:2475

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: