feat: finish *

This commit is contained in:
2023-10-30 17:30:10 +08:00
parent 1e543b6a7b
commit b158fddf2e
2 changed files with 18 additions and 8 deletions

View File

@ -430,7 +430,7 @@ int2048 &int2048::Multiply(const int2048 &B) {
// 实现复合乘法逻辑
const int2048 *pB = &B;
if (this == &B) pB = new int2048(B);
if ((this->num_length == 1 && this->val[0]) ||
if ((this->num_length == 1 && this->val[0] == 0) ||
(pB->num_length == 1 && pB->val[0] == 0)) {
*this = std::move(int2048(0));
return *this;
@ -542,4 +542,4 @@ bool operator>=(const int2048 &A, const int2048 &B) {
else
return cmp <= 0;
}
} // namespace sjtu
} // namespace sjtu

View File

@ -2,10 +2,13 @@
from os import system
from sys import exit
from random import randint
import sys
"""
this script is used to test * operator
"""
sys.set_int_max_str_digits(10000000)
code_cpp_pre="""
#include<iostream>
#include "/home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/include/int2048.h"
@ -22,7 +25,8 @@ def_cpp="int2048 a_0(0),a_1(0),a_2(0),a_3(0),a_4(0),a_5(0),a_6(0),a_7(0),a_8(0),
code_python_pre="""#!/usr/bin/python3
import sys
sys.set_int_max_str_digits(10000000)
"""
def_python="a_0,a_1,a_2,a_3,a_4,a_5,a_6,a_7,a_8,a_9=0,0,0,0,0,0,0,0,0,0"
@ -32,8 +36,8 @@ opt_python=[]
if True:
for i in range(0,10):
val=randint(-2**31,2**31-1)
opt_cpp.append("a_"+str(i)+"="+str(val)+";")
val=randint(-10**2,10**2)
opt_cpp.append("a_"+str(i)+"=int2048(\""+str(val)+"\");")
opt_python.append("a_"+str(i)+"="+str(val))
opt_cpp.append("a_"+str(i)+".print(); puts(\"\");")
opt_python.append("print(a_"+str(i)+")")
@ -44,8 +48,14 @@ if True:
bid=randint(0,9)
cid=randint(0,9)
op='*'
opt_cpp.append("a_"+str(aid)+"=a_"+str(bid)+op+"a_"+str(cid)+";")
opt_python.append("a_"+str(aid)+"=a_"+str(bid)+op+"a_"+str(cid))
bflag="+"
if randint(0,1)==0:
bflag="-"
cflag="+"
if randint(0,1)==0:
cflag="-"
opt_cpp.append("a_"+str(aid)+"=("+bflag+"a_"+str(bid)+")"+op+"("+cflag+"a_"+str(cid)+");")
opt_python.append("a_"+str(aid)+"=("+bflag+"a_"+str(bid)+")"+op+"("+cflag+"a_"+str(cid)+")")
opt_cpp.append("a_"+str(aid)+".print(); puts(\"\");")
opt_python.append("print(a_"+str(aid)+")")
opt_cpp.append("a_"+str(bid)+".print(); puts(\"\");")
@ -70,7 +80,7 @@ for opt in opt_cpp:
print(opt,file=sourc_cpp)
print(code_cpp_suf,file=sourc_cpp)
sourc_cpp.close()
system("g++ /tmp/2.cpp -I /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/include/ -L /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/src/ -lint2048 -o /tmp/2")
system("g++ /tmp/2.cpp -I /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/include/ -L /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/src/ -lint2048 -g -o /tmp/2")
system("/tmp/2 > /tmp/2_cpp.out")
sourc_python=open("/tmp/2.py","w")