summaryrefslogtreecommitdiffstats
path: root/generic/tclTestObj.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2016-11-17 16:12:14 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2016-11-17 16:12:14 (GMT)
commit8d1caeae4dbe404a28c14bdc0bc3a8e97f6eaaf2 (patch)
treece84219a5932e60edc4b6d0a8b9ee60cb721f33b /generic/tclTestObj.c
parent99fd1215e29a440df99afb1b967c6e91faffa7c6 (diff)
downloadtcl-8d1caeae4dbe404a28c14bdc0bc3a8e97f6eaaf2.zip
tcl-8d1caeae4dbe404a28c14bdc0bc3a8e97f6eaaf2.tar.gz
tcl-8d1caeae4dbe404a28c14bdc0bc3a8e97f6eaaf2.tar.bz2
Fix libtommath's mp_radix_size() function such that it returns 2 for single-digit numbers. Add testcases for mp_radix_size() and mp_iseven(). Undo useless change in bn_mp_add_d.c (bring back libtommath's version).
Diffstat (limited to 'generic/tclTestObj.c')
-rw-r--r--generic/tclTestObj.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c
index f113cfe..4226d51 100644
--- a/generic/tclTestObj.c
+++ b/generic/tclTestObj.c
@@ -132,10 +132,11 @@ TestbignumobjCmd(
Tcl_Obj *const objv[]) /* Argument vector */
{
const char * subcmds[] = {
- "set", "get", "mult10", "div10", NULL
+ "set", "get", "mult10", "div10", "iseven", "radixsize", NULL
};
enum options {
- BIGNUM_SET, BIGNUM_GET, BIGNUM_MULT10, BIGNUM_DIV10
+ BIGNUM_SET, BIGNUM_GET, BIGNUM_MULT10, BIGNUM_DIV10, BIGNUM_ISEVEN,
+ BIGNUM_RADIXSIZE
};
int index, varIndex;
@@ -253,6 +254,50 @@ TestbignumobjCmd(
} else {
SetVarToObj(varIndex, Tcl_NewBignumObj(&newValue));
}
+ break;
+
+ case BIGNUM_ISEVEN:
+ if (objc != 3) {
+ Tcl_WrongNumArgs(interp, 2, objv, "varIndex");
+ return TCL_ERROR;
+ }
+ if (CheckIfVarUnset(interp, varIndex)) {
+ return TCL_ERROR;
+ }
+ if (Tcl_GetBignumFromObj(interp, varPtr[varIndex],
+ &bignumValue) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (!Tcl_IsShared(varPtr[varIndex])) {
+ Tcl_SetIntObj(varPtr[varIndex], mp_iseven(&bignumValue));
+ } else {
+ SetVarToObj(varIndex, Tcl_NewIntObj(mp_iseven(&bignumValue)));
+ }
+ mp_clear(&bignumValue);
+ break;
+
+ case BIGNUM_RADIXSIZE:
+ if (objc != 3) {
+ Tcl_WrongNumArgs(interp, 2, objv, "varIndex");
+ return TCL_ERROR;
+ }
+ if (CheckIfVarUnset(interp, varIndex)) {
+ return TCL_ERROR;
+ }
+ if (Tcl_GetBignumFromObj(interp, varPtr[varIndex],
+ &bignumValue) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (mp_radix_size(&bignumValue, 10, &index) != MP_OKAY) {
+ return TCL_ERROR;
+ }
+ if (!Tcl_IsShared(varPtr[varIndex])) {
+ Tcl_SetIntObj(varPtr[varIndex], index);
+ } else {
+ SetVarToObj(varIndex, Tcl_NewIntObj(index));
+ }
+ mp_clear(&bignumValue);
+ break;
}
Tcl_SetObjResult(interp, varPtr[varIndex]);