PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ trim_preserve_decimal_digits()

static double trim_preserve_decimal_digits ( double  d,
int32_t  decimal_digits 
)
static

Definition at line 2531 of file lwgeom.c.

2532 {
2533  if (d == 0)
2534  return 0;
2535 
2536  int digits_left_of_decimal = (int) (1 + log10(fabs(d)));
2537  uint8_t bits_needed = bits_for_precision(decimal_digits + digits_left_of_decimal);
2538  uint64_t mask = 0xffffffffffffffffULL << (52 - bits_needed);
2539  uint64_t dint = 0;
2540  size_t dsz = sizeof(d) < sizeof(dint) ? sizeof(d) : sizeof(dint);
2541 
2542  memcpy(&dint, &d, dsz);
2543  dint &= mask;
2544  memcpy(&d, &dint, dsz);
2545  return d;
2546 }
static uint8_t bits_for_precision(int32_t significant_digits)
Definition: lwgeom.c:2515

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: