UT_string *buf = ud;
const double delta = 0.0000001;
- if (val == (double)(int)val) {
- utstring_printf (buf, "%.1lf", val);
- }
- else if (fabs (val - (double)(int)val) < delta) {
- /* Write at maximum precision */
- utstring_printf (buf, "%.*lg", DBL_DIG, val);
+ if (isfinite (val)) {
+ if (val == (double) (int) val) {
+ utstring_printf (buf, "%.1lf", val);
+ } else if (fabs (val - (double) (int) val) < delta) {
+ /* Write at maximum precision */
+ utstring_printf (buf, "%.*lg", DBL_DIG, val);
+ } else {
+ utstring_printf (buf, "%lf", val);
+ }
}
else {
- utstring_printf (buf, "%lf", val);
+ utstring_append_len (buf, "null", 5);
}
return 0;
FILE *fp = ud;
const double delta = 0.0000001;
- if (val == (double)(int)val) {
- fprintf (fp, "%.1lf", val);
- }
- else if (fabs (val - (double)(int)val) < delta) {
- /* Write at maximum precision */
- fprintf (fp, "%.*lg", DBL_DIG, val);
+ if (isfinite (val)) {
+ if (val == (double) (int) val) {
+ fprintf (fp, "%.1lf", val);
+ } else if (fabs (val - (double) (int) val) < delta) {
+ /* Write at maximum precision */
+ fprintf (fp, "%.*lg", DBL_DIG, val);
+ } else {
+ fprintf (fp, "%lf", val);
+ }
}
else {
- fprintf (fp, "%lf", val);
+ /* Encode as null */
+ fprintf (fp, "null");
}
return 0;
const double delta = 0.0000001;
char nbuf[64];
- if (val == (double)(int)val) {
- snprintf (nbuf, sizeof (nbuf), "%.1lf", val);
- }
- else if (fabs (val - (double)(int)val) < delta) {
- /* Write at maximum precision */
- snprintf (nbuf, sizeof (nbuf), "%.*lg", DBL_DIG, val);
+ if (isfinite (val)) {
+ if (val == (double) (int) val) {
+ snprintf (nbuf, sizeof (nbuf), "%.1lf", val);
+ } else if (fabs (val - (double) (int) val) < delta) {
+ /* Write at maximum precision */
+ snprintf (nbuf, sizeof (nbuf), "%.*lg", DBL_DIG, val);
+ } else {
+ snprintf (nbuf, sizeof (nbuf), "%lf", val);
+ }
}
else {
- snprintf (nbuf, sizeof (nbuf), "%lf", val);
+ memcpy (nbuf, "null", 5);
}
return write (fd, nbuf, strlen (nbuf));
GString *buf = ud;
const double delta = 0.0000001;
- if (val == (double) (int) val) {
- rspamd_printf_gstring (buf, "%.1f", val);
- }
- else if (fabs (val - (double) (int) val) < delta) {
- /* Write at maximum precision */
- rspamd_printf_gstring (buf, "%.*g", DBL_DIG, val);
+ if (isfinite (val)) {
+ if (val == (double) (int) val) {
+ rspamd_printf_gstring (buf, "%.1f", val);
+ } else if (fabs (val - (double) (int) val) < delta) {
+ /* Write at maximum precision */
+ rspamd_printf_gstring (buf, "%.*g", DBL_DIG, val);
+ } else {
+ rspamd_printf_gstring (buf, "%f", val);
+ }
}
else {
- rspamd_printf_gstring (buf, "%f", val);
+ rspamd_printf_gstring (buf, "null");
}
return 0;
rspamd_fstring_t **buf = ud;
const double delta = 0.0000001;
- if (val == (double)((gint) val)) {
- rspamd_printf_fstring (buf, "%.1f", val);
- }
- else if (fabs (val - (double) (int) val) < delta) {
- /* Write at maximum precision */
- rspamd_printf_fstring (buf, "%.*g", DBL_DIG, val);
+ if (isfinite (val)) {
+ if (val == (double) ((gint) val)) {
+ rspamd_printf_fstring (buf, "%.1f", val);
+ } else if (fabs (val - (double) (int) val) < delta) {
+ /* Write at maximum precision */
+ rspamd_printf_fstring (buf, "%.*g", DBL_DIG, val);
+ } else {
+ rspamd_printf_fstring (buf, "%f", val);
+ }
}
else {
- rspamd_printf_fstring (buf, "%f", val);
+ rspamd_printf_fstring (buf, "null");
}
return 0;