summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-04 06:16:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-04 06:16:54 -0700
commit959f4259bde59d89f257fdfec0334b421f1dd8ce (patch)
treeda08423aa6cc3663f11b55c55317d31cfa5801e8
parentf33a3b23cbec3a636a67b070e3ed4245ed7fc155 (diff)
downloadtxr-959f4259bde59d89f257fdfec0334b421f1dd8ce.tar.gz
txr-959f4259bde59d89f257fdfec0334b421f1dd8ce.tar.bz2
txr-959f4259bde59d89f257fdfec0334b421f1dd8ce.zip
bugfix: tostringp not behaving right for floats.
The obj printer is ignoring the pretty flag when rendering floating-point numbers, and just formatting them using *print-flo-format*. To address this issue, we introduce an additional *pprint-flo-format* variable. * lib.c (obj_print_impl): In the FLNUM case, use either the value of *print-flo-format* or *pprint-flo-format* based on the value of the pretty flag. * stream.c (pprint_flo_format_s): New symbol variable. (stream_init): Initialize pprint_flo_format_s with interned symbol *pprint-flo-format* and register this as a special variable. * stream.c (pprint_flo_format_s): Declared. * txr.1: Documented *pprint-flo-format*. Also put in a note in the description of the various print functions that the equivalences based on ~s and ~a only apply to floats when the special variables have their original values.
-rw-r--r--lib.c4
-rw-r--r--stream.c5
-rw-r--r--stream.h2
-rw-r--r--txr.139
4 files changed, 40 insertions, 10 deletions
diff --git a/lib.c b/lib.c
index 96b18000..a38ac973 100644
--- a/lib.c
+++ b/lib.c
@@ -10188,7 +10188,9 @@ dot:
break;
case FLNUM:
{
- val fmt = cdr(lookup_var(nil, print_flo_format_s));
+ val fmt = cdr(lookup_var(nil,
+ if3(pretty,
+ pprint_flo_format_s, print_flo_format_s)));
format(out, fmt, obj, nao);
}
break;
diff --git a/stream.c b/stream.c
index b00b4720..b34da981 100644
--- a/stream.c
+++ b/stream.c
@@ -74,7 +74,7 @@
val stdin_s, stdout_s, stddebug_s, stderr_s, stdnull_s;
val print_flo_precision_s, print_flo_digits_s, print_flo_format_s;
-val print_base_s, print_circle_s;
+val pprint_flo_format_s, print_base_s, print_circle_s;
val from_start_k, from_current_k, from_end_k;
val real_time_k, name_k, addr_k, fd_k, byte_oriented_k;
@@ -4193,6 +4193,9 @@ void stream_init(void)
reg_var(print_flo_format_s = intern(lit("*print-flo-format*"),
user_package),
lit("~s"));
+ reg_var(pprint_flo_format_s = intern(lit("*pprint-flo-format*"),
+ user_package),
+ lit("~a"));
reg_var(print_base_s = intern(lit("*print-base*"), user_package),
num_fast(10));
reg_var(print_circle_s = intern(lit("*print-circle*"), user_package), nil);
diff --git a/stream.h b/stream.h
index 24492459..1985cb42 100644
--- a/stream.h
+++ b/stream.h
@@ -123,7 +123,7 @@ extern val stdio_stream_s;
extern val stdin_s, stdout_s, stddebug_s, stderr_s, stdnull_s;
extern val print_flo_precision_s, print_flo_digits_s, print_flo_format_s;
-extern val print_base_s, print_circle_s;
+extern val pprint_flo_format_s, print_base_s, print_circle_s;
#if HAVE_SOCKETS
extern val socket_error_s;
diff --git a/txr.1 b/txr.1
index 95d79f2b..e9ae27e5 100644
--- a/txr.1
+++ b/txr.1
@@ -39351,7 +39351,7 @@ the
.code /dev/null
device on Unix, but does not involve the operating system.
-.coNP Special variable @ *print-flo-format*
+.coNP Special variables @ *print-flo-format* and @ *pprint-flo-format*
.desc
The
.code *print-flo-format*
@@ -39359,23 +39359,37 @@ variable determines the conversion format which is applied when
a floating-point value is converted to decimal text by the
functions
.codn print ,
-.codn pprint ,
.codn prinl ,
+and
+.codn tostring .
+
+The default value is
+.codn "~s" .
+
+The related variable
+.code *pprint-flo-format*
+similarly determines the conversion format applied to floating-point
+values by the functions
+.codn pprint ,
.codn pprinl ,
-.code tostring
and
.codn tostringp .
The default value is
-.codn "~s" .
+.codn "~a" .
-The format string must specify the consumption of exactly one argument.
+The format string in either variable must specify the consumption of
+exactly one
+.code format
+argument.
The conversion string may use embedded width and precision values:
for instance,
.code "~3,4f"
is a valid value for
-.codn *print-flo-format* .
+.code *print-flo-format*
+or
+.codn *pprint-flo-format* .
.coNP Special variable @ *print-flo-precision*
.desc
@@ -40011,7 +40025,18 @@ the equivalence is produced by using
in format rather than
.codn ~s .
-Note: for characters, the print function behaves as follows: most control
+.TP* Notes:
+For floating-point numbers, the above description of the behavior in
+terms of the format specifiers
+.code ~s
+and
+.code ~a
+only applies with respect to the default values of the variables
+.code *print-flo-format*
+and
+.codn *pprint-flo-format* .
+
+For characters, the print function behaves as follows: most control
characters in the Unicode
.code C0
and