Changeset: 476fea0b018d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/476fea0b018d
Modified Files:
clients/mapiclient/mclient.c
gdk/gdk_atoms.c
Branch: Aug2024
Log Message:
Print whole floating point numbers as integers.
diffs (112 lines):
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1177,10 +1177,16 @@ TESTrenderer(MapiHdl hdl)
if (strcmp(s, "-0") == 0) /* normalize -0 */
s = "0";
v = strtod(s, NULL);
- for (j = 4; j < 11; j++) {
- snprintf(buf, sizeof(buf), "%.*g", j,
v);
- if (v == strtod(buf, NULL))
- break;
+ if (v > (double) 999999999999999 ||
+ v < (double) -999999999999999 ||
+ (double) (int) v != v ||
+ snprintf(buf, sizeof(buf), "%.0f", v)
<= 0 ||
+ strtod(buf, NULL) != v) {
+ for (j = 4; j < 11; j++) {
+ snprintf(buf, sizeof(buf),
"%.*g", j, v);
+ if (v == strtod(buf, NULL))
+ break;
+ }
}
mnstr_printf(toConsole, "%s", buf);
} else if (strcmp(tp, "real") == 0) {
@@ -1190,10 +1196,16 @@ TESTrenderer(MapiHdl hdl)
if (strcmp(s, "-0") == 0) /* normalize -0 */
s = "0";
v = strtof(s, NULL);
- for (j = 4; j < 6; j++) {
- snprintf(buf, sizeof(buf), "%.*g", j,
v);
- if (v == strtof(buf, NULL))
- break;
+ if (v > (float) 9999999 ||
+ v < (float) -9999999 ||
+ (float) (int) v != v ||
+ snprintf(buf, sizeof(buf), "%.0f", v)
<= 0 ||
+ strtof(buf, NULL) != v) {
+ for (j = 4; j < 6; j++) {
+ snprintf(buf, sizeof(buf),
"%.*g", j, v);
+ if (v == strtof(buf, NULL))
+ break;
+ }
}
mnstr_printf(toConsole, "%s", buf);
} else
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -1086,7 +1086,7 @@ dblFromStr(const char *src, size_t *len,
ssize_t
dblToStr(char **dst, size_t *len, const dbl *src, bool external)
{
- int i;
+ int l = 0;
atommem(dblStrlen);
if (is_dbl_nil(*src)) {
@@ -1097,12 +1097,19 @@ dblToStr(char **dst, size_t *len, const
strcpy(*dst, str_nil);
return 1;
}
- for (i = 4; i < 18; i++) {
- snprintf(*dst, *len, "%.*g", i, *src);
+ if (*src <= (dbl) 999999999999999 &&
+ *src >= (dbl) -999999999999999 &&
+ (dbl) (int) *src == *src) {
+ l = snprintf(*dst, *len, "%.0f", *src);
+ if (strtod(*dst, NULL) == *src)
+ return (ssize_t) l;
+ }
+ for (int i = 4; i < 18; i++) {
+ l = snprintf(*dst, *len, "%.*g", i, *src);
if (strtod(*dst, NULL) == *src)
break;
}
- return (ssize_t) strlen(*dst);
+ return (ssize_t) l;
}
atom_io(dbl, Lng, lng)
@@ -1160,7 +1167,7 @@ fltFromStr(const char *src, size_t *len,
ssize_t
fltToStr(char **dst, size_t *len, const flt *src, bool external)
{
- int i;
+ int l = 0;
atommem(fltStrlen);
if (is_flt_nil(*src)) {
@@ -1171,12 +1178,19 @@ fltToStr(char **dst, size_t *len, const
strcpy(*dst, str_nil);
return 1;
}
- for (i = 4; i < 10; i++) {
- snprintf(*dst, *len, "%.*g", i, *src);
+ if (*src <= (flt) 9999999 &&
+ *src >= (flt) -9999999 &&
+ (flt) (int) *src == *src) {
+ l = snprintf(*dst, *len, "%.0f", *src);
+ if (strtof(*dst, NULL) == *src)
+ return (ssize_t) l;
+ }
+ for (int i = 4; i < 10; i++) {
+ l = snprintf(*dst, *len, "%.*g", i, *src);
if (strtof(*dst, NULL) == *src)
break;
}
- return (ssize_t) strlen(*dst);
+ return (ssize_t) l;
}
atom_io(flt, Int, int)
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]