diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-11-17 16:26:50 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-11-17 16:26:50 (GMT) |
commit | d7da846591f5edcc930be33973139f6ef0059580 (patch) | |
tree | 8745c9b69988bfd839bd9d090d41713bd840c002 /generic/tclTestObj.c | |
parent | 2edb1dcd838bb41a920ed09688ac6438f8efddc4 (diff) | |
parent | 2287394ba1bcf13a8abb6b8097f03e995cd3258a (diff) | |
download | tcl-d7da846591f5edcc930be33973139f6ef0059580.zip tcl-d7da846591f5edcc930be33973139f6ef0059580.tar.gz tcl-d7da846591f5edcc930be33973139f6ef0059580.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.c | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index 6053ae3..06f8e5f 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -152,10 +152,11 @@ TestbignumobjCmd( Tcl_Obj *const objv[]) /* Argument vector */ { const char *const 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; const char *string; @@ -274,6 +275,50 @@ TestbignumobjCmd( } else { SetVarToObj(varPtr, varIndex, Tcl_NewBignumObj(&newValue)); } + break; + + case BIGNUM_ISEVEN: + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "varIndex"); + return TCL_ERROR; + } + if (CheckIfVarUnset(interp, varPtr,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(varPtr, 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, varPtr,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(varPtr, varIndex, Tcl_NewIntObj(index)); + } + mp_clear(&bignumValue); + break; } Tcl_SetObjResult(interp, varPtr[varIndex]); |