upd: ready to write NTT

This commit is contained in:
2023-10-30 12:09:44 +08:00
parent d660095777
commit 116e675b29
4 changed files with 100 additions and 2 deletions

View File

@ -22,6 +22,8 @@ class int2048 {
signed char flag = +1;
int num_length = 0;
void NTT(__int128_t *, int, int);
public:
int2048();
int2048(long long);

View File

@ -330,12 +330,22 @@ int2048 operator-(int2048 A, const int2048 &B) {
return std::move(A);
}
inline void UnsignedMultiply(int2048 &A, const int2048 *pB) { ; }
inline void UnsignedMultiply(int2048 &A, const int2048 *pB)
{
;
}
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]) ||
(pB->num_length == 1 && pB->val[0] == 0)) {
*this = std::move(int2048(0));
return *this;
}
this->flag = this->flag * pB->flag;
UnsignedMultiply(*this,pB);
return *this;
}

85
tester/cases/2.py Executable file
View File

@ -0,0 +1,85 @@
#!/usr/bin/python3
from os import system
from sys import exit
from random import randint
"""
this script is used to test * operator
"""
code_cpp_pre="""
#include<iostream>
#include "/home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/include/int2048.h"
using namespace std;
using namespace sjtu;
int main()
{
"""
code_cpp_suf="""
return 0;
}
"""
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),a_9(0);"
code_python_pre="""#!/usr/bin/python3
"""
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"
opt_cpp=[]
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)+";")
opt_python.append("a_"+str(i)+"="+str(val))
opt_cpp.append("a_"+str(i)+".print(); puts(\"\");")
opt_python.append("print(a_"+str(i)+")")
if True:
for i in range(10):
aid=randint(0,9)
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))
opt_cpp.append("a_"+str(aid)+".print(); puts(\"\");")
opt_python.append("print(a_"+str(aid)+")")
opt_cpp.append("a_"+str(bid)+".print(); puts(\"\");")
opt_python.append("print(a_"+str(bid)+")")
opt_cpp.append("a_"+str(cid)+".print(); puts(\"\");")
opt_python.append("print(a_"+str(cid)+")")
if True:
for i in range(10):
aid=randint(0,9)
bid=randint(0,9)
op='*='
opt_cpp.append("a_"+str(aid)+op+"a_"+str(bid)+";")
opt_python.append("a_"+str(aid)+op+"a_"+str(bid))
opt_cpp.append("a_"+str(aid)+".print(); puts(\"\");")
opt_python.append("print(a_"+str(aid)+")")
sourc_cpp=open("/tmp/2.cpp","w")
print(code_cpp_pre,file=sourc_cpp)
print(def_cpp,file=sourc_cpp)
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("/tmp/2 > /tmp/2_cpp.out")
sourc_python=open("/tmp/2.py","w")
print(code_python_pre,file=sourc_python)
print(def_python,file=sourc_python)
for opt in opt_python:
print(opt,file=sourc_python)
sourc_python.close()
system("chmod +x /tmp/2.py")
system("/tmp/2.py > /tmp/2_python.out")
exit(system("diff -b -B -u /tmp/2_cpp.out /tmp/2_python.out > /tmp/2.diff")//256)

View File

@ -25,6 +25,7 @@
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C2T16 >/tmp/C2T16.out && diff -b -B -u /tmp/C2T16.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer2/16.out >/tmp/diffC2T16","uid":"#26","tid":"/2/16"},
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C2T17 >/tmp/C2T17.out && diff -b -B -u /tmp/C2T17.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer2/17.out >/tmp/diffC2T17","uid":"#27","tid":"/2/17"},
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C2T18 >/tmp/C2T18.out && diff -b -B -u /tmp/C2T18.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer2/18.out >/tmp/diffC2T18","uid":"#28","tid":"/2/18"},
{"command":"/home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/tester/cases/1.py","uid":"#29","tid":"/3/1"}
{"command":"/home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/tester/cases/1.py","uid":"#29","tid":"/3/1"},
{"command":"/home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/tester/cases/2.py","uid":"#30","tid":"/3/2"}
]
}