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:
Landon Curt Noll
2022-12-04 00:53:15 -08:00
parent 348f3ed427
commit f4f19f21dc
5 changed files with 101 additions and 34 deletions

36
CHANGES
View File

@@ -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 a few few minor text improvements. Updated cal/regress to test
config("tilde_space"). 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 Added config("fraction_space", boolean). The "fraction_space" controls
whether or not a space (' ') is printed before and after fractions. whether or not a space (' ') is printed before and after fractions.
By default, config("fraction_space") is false. 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 a few few minor text improvements. Updated cal/regress to test
config("tilde_space"). 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 Clarify in the calc man page, the relationship between -q and
calc start scripts such as the ~/.calcrc file. calc start scripts such as the ~/.calcrc file.

View File

@@ -547,8 +547,10 @@ define test_config()
'563: config("tilde_space") == 0'); '563: config("tilde_space") == 0');
vrfy(config("fraction_space") == 0, vrfy(config("fraction_space") == 0,
'564: 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()'; print '010: parsed test_config()';

View File

@@ -1191,12 +1191,18 @@ comprint(COMPLEX *c)
qtmp = c->imag[0]; qtmp = c->imag[0];
if (qiszero(&qtmp)) if (qiszero(&qtmp))
return; return;
if (conf->complex_space) {
math_chr(' ');
}
if (!qiszero(c->real) && !qisneg(&qtmp)) if (!qiszero(c->real) && !qisneg(&qtmp))
math_chr('+'); math_chr('+');
if (qisneg(&qtmp)) { if (qisneg(&qtmp)) {
math_chr('-'); math_chr('-');
qtmp.num.sign = 0; qtmp.num.sign = 0;
} }
if (conf->complex_space) {
math_chr(' ');
}
qprintnum(&qtmp, MODE_DEFAULT, conf->outdigits); qprintnum(&qtmp, MODE_DEFAULT, conf->outdigits);
math_chr('i'); math_chr('i');
} }

View File

@@ -95,6 +95,7 @@ NAMETYPE configs[] = {
{"tilde", CONFIG_TILDE}, {"tilde", CONFIG_TILDE},
{"tilde_space", CONFIG_TILDE_SPACE}, {"tilde_space", CONFIG_TILDE_SPACE},
{"fraction_space", CONFIG_FRACTION_SPACE}, {"fraction_space", CONFIG_FRACTION_SPACE},
{"complex_space", CONFIG_COMPLEX_SPACE},
{"tab", CONFIG_TAB}, {"tab", CONFIG_TAB},
{"quomod", CONFIG_QUOMOD}, {"quomod", CONFIG_QUOMOD},
{"quo", CONFIG_QUO}, {"quo", CONFIG_QUO},
@@ -152,9 +153,11 @@ CONFIG oldstd = { /* backward compatible standard configuration */
SQ_ALG2, /* size of number to use square alg 2 */ SQ_ALG2, /* size of number to use square alg 2 */
POW_ALG2, /* size of modulus to use REDC for powers */ POW_ALG2, /* size of modulus to use REDC for powers */
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */ REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
TRUE, /* OK to print a tilde on approximations */ TRUE, /* TRUE ==> print a tilde on approximations */
FALSE, /* OK to print a space after tilde on approximations */ FALSE, /* TRUE ==> print a space after tilde on approximations */
TRUE, /* OK to print tab before numeric values */ 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 */ 0, /* quomod() default rounding mode */
2, /* quotient // default rounding mode */ 2, /* quotient // default rounding mode */
0, /* mod % default rounding mode */ 0, /* mod % default rounding mode */
@@ -164,8 +167,8 @@ CONFIG oldstd = { /* backward compatible standard configuration */
8, /* cfsim() default rounding mode */ 8, /* cfsim() default rounding mode */
2, /* output default rounding mode */ 2, /* output default rounding mode */
24, /* round()/bround() default rounding mode */ 24, /* round()/bround() default rounding mode */
FALSE, /* OK to print leading 0 before decimal pt */ FALSE, /* TRUE ==> print leading 0 before decimal pt */
0, /* OK to print trailing 0's */ 0, /* TRUE ==> print trailing 0's */
MAXSCANCOUNT, /* max scan errors before abort */ MAXSCANCOUNT, /* max scan errors before abort */
PROMPT1, /* normal prompt */ PROMPT1, /* normal prompt */
PROMPT2, /* prompt when inside multi-line input */ PROMPT2, /* prompt when inside multi-line input */
@@ -176,31 +179,30 @@ CONFIG oldstd = { /* backward compatible standard configuration */
0, /* internal calc debug level */ 0, /* internal calc debug level */
3, /* calc resource file debug level */ 3, /* calc resource file debug level */
0, /* user defined 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 */ CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
NULL, /* our name */ NULL, /* our name */
NULL, /* basename of our name */ NULL, /* basename of our name */
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
TRUE, /* running under windows */ TRUE, /* TRUE ==> running under windows */
#else #else
FALSE, /* not using windows */ FALSE, /* FALSE ==> not using windows */
#endif #endif
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
TRUE, /* compiled under cygwin */ TRUE, /* TRUE ==> compiled under cygwin */
#else #else
FALSE, /* not compiled with cygwin */ FALSE, /* FALSE ==> not compiled with cygwin */
#endif #endif
#if defined(CUSTOM) #if defined(CUSTOM)
TRUE, /* compiled with -DCUSTOM */ TRUE, /* TRUE ==> compiled with -DCUSTOM */
#else #else
FALSE, /* compiled without -DCUSTOM */ FALSE, /* FALSE ==> compiled without -DCUSTOM */
#endif #endif
&allow_custom, /* *TRUE=> custom functions are enabled */ &allow_custom, /* *TRUE=> custom functions are enabled */
NULL, /* version */ NULL, /* version */
BASEB, /* base for calculations */ BASEB, /* base for calculations */
TRUE, /* warn when redeclaring */ TRUE, /* TRUE ==> warn when redeclaring */
TRUE, /* warn when variable names collide */ TRUE, /* 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 */
@@ -214,9 +216,11 @@ CONFIG newstd = { /* new non-backward compatible configuration */
SQ_ALG2, /* size of number to use square alg 2 */ SQ_ALG2, /* size of number to use square alg 2 */
POW_ALG2, /* size of modulus to use REDC for powers */ POW_ALG2, /* size of modulus to use REDC for powers */
REDC_ALG2, /* size of modulus to use REDC algorithm 2 */ REDC_ALG2, /* size of modulus to use REDC algorithm 2 */
TRUE, /* OK to print a tilde on approximations */ TRUE, /* TRUE ==> print a tilde on approximations */
FALSE, /* OK to print a space after tilde on approximations */ FALSE, /* TRUE ==> print spaces around / in fractions */
TRUE, /* OK to print tab before numeric values */ 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 */ 0, /* quomod() default rounding mode */
2, /* quotient // default rounding mode */ 2, /* quotient // default rounding mode */
0, /* mod % default rounding mode */ 0, /* mod % default rounding mode */
@@ -226,8 +230,8 @@ CONFIG newstd = { /* new non-backward compatible configuration */
8, /* cfsim() default rounding mode */ 8, /* cfsim() default rounding mode */
24, /* output default rounding mode */ 24, /* output default rounding mode */
24, /* round()/bround() default rounding mode */ 24, /* round()/bround() default rounding mode */
TRUE, /* OK to print leading 0 before decimal pt */ TRUE, /* TRUE ==> print leading 0 before decimal pt */
0, /* OK to print trailing 0's */ 0, /* TRUE ==> print trailing 0's */
MAXSCANCOUNT, /* max scan errors before abort */ MAXSCANCOUNT, /* max scan errors before abort */
"; ", /* normal prompt */ "; ", /* normal prompt */
";; ", /* prompt when inside multi-line input */ ";; ", /* prompt when inside multi-line input */
@@ -238,31 +242,30 @@ CONFIG newstd = { /* new non-backward compatible configuration */
0, /* internal calc debug level */ 0, /* internal calc debug level */
3, /* calc resource file debug level */ 3, /* calc resource file debug level */
0, /* user defined 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 */ CTRL_D_VIRGIN_EOF, /* ^D only exits on virgin lines */
NULL, /* our name */ NULL, /* our name */
NULL, /* basename of our name */ NULL, /* basename of our name */
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
TRUE, /* running under windows */ TRUE, /* TRUE ==> running under windows */
#else #else
FALSE, /* not using windows */ FALSE, /* FALSE ==> not using windows */
#endif #endif
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
TRUE, /* compiled under cygwin */ TRUE, /* TRUE ==> compiled under cygwin */
#else #else
FALSE, /* not compiled with cygwin */ FALSE, /* FALSE ==> not compiled with cygwin */
#endif #endif
#if defined(CUSTOM) #if defined(CUSTOM)
TRUE, /* compiled with -DCUSTOM */ TRUE, /* TRUE ==> compiled with -DCUSTOM */
#else #else
FALSE, /* compiled without -DCUSTOM */ FALSE, /* FALSE ==> compiled without -DCUSTOM */
#endif #endif
&allow_custom, /* *TRUE=> custom functions are enabled */ &allow_custom, /* *TRUE ==> custom functions are enabled */
NULL, /* version */ NULL, /* version */
BASEB, /* base for calculations */ BASEB, /* base for calculations */
TRUE, /* warn when redeclaring */ TRUE, /* TRUE ==> warn when redeclaring */
TRUE, /* warn when variable names collide */ TRUE, /* 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 */
@@ -658,6 +661,20 @@ setconfig(int type, VALUE *vp)
} }
break; 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: case CONFIG_TAB:
if (vp->v_type == V_NUM) { if (vp->v_type == V_NUM) {
q = vp->v_num; q = vp->v_num;
@@ -1247,6 +1264,10 @@ config_value(CONFIG *cfg, int type, VALUE *vp)
i = (cfg->fraction_space ? 1 : 0); i = (cfg->fraction_space ? 1 : 0);
break; break;
case CONFIG_COMPLEX_SPACE:
i = (cfg->complex_space ? 1 : 0);
break;
case CONFIG_TAB: case CONFIG_TAB:
i = (cfg->tab_ok ? 1 : 0); i = (cfg->tab_ok ? 1 : 0);
break; break;

View File

@@ -96,6 +96,7 @@
#define CONFIG_HZ 46 #define CONFIG_HZ 46
#define CONFIG_TILDE_SPACE 47 #define CONFIG_TILDE_SPACE 47
#define CONFIG_FRACTION_SPACE 48 #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 */ LEN redc2; /* size of modulus to use REDC algorithm 2 */
BOOL tilde_ok; /* OK to print a tilde on approximations */ BOOL tilde_ok; /* OK to print a tilde on approximations */
BOOL tilde_space; /* print space after 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 */ BOOL tab_ok; /* OK to print tab before numeric values */
LEN quomod; /* quomod() default rounding mode */ LEN quomod; /* quomod() default rounding mode */
LEN quo; /* quotient // default rounding mode */ LEN quo; /* quotient // default rounding mode */
@@ -168,7 +171,6 @@ 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;