mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Add config("complex_space") to control spaces around + or - in complex values
Added config("fraction_space", boolean) to help/config, along with a few few minor text improvements. Updated cal/regress to test config("tilde_space"). Added config("complex_space", boolean). The "complex_space" controls whether or not a space (' ') is printed before and after the + or - in complex values. By default, config("complex_space") is false. For example, with the default, config("complex_space", 0): ; asin(2) 1.57079632679489661923-1.31695789692481670863i With config("complex_space", 1): ; asin(2) 1.57079632679489661923 - 1.31695789692481670863i NOTE: Use of config("complex_space", 1) can break printing and scanning of fractional values via "%r". NOTE: Use of config("complex_space", 1) can break printing and scanning of complex values via "%c". Added config("complex_space", boolean) to help/config, along with a few few minor text improvements. Updated cal/regress to test config("complex_space").
This commit is contained in:
36
CHANGES
36
CHANGES
@@ -52,6 +52,16 @@ The following are the changes from calc version 2.14.2.0 to date:
|
||||
a few few minor text improvements. Updated cal/regress to test
|
||||
config("tilde_space").
|
||||
|
||||
For example, with the default, config("tilde_space", 0):
|
||||
|
||||
; pi(1e-50)
|
||||
~3.14159265358979323846
|
||||
|
||||
With config("tilde_space", 1):
|
||||
|
||||
; pi(1e-50)
|
||||
~ 3.14159265358979323846
|
||||
|
||||
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.
|
||||
@@ -78,6 +88,32 @@ The following are the changes from calc version 2.14.2.0 to date:
|
||||
a few few minor text improvements. Updated cal/regress to test
|
||||
config("tilde_space").
|
||||
|
||||
Added config("complex_space", boolean). The "complex_space" controls
|
||||
whether or not a space (' ') is printed before and after the + or -
|
||||
in complex values.
|
||||
|
||||
By default, config("complex_space") is false.
|
||||
|
||||
For example, with the default, config("complex_space", 0):
|
||||
|
||||
; asin(2)
|
||||
1.57079632679489661923-1.31695789692481670863i
|
||||
|
||||
With config("complex_space", 1):
|
||||
|
||||
; asin(2)
|
||||
1.57079632679489661923 - 1.31695789692481670863i
|
||||
|
||||
NOTE: Use of config("complex_space", 1) can break printing and scanning
|
||||
of fractional values via "%r".
|
||||
|
||||
NOTE: Use of config("complex_space", 1) can break printing and scanning
|
||||
of complex values via "%c".
|
||||
|
||||
Added config("complex_space", boolean) to help/config, along with
|
||||
a few few minor text improvements. Updated cal/regress to test
|
||||
config("complex_space").
|
||||
|
||||
Clarify in the calc man page, the relationship between -q and
|
||||
calc start scripts such as the ~/.calcrc file.
|
||||
|
||||
|
@@ -547,8 +547,10 @@ define test_config()
|
||||
'563: config("tilde_space") == 0');
|
||||
vrfy(config("fraction_space") == 0,
|
||||
'564: config("fraction_space") == 0');
|
||||
vrfy(config("complex_space") == 0,
|
||||
'565: config("complex_space") == 0');
|
||||
|
||||
print '565: Ending test_config';
|
||||
print '566: Ending test_config';
|
||||
}
|
||||
print '010: parsed test_config()';
|
||||
|
||||
|
@@ -1191,12 +1191,18 @@ comprint(COMPLEX *c)
|
||||
qtmp = c->imag[0];
|
||||
if (qiszero(&qtmp))
|
||||
return;
|
||||
if (conf->complex_space) {
|
||||
math_chr(' ');
|
||||
}
|
||||
if (!qiszero(c->real) && !qisneg(&qtmp))
|
||||
math_chr('+');
|
||||
if (qisneg(&qtmp)) {
|
||||
math_chr('-');
|
||||
qtmp.num.sign = 0;
|
||||
}
|
||||
if (conf->complex_space) {
|
||||
math_chr(' ');
|
||||
}
|
||||
qprintnum(&qtmp, MODE_DEFAULT, conf->outdigits);
|
||||
math_chr('i');
|
||||
}
|
||||
|
83
config.c
83
config.c
@@ -95,6 +95,7 @@ NAMETYPE configs[] = {
|
||||
{"tilde", CONFIG_TILDE},
|
||||
{"tilde_space", CONFIG_TILDE_SPACE},
|
||||
{"fraction_space", CONFIG_FRACTION_SPACE},
|
||||
{"complex_space", CONFIG_COMPLEX_SPACE},
|
||||
{"tab", CONFIG_TAB},
|
||||
{"quomod", CONFIG_QUOMOD},
|
||||
{"quo", CONFIG_QUO},
|
||||
@@ -152,9 +153,11 @@ CONFIG oldstd = { /* backward compatible standard configuration */
|
||||
SQ_ALG2, /* size of number to use square alg 2 */
|
||||
POW_ALG2, /* size of modulus to use REDC for powers */
|
||||
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
|
||||
TRUE, /* OK to print a tilde on approximations */
|
||||
FALSE, /* OK to print a space after tilde on approximations */
|
||||
TRUE, /* OK to print tab before numeric values */
|
||||
TRUE, /* TRUE ==> print a tilde on approximations */
|
||||
FALSE, /* TRUE ==> print a space after tilde on approximations */
|
||||
FALSE, /* TRUE ==> print spaces around / in fractions */
|
||||
FALSE, /* TRUE ==> print spaces around + or - in complex values */
|
||||
TRUE, /* TRUE ==> print tab before numeric values */
|
||||
0, /* quomod() default rounding mode */
|
||||
2, /* quotient // default rounding mode */
|
||||
0, /* mod % default rounding mode */
|
||||
@@ -164,8 +167,8 @@ CONFIG oldstd = { /* backward compatible standard configuration */
|
||||
8, /* cfsim() default rounding mode */
|
||||
2, /* output default rounding mode */
|
||||
24, /* round()/bround() default rounding mode */
|
||||
FALSE, /* OK to print leading 0 before decimal pt */
|
||||
0, /* OK to print trailing 0's */
|
||||
FALSE, /* TRUE ==> print leading 0 before decimal pt */
|
||||
0, /* TRUE ==> print trailing 0's */
|
||||
MAXSCANCOUNT, /* max scan errors before abort */
|
||||
PROMPT1, /* normal prompt */
|
||||
PROMPT2, /* prompt when inside multi-line input */
|
||||
@@ -176,31 +179,30 @@ CONFIG oldstd = { /* backward compatible standard configuration */
|
||||
0, /* internal calc debug level */
|
||||
3, /* calc resource file debug level */
|
||||
0, /* user defined debug level */
|
||||
FALSE, /* print Quit or abort executed messages */
|
||||
FALSE, /* TRUE ==> print Quit or abort executed messages */
|
||||
CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
|
||||
NULL, /* our name */
|
||||
NULL, /* basename of our name */
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
TRUE, /* running under windows */
|
||||
TRUE, /* TRUE ==> running under windows */
|
||||
#else
|
||||
FALSE, /* not using windows */
|
||||
FALSE, /* FALSE ==> not using windows */
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
TRUE, /* compiled under cygwin */
|
||||
TRUE, /* TRUE ==> compiled under cygwin */
|
||||
#else
|
||||
FALSE, /* not compiled with cygwin */
|
||||
FALSE, /* FALSE ==> not compiled with cygwin */
|
||||
#endif
|
||||
#if defined(CUSTOM)
|
||||
TRUE, /* compiled with -DCUSTOM */
|
||||
TRUE, /* TRUE ==> compiled with -DCUSTOM */
|
||||
#else
|
||||
FALSE, /* compiled without -DCUSTOM */
|
||||
FALSE, /* FALSE ==> compiled without -DCUSTOM */
|
||||
#endif
|
||||
&allow_custom, /* *TRUE=> custom functions are enabled */
|
||||
NULL, /* version */
|
||||
BASEB, /* base for calculations */
|
||||
TRUE, /* warn when redeclaring */
|
||||
TRUE, /* warn when variable names collide */
|
||||
FALSE, /* print spaces around / in fractions */
|
||||
TRUE, /* TRUE ==> warn when redeclaring */
|
||||
TRUE, /* TRUE ==> warn when variable names collide */
|
||||
};
|
||||
CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
MODE_INITIAL, /* current output mode */
|
||||
@@ -214,9 +216,11 @@ CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
SQ_ALG2, /* size of number to use square alg 2 */
|
||||
POW_ALG2, /* size of modulus to use REDC for powers */
|
||||
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
|
||||
TRUE, /* OK to print a tilde on approximations */
|
||||
FALSE, /* OK to print a space after tilde on approximations */
|
||||
TRUE, /* OK to print tab before numeric values */
|
||||
TRUE, /* TRUE ==> print a tilde on approximations */
|
||||
FALSE, /* TRUE ==> print spaces around / in fractions */
|
||||
FALSE, /* TRUE ==> print a space after tilde on approximations */
|
||||
FALSE, /* TRUE ==> print spaces around + or - in complex values */
|
||||
TRUE, /* TRUE ==> print tab before numeric values */
|
||||
0, /* quomod() default rounding mode */
|
||||
2, /* quotient // default rounding mode */
|
||||
0, /* mod % default rounding mode */
|
||||
@@ -226,8 +230,8 @@ CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
8, /* cfsim() default rounding mode */
|
||||
24, /* output default rounding mode */
|
||||
24, /* round()/bround() default rounding mode */
|
||||
TRUE, /* OK to print leading 0 before decimal pt */
|
||||
0, /* OK to print trailing 0's */
|
||||
TRUE, /* TRUE ==> print leading 0 before decimal pt */
|
||||
0, /* TRUE ==> print trailing 0's */
|
||||
MAXSCANCOUNT, /* max scan errors before abort */
|
||||
"; ", /* normal prompt */
|
||||
";; ", /* prompt when inside multi-line input */
|
||||
@@ -238,31 +242,30 @@ CONFIG newstd = { /* new non-backward compatible configuration */
|
||||
0, /* internal calc debug level */
|
||||
3, /* calc resource file debug level */
|
||||
0, /* user defined debug level */
|
||||
FALSE, /* print Quit or abort executed messages */
|
||||
FALSE, /* TRUE ==> print Quit or abort executed messages */
|
||||
CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
|
||||
NULL, /* our name */
|
||||
NULL, /* basename of our name */
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
TRUE, /* running under windows */
|
||||
TRUE, /* TRUE ==> running under windows */
|
||||
#else
|
||||
FALSE, /* not using windows */
|
||||
FALSE, /* FALSE ==> not using windows */
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
TRUE, /* compiled under cygwin */
|
||||
TRUE, /* TRUE ==> compiled under cygwin */
|
||||
#else
|
||||
FALSE, /* not compiled with cygwin */
|
||||
FALSE, /* FALSE ==> not compiled with cygwin */
|
||||
#endif
|
||||
#if defined(CUSTOM)
|
||||
TRUE, /* compiled with -DCUSTOM */
|
||||
TRUE, /* TRUE ==> compiled with -DCUSTOM */
|
||||
#else
|
||||
FALSE, /* compiled without -DCUSTOM */
|
||||
FALSE, /* FALSE ==> compiled without -DCUSTOM */
|
||||
#endif
|
||||
&allow_custom, /* *TRUE=> custom functions are enabled */
|
||||
&allow_custom, /* *TRUE ==> custom functions are enabled */
|
||||
NULL, /* version */
|
||||
BASEB, /* base for calculations */
|
||||
TRUE, /* warn when redeclaring */
|
||||
TRUE, /* warn when variable names collide */
|
||||
FALSE, /* print spaces around / in fractions */
|
||||
TRUE, /* TRUE ==> warn when redeclaring */
|
||||
TRUE, /* TRUE ==> warn when variable names collide */
|
||||
};
|
||||
CONFIG *conf = NULL; /* loaded in at startup - current configuration */
|
||||
|
||||
@@ -658,6 +661,20 @@ setconfig(int type, VALUE *vp)
|
||||
}
|
||||
break;
|
||||
|
||||
case CONFIG_COMPLEX_SPACE:
|
||||
if (vp->v_type == V_NUM) {
|
||||
q = vp->v_num;
|
||||
conf->complex_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 complex_space");
|
||||
not_reached();
|
||||
}
|
||||
conf->complex_space = (int)temp;
|
||||
}
|
||||
break;
|
||||
|
||||
case CONFIG_TAB:
|
||||
if (vp->v_type == V_NUM) {
|
||||
q = vp->v_num;
|
||||
@@ -1247,6 +1264,10 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
|
||||
i = (cfg->fraction_space ? 1 : 0);
|
||||
break;
|
||||
|
||||
case CONFIG_COMPLEX_SPACE:
|
||||
i = (cfg->complex_space ? 1 : 0);
|
||||
break;
|
||||
|
||||
case CONFIG_TAB:
|
||||
i = (cfg->tab_ok ? 1 : 0);
|
||||
break;
|
||||
|
4
config.h
4
config.h
@@ -96,6 +96,7 @@
|
||||
#define CONFIG_HZ 46
|
||||
#define CONFIG_TILDE_SPACE 47
|
||||
#define CONFIG_FRACTION_SPACE 48
|
||||
#define CONFIG_COMPLEX_SPACE 49
|
||||
|
||||
|
||||
/*
|
||||
@@ -134,6 +135,8 @@ struct config {
|
||||
LEN redc2; /* size of modulus to use REDC algorithm 2 */
|
||||
BOOL tilde_ok; /* OK to print a tilde on approximations */
|
||||
BOOL tilde_space; /* print space after tilde on approximations */
|
||||
BOOL fraction_space; /* TRUE => print spaces around / in fractions */
|
||||
BOOL complex_space; /* TRUE => print spaces around + or - in complex values */
|
||||
BOOL tab_ok; /* OK to print tab before numeric values */
|
||||
LEN quomod; /* quomod() default rounding mode */
|
||||
LEN quo; /* quotient // default rounding mode */
|
||||
@@ -168,7 +171,6 @@ 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;
|
||||
|
||||
|
Reference in New Issue
Block a user