PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwprint_double()

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

Definition at line 490 of file lwprint.c.

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

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().

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