PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ trim_preserve_decimal_digits()

static double trim_preserve_decimal_digits ( double  d,
int32_t  decimal_digits 
)
static

Definition at line 2548 of file lwgeom.c.

2549 {
2550  if (d == 0)
2551  return 0;
2552 
2553  int digits_left_of_decimal = (int) (1 + log10(fabs(d)));
2554  uint8_t bits_needed = bits_for_precision(decimal_digits + digits_left_of_decimal);
2555  uint64_t mask = 0xffffffffffffffffULL << (52 - bits_needed);
2556  uint64_t dint = 0;
2557  size_t dsz = sizeof(d) < sizeof(dint) ? sizeof(d) : sizeof(dint);
2558 
2559  memcpy(&dint, &d, dsz);
2560  dint &= mask;
2561  memcpy(&d, &dint, dsz);
2562  return d;
2563 }
static uint8_t bits_for_precision(int32_t significant_digits)
Definition: lwgeom.c:2532

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: