diff --git a/CHANGES b/CHANGES index ab4cc27..4167dd0 100644 --- a/CHANGES +++ b/CHANGES @@ -31,19 +31,52 @@ The following are the changes from calc version 2.14.2.0 to date: ; 1/3 ~0.33333333333333333333 + ; sqrt(7 + 5i,1e-100) + ~2.79305614578749801863+~0.89507688693280053094i With config("tilde_space", 1): ; 1/3 ~ 0.33333333333333333333 + ; sqrt(7 + 5i,1e-100) + ~ 2.79305614578749801863+~ 0.89507688693280053094i - To disable "tilde_space", use config("tilde_space", 0) on the - command line and/or use config("tilde_space", 0),; in your ~/.calcrc. + NOTE: Use of config("tilde_space", 1) can break printing and scanning + of complex values via "%c". + + To enable "tilde_space", use config("tilde_space", 1) on the + command line and/or use config("tilde_space", 1),; in your ~/.calcrc. Thanks goes to for this suggestion. Added config("tilde_space", boolean) to help/config, along with a few few minor text improvements. Updated cal/regress to test - config("tilde_space") and to account for the new default. + config("tilde_space"). + + Added config("fraction_space", boolean). The "fraction_space" controls + whether or not a space (' ') is printed before and after fractions. + By default, config("fraction_space") is false. + + For example, with the default, config("fraction_space", 0): + + ; base(1/3), + ; 1/7 + 1/7 + + With config("fraction_space", 1): + + ; base(1/3), + ; 1/7 + 1 / 7 + + NOTE: Use of config("fraction_space", 1) can break printing and scanning + of fractional values via "%r". + + NOTE: Use of config("fraction_space", 1) can break printing and scanning + of complex values via "%c". + + Added config("fraction_space", boolean) to help/config, along with + a few few minor text improvements. Updated cal/regress to test + config("tilde_space"). The following are the changes from calc version 2.14.1.2 to date: diff --git a/cal/regress.cal b/cal/regress.cal index 9e1edb5..1013a42 100644 --- a/cal/regress.cal +++ b/cal/regress.cal @@ -541,7 +541,14 @@ define test_config() vrfy(issimple(config("dupvar_warn")), '562: issimple(config("rdupvar_warn"))'); - print '563: Ending test_config'; + + /* test new space modes */ + vrfy(config("tilde_space") == 0, + '563: config("tilde_space") == 0'); + vrfy(config("fraction_space") == 0, + '564: config("fraction_space") == 0'); + + print '565: Ending test_config'; } print '010: parsed test_config()'; @@ -3924,7 +3931,7 @@ define test_fileops() vrfy(!iserror(p=fopen("tmp4200","r")), '4274: !iserror(p=fopen("tmp4200","r"))'); vrfy(!iserror(s=fgetline(p)), '4275: !iserror(s=fgetline(p))'); - vrfy(strcmp(s,"chongo") == 0, '4276: strcmp(s,"chongo") == 0'); + vrfy(strcmp(s,"chongo") == 0, '4276: strcmp(s,"chongo") == 0'); vrfy(!iserror(s=fgetfile(p)), '4277: !iserror(s=fgetfile(p))'); vrfy(strcmp(s,"w\0a\0s\nhere\n") == 0, '4278: strcmp(s,"w\0a\0s\nhere\n") == 0'); @@ -4399,11 +4406,16 @@ define test_strprintf() vrfy(strprintf("%g", 385) == "3.8e2", '4851: strprintf("%g", 385) == "3.8e2"'); + c = config("fraction_space", 1); + print '4852: c = config("fraction_space", 1)'; + vrfy(strprintf("%r = %f", 27/29, 27/29) == "27 / 29 = .93", + '4853: strprintf("%r = %f", 27/29, 27/29) == "27 / 29 = .93"'); + /* restore config */ c = config("all", callcfg); - print '4852: c = config("all", callcfg)'; + print '4854: c = config("all", callcfg)'; - print '4853: Ending test_strprintf'; + print '4855: Ending test_strprintf'; } print '088: parsed test_fileop()'; @@ -8159,7 +8171,7 @@ vrfy(config("redecl_warn",0), '8651: config("redecl_warn",0)'); vrfy(config("dupvar_warn",0), '8652: config("dupvar_warn",0)'); vrfy(u_glob == 6, '8653: u_glob == 6'); global u_glob = 555; -print '8654: declare u_glob'; +print '8654: declare u_glob'; vrfy(u_glob == 555, '8655: u_glob == 555'); define func_8650(u_glob) { local u_glob; return u_glob; } print '8656: u_glob as both local and parameter'; diff --git a/comfunc.c b/comfunc.c index 4a5770e..d8856c5 100644 --- a/comfunc.c +++ b/comfunc.c @@ -1223,7 +1223,13 @@ cprintfr(COMPLEX *c) zprintval(i->num, 0L, 0L); math_chr('i'); if (qisfrac(i)) { + if (conf->fraction_space) { + math_chr(' '); + } math_chr('/'); + if (conf->fraction_space) { + math_chr(' '); + } zprintval(i->den, 0L, 0L); } } diff --git a/config.c b/config.c index 573ebf9..2bfffe8 100644 --- a/config.c +++ b/config.c @@ -132,6 +132,7 @@ NAMETYPE configs[] = { {"redecl_warn", CONFIG_REDECL_WARN}, {"dupvar_warn", CONFIG_DUPVAR_WARN}, {"hz", CONFIG_HZ}, + {"fraction_space", CONFIG_FRACTION_SPACE}, {NULL, 0} }; @@ -199,6 +200,7 @@ CONFIG oldstd = { /* backward compatible standard configuration */ BASEB, /* base for calculations */ TRUE, /* warn when redeclaring */ TRUE, /* warn when variable names collide */ + FALSE, /* print spaces around / in fractions */ }; CONFIG newstd = { /* new non-backward compatible configuration */ MODE_INITIAL, /* current output mode */ @@ -260,6 +262,7 @@ CONFIG newstd = { /* new non-backward compatible configuration */ BASEB, /* base for calculations */ TRUE, /* warn when redeclaring */ TRUE, /* warn when variable names collide */ + FALSE, /* print spaces around / in fractions */ }; CONFIG *conf = NULL; /* loaded in at startup - current configuration */ @@ -1006,6 +1009,20 @@ setconfig(int type, VALUE *vp) not_reached(); break; + case CONFIG_FRACTION_SPACE: + if (vp->v_type == V_NUM) { + q = vp->v_num; + conf->fraction_space = !qiszero(q); + } else if (vp->v_type == V_STR) { + temp = lookup_long(truth, vp->v_str->s_str); + if (temp < 0) { + math_error("Illegal truth value for fraction_space"); + not_reached(); + } + conf->fraction_space = (int)temp; + } + break; + default: math_error("Setting illegal config parameter"); not_reached(); @@ -1405,6 +1422,10 @@ config_value(CONFIG *cfg, int type, VALUE *vp) i = CALC_HZ; break; + case CONFIG_FRACTION_SPACE: + i = (cfg->fraction_space ? 1 : 0); + break; + default: math_error("Getting illegal CONFIG element"); not_reached(); diff --git a/config.h b/config.h index 3e8b050..33ec910 100644 --- a/config.h +++ b/config.h @@ -95,6 +95,7 @@ #define CONFIG_DUPVAR_WARN 45 #define CONFIG_HZ 46 #define CONFIG_TILDE_SPACE 47 +#define CONFIG_FRACTION_SPACE 48 /* @@ -167,6 +168,7 @@ struct config { int baseb; /* base for calculations */ BOOL redecl_warn; /* TRUE => warn of redeclaring variables */ BOOL dupvar_warn; /* TRUE => warn of var name collisions */ + BOOL fraction_space; /* TRUE => print spaces around / in fractions */ }; typedef struct config CONFIG; diff --git a/hash.c b/hash.c index ce35c88..4969367 100644 --- a/hash.c +++ b/hash.c @@ -1002,6 +1002,7 @@ hash_value(int type, void *v, HASH *state) state = hash_int(type, value->v_config->baseb, state); state = hash_bool(type, value->v_config->redecl_warn, state); state = hash_bool(type, value->v_config->dupvar_warn, state); + state = hash_bool(type, value->v_config->fraction_space, state); break; case V_HASH: diff --git a/help/config b/help/config index b38660f..4f6ebb5 100644 --- a/help/config +++ b/help/config @@ -382,6 +382,9 @@ DESCRIPTION printed after leading tilde ('~'). See config("tilde") above. If config("tilde") is false, then config("tilde_space") has no effect. + NOTE: Use of config("tilde_space", 1) can break printing and scanning + of complex values via "%c". + The initial "tilde_space" value is 0. =-= @@ -899,6 +902,21 @@ DESCRIPTION This config parameter is read-only and cannot be set. + =-= + + config("fraction_space", boolean) + + The "fraction_space" controls whether or not a space (' ') is + printed both before and after '/' when printing a fraction. + + NOTE: Use of config("fraction_space", 1) can break printing and scanning + of fractional values via "%r". + + NOTE: Use of config("fraction_space", 1) can break printing and scanning + of complex values via "%c". + + The initial "fraction_space" value is 0. + EXAMPLE ; current_cfg = config("all"); ; config("tilde", off),; @@ -961,6 +979,7 @@ EXAMPLE redecl_warn 1 dupvar_warn 1 hz 100 + fraction_space 0 ; display() 20 diff --git a/qio.c b/qio.c index fb41d31..1851a80 100644 --- a/qio.c +++ b/qio.c @@ -420,7 +420,13 @@ qprintfr(NUMBER *q, long width, BOOL force) { zprintval(q->num, 0L, width); if (force || qisfrac(q)) { + if (conf->fraction_space) { + PUTCHAR(' '); + } PUTCHAR('/'); + if (conf->fraction_space) { + PUTCHAR(' '); + } zprintval(q->den, 0L, width); } } @@ -454,7 +460,13 @@ qprintfx(NUMBER *q, long width) { zprintx(q->num, width); if (qisfrac(q)) { + if (conf->fraction_space) { + PUTCHAR(' '); + } PUTCHAR('/'); + if (conf->fraction_space) { + PUTCHAR(' '); + } zprintx(q->den, 0L); } } @@ -469,7 +481,13 @@ qprintfb(NUMBER *q, long width) { zprintb(q->num, width); if (qisfrac(q)) { + if (conf->fraction_space) { + PUTCHAR(' '); + } PUTCHAR('/'); + if (conf->fraction_space) { + PUTCHAR(' '); + } zprintb(q->den, 0L); } } @@ -484,7 +502,13 @@ qprintfo(NUMBER *q, long width) { zprinto(q->num, width); if (qisfrac(q)) { + if (conf->fraction_space) { + PUTCHAR(' '); + } PUTCHAR('/'); + if (conf->fraction_space) { + PUTCHAR(' '); + } zprinto(q->den, 0L); } } @@ -757,6 +781,12 @@ fitprint(NUMBER *q, long width) width1 = width - width2; } fitzprint(q->num, numdigits, width1); + if (conf->fraction_space) { + PUTCHAR(' '); + } PUTCHAR('/'); + if (conf->fraction_space) { + PUTCHAR(' '); + } fitzprint(q->den, dendigits, width2); }