mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Add config("fraction_space") to control spaces around printing fractions
Added config("tilde_space", boolean) to help/config, along with a few few minor text improvements. Updated cal/regress to test 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").
This commit is contained in:
39
CHANGES
39
CHANGES
@@ -31,19 +31,52 @@ The following are the changes from calc version 2.14.2.0 to date:
|
|||||||
|
|
||||||
; 1/3
|
; 1/3
|
||||||
~0.33333333333333333333
|
~0.33333333333333333333
|
||||||
|
; sqrt(7 + 5i,1e-100)
|
||||||
|
~2.79305614578749801863+~0.89507688693280053094i
|
||||||
|
|
||||||
With config("tilde_space", 1):
|
With config("tilde_space", 1):
|
||||||
|
|
||||||
; 1/3
|
; 1/3
|
||||||
~ 0.33333333333333333333
|
~ 0.33333333333333333333
|
||||||
|
; sqrt(7 + 5i,1e-100)
|
||||||
|
~ 2.79305614578749801863+~ 0.89507688693280053094i
|
||||||
|
|
||||||
To disable "tilde_space", use config("tilde_space", 0) on the
|
NOTE: Use of config("tilde_space", 1) can break printing and scanning
|
||||||
command line and/or use config("tilde_space", 0),; in your ~/.calcrc.
|
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 <GitHub use ljramalho> for this suggestion.
|
Thanks goes to <GitHub use ljramalho> for this suggestion.
|
||||||
|
|
||||||
Added config("tilde_space", boolean) to help/config, along with
|
Added config("tilde_space", boolean) to help/config, along with
|
||||||
a few few minor text improvements. Updated cal/regress to test
|
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:
|
The following are the changes from calc version 2.14.1.2 to date:
|
||||||
|
@@ -541,7 +541,14 @@ define test_config()
|
|||||||
vrfy(issimple(config("dupvar_warn")),
|
vrfy(issimple(config("dupvar_warn")),
|
||||||
'562: issimple(config("rdupvar_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()';
|
print '010: parsed test_config()';
|
||||||
|
|
||||||
@@ -3924,7 +3931,7 @@ define test_fileops()
|
|||||||
vrfy(!iserror(p=fopen("tmp4200","r")),
|
vrfy(!iserror(p=fopen("tmp4200","r")),
|
||||||
'4274: !iserror(p=fopen("tmp4200","r"))');
|
'4274: !iserror(p=fopen("tmp4200","r"))');
|
||||||
vrfy(!iserror(s=fgetline(p)), '4275: !iserror(s=fgetline(p))');
|
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(!iserror(s=fgetfile(p)), '4277: !iserror(s=fgetfile(p))');
|
||||||
vrfy(strcmp(s,"w\0a\0s\nhere\n") == 0,
|
vrfy(strcmp(s,"w\0a\0s\nhere\n") == 0,
|
||||||
'4278: 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",
|
vrfy(strprintf("%g", 385) == "3.8e2",
|
||||||
'4851: 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 */
|
/* restore config */
|
||||||
c = config("all", callcfg);
|
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()';
|
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(config("dupvar_warn",0), '8652: config("dupvar_warn",0)');
|
||||||
vrfy(u_glob == 6, '8653: u_glob == 6');
|
vrfy(u_glob == 6, '8653: u_glob == 6');
|
||||||
global u_glob = 555;
|
global u_glob = 555;
|
||||||
print '8654: declare u_glob';
|
print '8654: declare u_glob';
|
||||||
vrfy(u_glob == 555, '8655: u_glob == 555');
|
vrfy(u_glob == 555, '8655: u_glob == 555');
|
||||||
define func_8650(u_glob) { local u_glob; return u_glob; }
|
define func_8650(u_glob) { local u_glob; return u_glob; }
|
||||||
print '8656: u_glob as both local and parameter';
|
print '8656: u_glob as both local and parameter';
|
||||||
|
@@ -1223,7 +1223,13 @@ cprintfr(COMPLEX *c)
|
|||||||
zprintval(i->num, 0L, 0L);
|
zprintval(i->num, 0L, 0L);
|
||||||
math_chr('i');
|
math_chr('i');
|
||||||
if (qisfrac(i)) {
|
if (qisfrac(i)) {
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
math_chr(' ');
|
||||||
|
}
|
||||||
math_chr('/');
|
math_chr('/');
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
math_chr(' ');
|
||||||
|
}
|
||||||
zprintval(i->den, 0L, 0L);
|
zprintval(i->den, 0L, 0L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
config.c
21
config.c
@@ -132,6 +132,7 @@ NAMETYPE configs[] = {
|
|||||||
{"redecl_warn", CONFIG_REDECL_WARN},
|
{"redecl_warn", CONFIG_REDECL_WARN},
|
||||||
{"dupvar_warn", CONFIG_DUPVAR_WARN},
|
{"dupvar_warn", CONFIG_DUPVAR_WARN},
|
||||||
{"hz", CONFIG_HZ},
|
{"hz", CONFIG_HZ},
|
||||||
|
{"fraction_space", CONFIG_FRACTION_SPACE},
|
||||||
{NULL, 0}
|
{NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -199,6 +200,7 @@ CONFIG oldstd = { /* backward compatible standard configuration */
|
|||||||
BASEB, /* base for calculations */
|
BASEB, /* base for calculations */
|
||||||
TRUE, /* warn when redeclaring */
|
TRUE, /* warn when redeclaring */
|
||||||
TRUE, /* warn when variable names collide */
|
TRUE, /* warn when variable names collide */
|
||||||
|
FALSE, /* print spaces around / in fractions */
|
||||||
};
|
};
|
||||||
CONFIG newstd = { /* new non-backward compatible configuration */
|
CONFIG newstd = { /* new non-backward compatible configuration */
|
||||||
MODE_INITIAL, /* current output mode */
|
MODE_INITIAL, /* current output mode */
|
||||||
@@ -260,6 +262,7 @@ CONFIG newstd = { /* new non-backward compatible configuration */
|
|||||||
BASEB, /* base for calculations */
|
BASEB, /* base for calculations */
|
||||||
TRUE, /* warn when redeclaring */
|
TRUE, /* warn when redeclaring */
|
||||||
TRUE, /* warn when variable names collide */
|
TRUE, /* warn when variable names collide */
|
||||||
|
FALSE, /* print spaces around / in fractions */
|
||||||
};
|
};
|
||||||
CONFIG *conf = NULL; /* loaded in at startup - current configuration */
|
CONFIG *conf = NULL; /* loaded in at startup - current configuration */
|
||||||
|
|
||||||
@@ -1006,6 +1009,20 @@ setconfig(int type, VALUE *vp)
|
|||||||
not_reached();
|
not_reached();
|
||||||
break;
|
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:
|
default:
|
||||||
math_error("Setting illegal config parameter");
|
math_error("Setting illegal config parameter");
|
||||||
not_reached();
|
not_reached();
|
||||||
@@ -1405,6 +1422,10 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
|||||||
i = CALC_HZ;
|
i = CALC_HZ;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CONFIG_FRACTION_SPACE:
|
||||||
|
i = (cfg->fraction_space ? 1 : 0);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
math_error("Getting illegal CONFIG element");
|
math_error("Getting illegal CONFIG element");
|
||||||
not_reached();
|
not_reached();
|
||||||
|
2
config.h
2
config.h
@@ -95,6 +95,7 @@
|
|||||||
#define CONFIG_DUPVAR_WARN 45
|
#define CONFIG_DUPVAR_WARN 45
|
||||||
#define CONFIG_HZ 46
|
#define CONFIG_HZ 46
|
||||||
#define CONFIG_TILDE_SPACE 47
|
#define CONFIG_TILDE_SPACE 47
|
||||||
|
#define CONFIG_FRACTION_SPACE 48
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -167,6 +168,7 @@ struct config {
|
|||||||
int baseb; /* base for calculations */
|
int baseb; /* base for calculations */
|
||||||
BOOL redecl_warn; /* TRUE => warn of redeclaring variables */
|
BOOL redecl_warn; /* TRUE => warn of redeclaring variables */
|
||||||
BOOL dupvar_warn; /* TRUE => warn of var name collisions */
|
BOOL dupvar_warn; /* TRUE => warn of var name collisions */
|
||||||
|
BOOL fraction_space; /* TRUE => print spaces around / in fractions */
|
||||||
};
|
};
|
||||||
typedef struct config CONFIG;
|
typedef struct config CONFIG;
|
||||||
|
|
||||||
|
1
hash.c
1
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_int(type, value->v_config->baseb, state);
|
||||||
state = hash_bool(type, value->v_config->redecl_warn, 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->dupvar_warn, state);
|
||||||
|
state = hash_bool(type, value->v_config->fraction_space, state);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case V_HASH:
|
case V_HASH:
|
||||||
|
19
help/config
19
help/config
@@ -382,6 +382,9 @@ DESCRIPTION
|
|||||||
printed after leading tilde ('~'). See config("tilde") above.
|
printed after leading tilde ('~'). See config("tilde") above.
|
||||||
If config("tilde") is false, then config("tilde_space") has no effect.
|
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.
|
The initial "tilde_space" value is 0.
|
||||||
|
|
||||||
=-=
|
=-=
|
||||||
@@ -899,6 +902,21 @@ DESCRIPTION
|
|||||||
|
|
||||||
This config parameter is read-only and cannot be set.
|
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
|
EXAMPLE
|
||||||
; current_cfg = config("all");
|
; current_cfg = config("all");
|
||||||
; config("tilde", off),;
|
; config("tilde", off),;
|
||||||
@@ -961,6 +979,7 @@ EXAMPLE
|
|||||||
redecl_warn 1
|
redecl_warn 1
|
||||||
dupvar_warn 1
|
dupvar_warn 1
|
||||||
hz 100
|
hz 100
|
||||||
|
fraction_space 0
|
||||||
|
|
||||||
; display()
|
; display()
|
||||||
20
|
20
|
||||||
|
30
qio.c
30
qio.c
@@ -420,7 +420,13 @@ qprintfr(NUMBER *q, long width, BOOL force)
|
|||||||
{
|
{
|
||||||
zprintval(q->num, 0L, width);
|
zprintval(q->num, 0L, width);
|
||||||
if (force || qisfrac(q)) {
|
if (force || qisfrac(q)) {
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
PUTCHAR(' ');
|
||||||
|
}
|
||||||
PUTCHAR('/');
|
PUTCHAR('/');
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
PUTCHAR(' ');
|
||||||
|
}
|
||||||
zprintval(q->den, 0L, width);
|
zprintval(q->den, 0L, width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -454,7 +460,13 @@ qprintfx(NUMBER *q, long width)
|
|||||||
{
|
{
|
||||||
zprintx(q->num, width);
|
zprintx(q->num, width);
|
||||||
if (qisfrac(q)) {
|
if (qisfrac(q)) {
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
PUTCHAR(' ');
|
||||||
|
}
|
||||||
PUTCHAR('/');
|
PUTCHAR('/');
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
PUTCHAR(' ');
|
||||||
|
}
|
||||||
zprintx(q->den, 0L);
|
zprintx(q->den, 0L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -469,7 +481,13 @@ qprintfb(NUMBER *q, long width)
|
|||||||
{
|
{
|
||||||
zprintb(q->num, width);
|
zprintb(q->num, width);
|
||||||
if (qisfrac(q)) {
|
if (qisfrac(q)) {
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
PUTCHAR(' ');
|
||||||
|
}
|
||||||
PUTCHAR('/');
|
PUTCHAR('/');
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
PUTCHAR(' ');
|
||||||
|
}
|
||||||
zprintb(q->den, 0L);
|
zprintb(q->den, 0L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -484,7 +502,13 @@ qprintfo(NUMBER *q, long width)
|
|||||||
{
|
{
|
||||||
zprinto(q->num, width);
|
zprinto(q->num, width);
|
||||||
if (qisfrac(q)) {
|
if (qisfrac(q)) {
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
PUTCHAR(' ');
|
||||||
|
}
|
||||||
PUTCHAR('/');
|
PUTCHAR('/');
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
PUTCHAR(' ');
|
||||||
|
}
|
||||||
zprinto(q->den, 0L);
|
zprinto(q->den, 0L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -757,6 +781,12 @@ fitprint(NUMBER *q, long width)
|
|||||||
width1 = width - width2;
|
width1 = width - width2;
|
||||||
}
|
}
|
||||||
fitzprint(q->num, numdigits, width1);
|
fitzprint(q->num, numdigits, width1);
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
PUTCHAR(' ');
|
||||||
|
}
|
||||||
PUTCHAR('/');
|
PUTCHAR('/');
|
||||||
|
if (conf->fraction_space) {
|
||||||
|
PUTCHAR(' ');
|
||||||
|
}
|
||||||
fitzprint(q->den, dendigits, width2);
|
fitzprint(q->den, dendigits, width2);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user