PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ lwprint_double()

int lwprint_double ( double  d,
int  maxdd,
char *  buf,
size_t  bufsize 
)

Definition at line 488 of file lwprint.c.

References FP_TOLERANCE, OUT_MAX_DOUBLE, OUT_MAX_DOUBLE_PRECISION, and trim_trailing_zeros().

Referenced by assvg_point_buf(), pointArray_svg_abs(), pointArray_svg_rel(), pointArray_to_geojson(), pointArray_toGML2(), pointArray_toGML3(), ptarray_to_wkt_sb(), and ptarray_to_x3d3_sb().

489 {
490  double ad = fabs(d);
491  int ndd;
492  int length = 0;
493  if (ad <= FP_TOLERANCE)
494  {
495  d = 0;
496  ad = 0;
497  }
498  if (ad < OUT_MAX_DOUBLE)
499  {
500  ndd = ad < 1 ? 0 : floor(log10(ad)) + 1; /* non-decimal digits */
501  if (maxdd > (OUT_MAX_DOUBLE_PRECISION - ndd)) maxdd -= ndd;
502  length = snprintf(buf, bufsize, "%.*f", maxdd, d);
503  }
504  else
505  {
506  length = snprintf(buf, bufsize, "%g", d);
507  }
508  assert(length < (int) bufsize);
509  trim_trailing_zeros(buf);
510  return length;
511 }
#define OUT_MAX_DOUBLE_PRECISION
#define FP_TOLERANCE
Floating point comparators.
#define OUT_MAX_DOUBLE
static void trim_trailing_zeros(char *str)
Definition: lwprint.c:444
Here is the call graph for this function:
Here is the caller graph for this function: