📄 regress.cal
字号:
/* * test_config - test config control */define test_config(){ local callcfg; /* caller configuration value */ local oldcfg; /* caller configuration value */ local newcfg; /* caller configuration value */ print '500: Beginning test_config'; /* check the set and return of all config */ callcfg = config("all"); print '501: callcfg = config("all")'; vrfy(callcfg == startcfg, '502: callcfg == startcfg'); callcfg = config("all", "oldstd"); print '503: callcfg = config("all","oldstd")'; vrfy(callcfg == startcfg, '504: callcfg == startcfg'); oldcfg = config("all"); print '505: oldcfg = config("all");'; vrfy(config("all") == oldcfg, '506: config("all") == oldcfg'); vrfy(oldcfg==config("all","newstd"), '507: oldcfg==config("all","newstd")'); vrfy(defcfg == config("all"), '508: defcfg == config("all")'); /* vrfy the state of the default config */ vrfy(config("mode") == "real", '509: config("mode") == "real"'); vrfy(config("display") == 20, '510: config("display") == 20'); vrfy(config("epsilon") == 1e-20, '511: config("epsilon") == 1e-20'); vrfy(config("trace") == 0, '512: config("trace") == 0'); vrfy(config("maxprint") == 16, '513: config("maxprint") == 16'); vrfy(config("mul2") == 1780, '514: config("mul2") == 1780'); vrfy(config("sq2") == 3388, '515: config("sq2") == 3388'); vrfy(config("pow2") == 176, '516: config("pow2") == 176'); vrfy(config("redc2") == 220, '517: config("redc2") == 220'); vrfy(config("tilde"), '518: config("tilde")'); vrfy(config("tab"), '519: config("tab")'); vrfy(config("quomod") == 0, '520: config("quomod") == 0'); vrfy(config("quo") == 2, '521: config("quo") == 2'); vrfy(config("mod") == 0, '522: config("mod") == 0'); vrfy(config("sqrt") == 24, '523: config("sqrt") == 24'); vrfy(config("appr") == 24, '524: config("appr") == 24'); vrfy(config("cfappr") == 0, '525: config("cfappr") == 0'); vrfy(config("cfsim") == 8, '526: config("cfsim") == 8'); vrfy(config("outround") == 24, '527: config("outround") == 24'); vrfy(config("round") == 24, '528: config("round") == 24'); vrfy(config("leadzero") == 1, '529: config("leadzero") == 1'); vrfy(config("fullzero") == 0, '530: config("fullzero") == 0'); vrfy(config("maxscan") == 20, '531: config("maxscan") == 20'); vrfy(config("prompt") == "; ", '532: config("prompt") == "; "'); vrfy(config("more") == ";; ", '533: config("more") == ";; "'); /* convert to "oldstd" config by individual changes */ print '534: test unused'; vrfy(config("outround", 2) == 24, '535: config("outround", 2) == 24'); vrfy(config("leadzero","n") == 1, '536: config("leadzero","n") == 1'); print '537: test unused'; vrfy(config("prompt", "> ") == "; ", '538: config("prompt", "> ") == "; "'); vrfy(config("more", ">> ") == ";; ", '539: config("more", ">> ") == ";; "'); vrfy(config("all") == oldcfg, '540: config("all") == oldcfg'); /* restore the configation at the start of this function */ vrfy(config("all",callcfg) == oldcfg, '541: config("all",callcfg) == oldcfg'); /* display and fullzero tests */ vrfy(config("display",2) == 20, '542: config("display",2) == 20'); vrfy(config("leadzero",0) == 1, '543: config("leadzero",0) == 1'); vrfy(config("fullzero",1) == 0, '544: config("fullzero",1) == 0'); vrfy(strprintf("%d %d %d", 0, 1, 2) == ".00 1.00 2.00", '545: strprintf("%d %d %d", 0, 1, 2) == ".00 1.00 2.00"'); vrfy(config("display",20) == 2, '546: config("display",20) == 2'); vrfy(config("leadzero",1) == 0, '547: config("leadzero",1) == 0'); vrfy(config("fullzero",0) == 1, '548: config("fullzero",0) == 1'); vrfy(strprintf("%d %d %d", 0, 1, 2) == "0 1 2", '549: strprintf("%d %d %d", 0, 1, 2) == "0 1 2"'); /* restore calling config */ vrfy(config("all",callcfg) == startcfg, '550: config("all",callcfg) == startcfg'); vrfy(config("all") == callcfg, '551: config("all") == callcfg'); vrfy(config("all") == startcfg, '552: config("all") == startcfg'); /* check read-only config values */ vrfy(strlen(config("program")) > 0, '553: strlen(config("program")) > 0'); vrfy(strlen(config("basename")) > 0, '554: strlen(config("basename")) > 0'); vrfy(strlen(config("version")) > 0, '555: strlen(config("version")) > 0'); /* mode2 is off by default */ vrfy(config("mode2") == "off", '556: config("mode2") == "off"'); /* hz is numeric */ vrfy(isint(config("hz")), '557: isint(config("hz"))'); /* compile_custom is simple */ vrfy(issimple(config("compile_custom")), '558: issimple(config("compile_custom"))'); /* allow_custom is simple */ vrfy(issimple(config("allow_custom")), '559: issimple(config("allow_custom"))'); /* allow_custom is simple */ vrfy(issimple(config("allow_custom")), '559: issimple(config("allow_custom"))'); /* baseb is numeric */ vrfy(isint(config("baseb")), '560: isint(config("baseb"))'); /* redecl_warn is simple */ vrfy(issimple(config("redecl_warn")), '561: issimple(config("redecl_warn"))'); /* dupvar_warn is simple */ vrfy(issimple(config("dupvar_warn")), '562: issimple(config("rdupvar_warn"))'); print '563: Ending test_config';}print '010: parsed test_config()';/* * Do multiplication and division on three numbers in various ways * and vrfy the results agree. */define muldivcheck(a, b, c, str){ local abc, acb, bac, bca, cab, cba; abc = (a * b) * c; acb = (a * c) * b; bac = (b * a) * c; bca = (b * c) * a; cab = (c * a) * b; cba = (c * b) * a; if (abc != acb) {print '**** abc != acb:', str; ++prob;} if (acb != bac) {print '**** acb != bac:', str; ++prob;} if (bac != bca) {print '**** bac != bca:', str; ++prob;} if (bca != cab) {print '**** bca != cab:', str; ++prob;} if (cab != cba) {print '**** cab != cba:', str; ++prob;} if (abc/a != b*c) {print '**** abc/a != bc:', str; ++prob;} if (abc/b != a*c) {print '**** abc/b != ac:', str; ++prob;} if (abc/c != a*b) {print '**** abc/c != ab:', str; ++prob;} print str;}print '011: parsed muldivcheck(a, b, c, str)';/* * Use the identity for squaring the sum of two squares to check * multiplication and squaring. */define squarecheck(a, b, str){ local a2, b2, tab, apb, apb2, t; a2 = a^2; b2 = b^2; tab = a * b * 2; apb = a + b; apb2 = apb^2; if (a2 != a*a) {print '**** a^2 != a*a:', str; ++prob;} if (b2 != b*b) {print '**** b^2 != b*b:', str; ++prob;} if (apb2 != apb*apb) { print '**** (a+b)^2 != (a+b)*(a+b):', str; ++prob; } if (a2+tab+b2 != apb2) { print '**** (a+b)^2 != a^2 + 2ab + b^2:', str; ++prob; } if (a2/a != a) {print '**** a^2/a != a:', str; ++prob;} if (b2/b != b) {print '**** b^2/b != b:', str; ++prob;} if (apb2/apb != apb) {print '**** (a+b)^2/(a+b) != a+b:', str; ++prob;} if (a2*b2 != (a*b)^2) {print '**** a^2*b^2 != (ab)^2:', str; ++prob;} print str;}print '012: parsed squarecheck(a, b, str)';/* * Use the raising of numbers to large powers to check multiplication * and exponentiation. */define powercheck(a, p1, p2, str){ local a1, a2, a3; a1 = (a^p1)^p2; a2 = (a^p2)^p1; a3 = a^(p1*p2); if (a1 != a2) {print '**** (a^p1)^p2 != (a^p2)^p1:', str; ++prob;} if (a1 != a3) {print '**** (a^p1)^p2 != a^(p1*p2):', str; ++prob;} print str;}print '013: parsed powercheck(a, p1, p2, str)';/* * Test fraction reductions. * Arguments MUST be relatively prime. */define fraccheck(a, b, c, str){ local ab, bc, ca, aoc, boc, aob; ab = a * b; bc = b * c; ca = c * a; aoc = ab / bc; if (num(aoc) != a) {print '**** num(aoc) != a:', str; ++prob;} if (den(aoc) != c) {print '**** den(aoc) != c:', str; ++prob;} boc = ab / ca; if (num(boc) != b) {print '**** num(boc) != b:', str; ++prob;} if (den(boc) != c) {print '**** den(boc) != c:', str; ++prob;} aob = ca / bc; if (num(aob) != a) {print '**** num(aob) != a:', str; ++prob;} if (den(aob) != b) {print '**** den(aob) != b:', str; ++prob;} if (aob*boc != aoc) {print '**** aob*boc != aoc;', str; ++prob;} print str;}print '014: parsed fraccheck(a, b, c, str)';/* * Test multiplication and squaring algorithms. */define algcheck(a, b, str){ local ss, ms, t1, t2, t3, t4, t5, t6, t7; local a1, a2, a3, a4, a5, a6, a7; local oldmul2, oldsq2; oldmul2 = config("mul2", 2); oldsq2 = config("sq2", 2); a1 = a * b; a2 = a * a; a3 = b * b; a4 = a^2; a5 = b^2; a6 = a2^2; a7 = pmod(3,a-1,a); for (ms = 2; ms < 20; ms++) { for (ss = 2; ss < 20; ss++) { config("mul2", ms); config("sq2", ss); t1 = a * b; t2 = a * a; t3 = b * b; t4 = a^2; t5 = b^2; t6 = t2^2; if (((ms + ss) % 37) == 4) t7 = pmod(3,a-1,a); if (t1 != a1) {print '**** t1 != a1:', str; ++prob;} if (t2 != a2) {print '**** t2 != a2:', str; ++prob;} if (t3 != a3) {print '**** t3 != a3:', str; ++prob;} if (t4 != a4) {print '**** t4 != a4:', str; ++prob;} if (t5 != a5) {print '**** t5 != a5:', str; ++prob;} if (t6 != a6) {print '**** t6 != a6:', str; ++prob;} if (t7 != a7) {print '**** t7 != a7:', str; ++prob;} } } config("mul2", oldmul2); config("sq2", oldsq2); print str;}print '015: parsed algcheck(a, b, str)';/* * Test big numbers using some identities. */define test_bignums(){ local a, b, c, d; print '600: Beginning test_bignums'; a = 64357824568234938591; b = 12764632632458756817; c = 43578234973856347982; muldivcheck(a, b, c, '601: muldivcheck 1'); a = 3^100; b = 5^97; c = 7^88; muldivcheck(a, b, c, '602: muldivcheck 2'); a = 2^160 - 1; b = 2^161 - 1; c = 2^162 - 1; muldivcheck(a, b, c, '603: muldivcheck 3'); a = 3^35 / 5^35; b = 7^35 / 11^35; c = 13^35 / 17^35; muldivcheck(a, b, c, '604: muldivcheck 4'); a = (10^97-1) / 9; b = (10^53-1) / 9; c = (10^37-1) / 9; muldivcheck(a, b, c, '605: muldivcheck 5'); a = 17^50; b = 19^47; squarecheck(a, b, '606: squarecheck 1'); a = 2^111-1; b = 2^17; squarecheck(a, b, '607: squarecheck 2'); a = 23^43 / 29^43; b = 31^42 / 37^29; squarecheck(a, b, '608: squarecheck 3'); a = 4657892345743659834657238947854639; b = 43784356784365893467659347867689; squarecheck(a, b, '609: squarecheck 4'); a = (10^80-1) / 9; b = (10^50-1) / 9; squarecheck(a, b, '610: squarecheck 5'); a = 101^99; b = 2 * a; squarecheck(a, b, '611: squarecheck 6'); a = (10^19-1) / 9; vrfy(ptest(a, 20), '612: primetest R19'); a = (10^23-1) / 9; vrfy(ptest(a, 20), '613: primetest R23'); a = 2^127 - 1; vrfy(ptest(a, 1), '614: primetest M127');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -