From 9f633256dea9a141bc5a4d96b2b9c47e3ecb4858 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 13 Nov 2015 20:36:46 -0800 Subject: New global control over float print precision. * configure (have_dbl_decimal_dig): New variable. New configure test to test for DBL_DECIMAL_DIG or __DBL_DECIMAL_DIG__, resulting in FLO_MAX_DIG macro being deposited in config.h. * arith.c (arith_init): Register flo-max-dig variable. * stream.c (print_flo_precision_s): New symbol variable. (formatv): Obtain default precision from *print-flo-precision* special variable, rather than hard coded DBL_DIG. (stream_init): Initialize print_flo_precision_s variable, and register *print-flo-precision* special. * txr.1: Document flo-max-dig, *print-flo-precision*, and change of behavior in format. --- stream.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'stream.c') diff --git a/stream.c b/stream.c index 275de1bb..ade41325 100644 --- a/stream.c +++ b/stream.c @@ -63,6 +63,8 @@ val stdin_s, stdout_s, stddebug_s, stderr_s, stdnull_s; +val print_flo_precision_s; + val from_start_k, from_current_k, from_end_k; val real_time_k, name_k, fd_k; val format_s; @@ -2183,7 +2185,7 @@ val formatv(val stream_in, val fmtstr, struct args *al) } state = vf_init, saved_state = vf_init; int width = 0, precision = 0, precision_p = 0, digits = 0, lt = 0, neg = 0; enum align align = al_right; - int sign = 0, zeropad = 0; + int sign = 0, zeropad = 0, dfl_precision = 0; cnum value; cnum arg_ix = 0; @@ -2453,8 +2455,12 @@ val formatv(val stream_in, val fmtstr, struct args *al) } goto output_num; case FLNUM: - if (!precision_p) - precision = DBL_DIG; + if (!precision_p) { + if (!dfl_precision) + dfl_precision = c_num(cdr(lookup_var(nil, + print_flo_precision_s))); + precision = dfl_precision; + } if (precision > 500) uw_throwf(error_s, lit("excessive precision in format: ~s\n"), @@ -3270,6 +3276,10 @@ void stream_init(void) reg_var(stdnull_s = intern(lit("*stdnull*"), user_package), make_null_stream()); + reg_var(print_flo_precision_s = intern(lit("*print-flo-precision*"), + user_package), + num_fast(DBL_DIG)); + #if HAVE_ISATTY if (isatty(fileno(stdin)) == 1) stream_set_prop(std_input, real_time_k, t); -- cgit v1.2.3