about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/math.c19
-rw-r--r--Src/params.c13
-rw-r--r--Src/subst.c9
3 files changed, 30 insertions, 11 deletions
diff --git a/Src/math.c b/Src/math.c
index a7fcd0978..38466ed8e 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -186,6 +186,8 @@ static int type[TOKCOUNT] =
 /* 50 */  LR|OP_OPF, RL|OP_E2, LR|OP_OPF
 };
 
+/**/
+int outputradix;
 
 /**/
 static int
@@ -340,12 +342,22 @@ zzlex(void)
 	    return EOI;
 	case '[':
 	    {
-		int base = zstrtol(ptr, &ptr, 10);
+		int base, setradix = 0;
+		if (*ptr == '#') {
+		    ptr++;
+		    setradix = 1;
+		}
+		base = zstrtol(ptr, &ptr, 10);
 
 		if (*ptr == ']')
 		    ptr++;
-		yyval.u.l = zstrtol(ptr, &ptr, lastbase = base);
-		return NUM;
+		if (setradix)
+		    outputradix = base;
+		else {
+		    yyval.u.l = zstrtol(ptr, &ptr, lastbase = base);
+		    return NUM;
+		}
+		break;
 	    }
 	case ' ':
 	case '\t':
@@ -934,6 +946,7 @@ matheval(char *s)
     char *junk;
     mnumber x;
     int xmtok = mtok;
+    outputradix = 0;
 
     if (!*s) {
 	x.type = MN_INTEGER;
diff --git a/Src/params.c b/Src/params.c
index 6ccfd9307..8c39ec2ac 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1577,9 +1577,11 @@ setnumvalue(Value v, mnumber val)
     switch (PM_TYPE(v->pm->flags)) {
     case PM_SCALAR:
     case PM_ARRAY:
-	if (val.type & MN_INTEGER)
-	    convbase(p = buf, val.u.l, 0);
-	else
+	if ((val.type & MN_INTEGER) || outputradix) {
+	    if (!(val.type & MN_INTEGER))
+		val.u.l = (zlong) val.u.d;
+	    convbase(p = buf, val.u.l, outputradix);
+	} else
 	    p = convfloat(val.u.d, 0, 0, NULL);
 	setstrvalue(v, ztrdup(p));
 	break;
@@ -1909,9 +1911,10 @@ setnparam(char *s, mnumber val)
 	pm = createparam(t, (val.type & MN_INTEGER) ? PM_INTEGER
 			 : PM_FFLOAT);
 	DPUTS(!pm, "BUG: parameter not created");
-	if (val.type & MN_INTEGER)
+	if (val.type & MN_INTEGER) {
+	    pm->ct = outputradix;
 	    pm->u.val = val.u.l;
-	else
+	} else
 	    pm->u.dval = val.u.d;
 	return pm;
     }
diff --git a/Src/subst.c b/Src/subst.c
index 94a1222d8..beb99b5ee 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -1964,10 +1964,13 @@ arithsubst(char *a, char **bptr, char *rest)
 
     singsub(&a);
     v = matheval(a);
-    if (v.type & MN_FLOAT)
+    if ((v.type & MN_FLOAT) && !outputradix)
 	b = convfloat(v.u.d, 0, 0, NULL);
-    else
-	convbase(buf, v.u.l, 0);
+    else {
+	if (v.type & MN_FLOAT)
+	    v.u.l = (zlong) v.u.d;
+	convbase(buf, v.u.l, outputradix);
+    }
     t = *bptr = (char *) hcalloc(strlen(*bptr) + strlen(b) + 
 				 strlen(rest) + 1);
     t--;