change error printing from errnum to errsym

When printing an error, calc used to print the errnum (error number):

    ; 1/0
	    Error 10001

Calc now prints the errsym (errsym):

    ; 1/0
	    Error E_DIVBYZERO

Added errsym E_LN_3 for ln(0).
Added errsym E_LOG_5 for log(0).
Added errsym E_LOG2_4 for log2(0).
Added errsym E_LOGN_6 for logn(0,base).
This commit is contained in:
Landon Curt Noll
2023-10-03 22:12:14 -07:00
parent db582d6e34
commit 42129a3672
22 changed files with 113 additions and 44 deletions

15
CHANGES
View File

@@ -419,6 +419,21 @@ The following are the changes from calc version 2.14.3.4 to 2.14.3.5:
config("triground")
When printing an error, calc used to print the errnum (error number):
; 1/0
Error 10001
Calc now prints the errsym (errsym):
; 1/0
Error E_DIVBYZERO
Added errsym E_LN_3 for ln(0).
Added errsym E_LOG_5 for log(0).
Added errsym E_LOG2_4 for log2(0).
Added errsym E_LOGN_6 for logn(0,base).
The following are the changes from calc version 2.14.3.0 to 2.14.3.4:

View File

@@ -755,6 +755,10 @@ CONST struct errtbl error_table[] =
{ 10603, "E_CIS_1", "Non-real epsilon for cis" },
{ 10604, "E_CIS_2", "Bad first argument for cis" },
{ 10605, "E_CIS_3", "Too-large re(argument) for cis" },
{ 10606, "E_LN_3", "Cannot calculate ln of 0" },
{ 10607, "E_LOG_5", "Cannot calculate log of 0" },
{ 10608, "E_LOG2_4", "Cannot calculate log base 2 of 0" },
{ 10609, "E_LOGN_6", "Cannot calculate log base n of 0" },
/* IMPORTANT NOTE: add new entries above here and be sure their errnum numeric value is consecutive! */
/* The next NULL entry must be last */

38
func.c
View File

@@ -2232,8 +2232,10 @@ f_ln(int count, VALUE **vals)
*/
switch (vals[0]->v_type) {
case V_NUM:
if (!qisneg(vals[0]->v_num) &&
!qiszero(vals[0]->v_num)) {
if (qiszero(vals[0]->v_num)) {
return error_value(E_LN_3);
}
if (!qisneg(vals[0]->v_num)) {
result.v_num = qln(vals[0]->v_num, err);
result.v_type = V_NUM;
return result;
@@ -2244,6 +2246,9 @@ f_ln(int count, VALUE **vals)
c = c_ln(&ctmp, err);
break;
case V_COM:
if (ciszero(vals[0]->v_com)) {
return error_value(E_LN_3);
}
c = c_ln(vals[0]->v_com, err);
break;
default:
@@ -2289,8 +2294,10 @@ f_log(int count, VALUE **vals)
*/
switch (vals[0]->v_type) {
case V_NUM:
if (!qisneg(vals[0]->v_num) &&
!qiszero(vals[0]->v_num)) {
if (qiszero(vals[0]->v_num)) {
return error_value(E_LOG_5);
}
if (!qisneg(vals[0]->v_num)) {
result.v_num = qlog(vals[0]->v_num, err);
result.v_type = V_NUM;
return result;
@@ -2301,6 +2308,9 @@ f_log(int count, VALUE **vals)
c = c_log(&ctmp, err);
break;
case V_COM:
if (ciszero(vals[0]->v_com)) {
return error_value(E_LOG_5);
}
c = c_log(vals[0]->v_com, err);
break;
default:
@@ -2349,6 +2359,9 @@ f_log2(int count, VALUE **vals)
*/
switch (vals[0]->v_type) {
case V_NUM:
if (qiszero(vals[0]->v_num)) {
return error_value(E_LOG2_4);
}
if (!qisneg(vals[0]->v_num) &&
!qiszero(vals[0]->v_num)) {
result.v_num = qlog2(vals[0]->v_num, err);
@@ -2361,6 +2374,9 @@ f_log2(int count, VALUE **vals)
c = c_log2(&ctmp, err);
break;
case V_COM:
if (ciszero(vals[0]->v_com)) {
return error_value(E_LOG2_4);
}
c = c_log2(vals[0]->v_com, err);
break;
default:
@@ -2447,7 +2463,7 @@ f_logn(int count, VALUE **vals)
switch (vals[0]->v_type) {
case V_NUM:
if (qiszero(vals[0]->v_num)) {
return error_value(E_LOGN_3);
return error_value(E_LOGN_6);
}
if (qisneg(vals[0]->v_num)) {
ctmp.real = vals[0]->v_num;
@@ -2471,7 +2487,7 @@ f_logn(int count, VALUE **vals)
break;
case V_COM:
if (ciszero(vals[0]->v_com)) {
return error_value(E_LOGN_3);
return error_value(E_LOGN_6);
}
ln_x_c = c_ln(vals[0]->v_com, err);
if (ln_x_c == NULL) {
@@ -12027,6 +12043,11 @@ f_aexsec(int count, VALUE **vals)
arg1 = *vals[0];
if (arg1.v_type == V_NUM) {
/* firewall */
if (qisnegone(arg1.v_num)) {
return error_value(E_AEXSEC_3);
}
/* try to compute result using real trig function */
result.v_num = qaexsec_or_NULL(arg1.v_num, eps);
@@ -12169,6 +12190,11 @@ f_aexcsc(int count, VALUE **vals)
arg1 = *vals[0];
if (arg1.v_type == V_NUM) {
/* firewall */
if (qisnegone(arg1.v_num)) {
return error_value(E_AEXCSC_3);
}
/* try to compute result using real trig function */
result.v_num = qaexcsc_or_NULL(arg1.v_num, eps);

View File

@@ -18,7 +18,7 @@ DESCRIPTION
EXAMPLE
; print acsc(0), acsc(0.5), acsc(1)
Error 10454 1.57079632679489661923-1.31695789692481670863i 1.57079632679489661923
Error E_ACSC_3 1.57079632679489661923-1.31695789692481670863i 1.57079632679489661923
; print acsc(-0.5), acsc(-1)
-1.57079632679489661923+1.31695789692481670863i -1.57079632679489661923

View File

@@ -23,7 +23,7 @@ EXAMPLE
1.57079632679489661923 0.72972765622696636345 0.52359877559829887308
; print aexcsc(-0.5), aexcsc(-1)
1.57079632679489661923-1.31695789692481670863i Error 10454
1.57079632679489661923-1.31695789692481670863i Error E_AEXCSC_3
; print aexcsc(.5, 1e-5), aexcsc(.5, 1e-10), aexcsc(.5, 1e-15)
0.72973 0.7297276562 0.729727656226966

View File

@@ -23,7 +23,7 @@ EXAMPLE
0 0.84106867056793025578 1.04719755119659774615
; print aexsec(-0.5), aexsec(-1)
1.31695789692481670863i Error 10453
1.31695789692481670863i Error E_AEXSEC_3
; print aexsec(.5, 1e-5), aexsec(.5, 1e-10), aexsec(.5, 1e-15), aexsec(.5, 1e-20)
0.84107 0.8410686706 0.84106867056793 0.84106867056793025578

View File

@@ -18,7 +18,7 @@ DESCRIPTION
EXAMPLE
; print asec(0), asec(0.5), asec(1)
Error 10453 1.31695789692481670863i 0
Error E_ASEC_3 1.31695789692481670863i 0
; print asec(-0.5), asec(-1)
3.14159265358979323846-1.31695789692481670863i 3.14159265358979323846

View File

@@ -28,7 +28,7 @@ EXAMPLE
chunksize = 256, maxsize = 256, datalen = 3
010203
; blocks(2)
Error 10211
Error E_BLOCKS_2
; strerror()
"Non-allocated index number for blocks"
@@ -41,7 +41,7 @@ LINK LIBRARY
SEE ALSO
blk, blkfree
## Copyright (C) 1999,2021 Landon Curt Noll
## Copyright (C) 1999,2021,2023 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -73,13 +73,13 @@ EXAMPLE
; print custom("sysinfo", "baseb")
Calc was built with custom functions disabled
Error 10195
Error E_NO_C_ARG
If calc compiled with ALLOW_CUSTOM= -DCUSTOM and is invoked without -C:
; print custom("sysinfo", "baseb")
Calc must be run with a -C argument to use custom function
Error 10194
Error E_NO_C_ARG
If calc compiled with ALLOW_CUSTOM= -DCUSTOM and is invoked with -C:

View File

@@ -36,7 +36,7 @@ EXAMPLE
0
; a = 1/0; b = 2 + ""; c = error(27); d = newerror("a");
; print errcount(), a, errcount(), errmax();
4 Error 10001 4 10
4 Error E_DIVBYZERO 4 10
LIMITS
0 <= num < 2^32

View File

@@ -20,7 +20,7 @@ DESCRIPTION
EXAMPLE
; errmax(2)
0
20
; errcount()
0
; a = 1/0; b = 2 + ""; c = error(27); d = newerror("alpha");

View File

@@ -111,7 +111,7 @@ EXAMPLE
; print errcount(), errmax()
1 20
; print a
Error 10009
Error E_INV
; print iserror(a)
10009
; print strerror(a)

View File

@@ -28,7 +28,7 @@ EXAMPLE
; fgetstr(f)
; fputstr(f, "Gamma")
Error 72
Error E_FPUTSTR_3
LIMITS
none
@@ -39,7 +39,7 @@ LINK LIBRARY
SEE ALSO
fgetstr, fgetfield, fgets, fputs, fopen, files, fprintf
## Copyright (C) 1999-2006 Landon Curt Noll
## Copyright (C) 1999-2006,2023 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -31,7 +31,7 @@ EXAMPLE
Number: 1
; freestatics()
; f(1)
Error 10005
Error E_MUL
; strerror(.)
"Bad arguments for *"
@@ -44,7 +44,7 @@ LINK LIBRARY
SEE ALSO
free, freeglobals, freeredc
## Copyright (C) 1999 Landon Curt Noll
## Copyright (C) 1999,2023 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -28,7 +28,7 @@ EXAMPLE
"Leonard Euler"
; !chmod u-w /tmp/junk
; freopen(f, "w")
Error 10013
Error E_FRAC
LIMITS
none
@@ -40,7 +40,7 @@ SEE ALSO
errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen,
fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt
## Copyright (C) 1999-2006,2021 Landon Curt Noll
## Copyright (C) 1999-2006,2021,2023 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -40,7 +40,7 @@ EXAMPLE
; iserror(e1)
20000
; error(20000)
Error 20000
Error E_20000
; strerror(error(20000))
"triangle side length <= 0"
; strerror(e1);

View File

@@ -228,7 +228,7 @@ EXAMPLE
"No-type-change destination for assign"
; B = 45
; swap(A,B)
Error 10372
Error E_SWAP_2
; strerror()
"No-assign-to-or-from argument for swap"
; protect(A,-64)
@@ -244,21 +244,21 @@ EXAMPLE
; B = list(5,6,7,8)
; protect(A,16)
; copy(B,A)
Error 10226
Error E_COPY_14
; strerror()
"No-copy-to destination variable"
; A = list(1,2,3)
; protect(A,32)
; append(A,4)
Error 10402
Error E_LIST_4
; strerror()
"No-relocate for list append"
; A = blk(0,5)
; copy("abc", A)
; copy("de",A)
Error 10229
Error E_COPY_17
; strerror()
"No-relocate destination variable"
@@ -266,7 +266,7 @@ EXAMPLE
; protect(A,0)
; protect(*A, 16)
; copy("abc", A)
Error 10228
Error E_COPY_16
; strerror()
"No-copy-to destination named block"
@@ -279,7 +279,7 @@ LINK LIBRARY
SEE ALSO
assign, copy, blk, error, errno, strerror
## Copyright (C) 1999-2006,2021 Landon Curt Noll
## Copyright (C) 1999-2006,2021,2023 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -22,7 +22,7 @@ EXAMPLE
; scan(a, 0, c, d)
; 2+3 b=a^2 3+4i 3+"a"
; print a,b,c,d
5 25 3+4i Error 3
5 25 3+4i Error E_ADD
LIMITS
The number of arguments is not to exceed 1024.
@@ -33,7 +33,7 @@ LINK LIBRARY
SEE ALSO
fscan, strscan, fscanf, strscanf, scanf, printf, fprintf
## Copyright (C) 1999-2006 Landon Curt Noll
## Copyright (C) 1999-2006,2023 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -1057,7 +1057,7 @@ qln(NUMBER *q, NUMBER *epsilon)
bool neg;
if (qiszero(q)) {
math_error("logarithm of 0");
math_error("ln of 0");
not_reached();
}
if (qiszero(epsilon)) {
@@ -1173,7 +1173,7 @@ qlog(NUMBER *q, NUMBER *epsilon)
/* firewall */
if (qiszero(q)) {
math_error("logarithm of 0");
math_error("log of 0");
not_reached();
}
if (qiszero(epsilon)) {
@@ -1254,7 +1254,7 @@ qlog2(NUMBER *q, NUMBER *epsilon)
/* firewall */
if (qiszero(q)) {
math_error("logarithm of 0");
math_error("log2 of 0");
not_reached();
}
if (qiszero(epsilon)) {
@@ -1328,7 +1328,7 @@ qlogn(NUMBER *q, NUMBER *n, NUMBER *epsilon)
/* firewall */
if (qiszero(q)) {
math_error("logarithm of 0");
math_error("log base n of 0");
not_reached();
}
if (qiszero(epsilon)) {

View File

@@ -241,10 +241,20 @@ printtype(VALUE *vp)
{
int type;
char *s;
char *errsym;
bool alloced;
type = vp->v_type;
if (type < 0) {
errsym = errnum_2_errsym(-type, &alloced);
if (errsym == NULL) {
printf("Error %d", -type);
} else {
printf("Error %s", errsym);
if (alloced == true) {
free(errsym);
}
}
return;
}
switch (type) {

22
value.c
View File

@@ -2794,15 +2794,31 @@ printvalue(VALUE *vp, int flags)
{
NUMBER *qtemp;
int type;
char *errsym;
bool alloced;
type = vp->v_type;
if (type < 0) {
if (userfunc("error_print", vp))
if (userfunc("error_print", vp)) {
return;
if (-type >= E__BASE)
}
errsym = errnum_2_errsym(-type, &alloced);
if (errsym == NULL) {
if (-type >= E__BASE) {
math_fmt("Error %d", -type);
else
} else {
math_fmt("System error %d", -type);
}
} else {
if (-type >= E__BASE) {
math_fmt("Error %s", errsym);
} else {
math_fmt("System error %s", errsym);
}
if (alloced == true) {
free(errsym);
}
}
return;
}
switch (type) {

View File

@@ -84,8 +84,6 @@ typedef struct random RANDOM;
*
* NOTE: The v_type can be a negative value. This happens when
* an error is returned as a VALUE.
*
* XXX - calc v3 wish: make v_type and v_subtype an int32_t - XXX
*/
struct value {
short v_type; /* type of value - IMPORTANT: v_type < 0 is an error code */