cpp_mp/main.cpp
2025-11-23 19:00:32 +01:00

119 lines
3.2 KiB
C++

#include <iostream>
//#include "mp.hpp"
#include "mp/int.hpp"
#include "mp/storage.hpp"
#include "mp/math.hpp"
template <class T>
static void PrintInt(const char* name, const T& val)
{
std::cout << name << " = " << mp::to_hex_string(val) << std::endl;
}
int main()
{
// mp::Int a{0xDEADBEEFDEADF154, 0x0123456789ABCDEF, 0x1111222233334444};
mp::Int<32> a{0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
mp::Int<1> b{0x55};
PrintInt("a", a);
PrintInt("b", b);
auto c = a + b;
//auto c = binary_opa, b);
PrintInt("c", c);
//a += mp::Int<1>{1};
//PrintInt("a", a);
//a -= mp::Int<1>{1};
//PrintInt("a", a);
std::cout << mp::Int<17>::LAST_ELEM_MASK << std::endl;
std::cout << sizeof(mp::Int<1>) << std::endl;
std::cout << sizeof(mp::Int<2>) << std::endl;
std::cout << sizeof(mp::Int<3>) << std::endl;
std::cout << sizeof(mp::Int<4>) << std::endl;
std::cout << sizeof(mp::Int<5>) << std::endl;
std::cout << sizeof(mp::Int<6>) << std::endl;
std::cout << sizeof(mp::Int<7>) << std::endl;
std::cout << sizeof(mp::Int<8>) << std::endl;
std::cout << sizeof(mp::Int<9>) << std::endl;
std::cout << sizeof(mp::Int<10>) << std::endl;
std::cout << sizeof(mp::Int<20>) << std::endl;
std::cout << sizeof(mp::Int<30>) << std::endl;
std::cout << sizeof(mp::Int<40>) << std::endl;
std::cout << sizeof(mp::Int<50>) << std::endl;
std::cout << sizeof(mp::Int<60>) << std::endl;
std::cout << sizeof(mp::Int<70>) << std::endl;
std::cout << sizeof(mp::Int<80>) << std::endl;
std::cout << sizeof(mp::Int<90>) << std::endl;
std::cout << sizeof(mp::Int<100>) << std::endl;
std::cout << sizeof(mp::Int<110>) << std::endl;
std::cout << sizeof(mp::Int<120>) << std::endl;
std::cout << sizeof(mp::Int<130>) << std::endl;
std::cout << sizeof(mp::Int<140>) << std::endl;
std::cout << sizeof(mp::Int<150>) << std::endl;
std::cout << sizeof(mp::Int<160>) << std::endl;
{
mp::Int<1024> acc{1};
try
{
while (true)
{
acc *= mp::Int<1>{10};
PrintInt("acc", acc);
}
}
catch (const mp::OverflowErrorOf<decltype(acc), mp::Int<1>>& e)
{
std::cout << "overflow" << std::endl;
PrintInt("value", e.value());
}
catch (const std::exception& e)
{
std::cout << "error: " << e.what() << std::endl;
}
}
//{
// mp::Int<32> val{1};
// for (mp::Int<4> a{1}; a < 100U; a += 1U)
// {
// for (size_t i = 0; i < 20; ++i)
// {
// val *= a;
// //PrintInt("val", val);
// }
// for (size_t i = 0; i < 20; ++i)
// {
// val /= a;
// }
// //if (val != 0U)
// //{
// PrintInt("val", val);
// //}
// }
//}
{
mp::Int<32> a{0xA0000000, 0x6D7217CA, 0x431E0FAE, 0x1};
mp::Int<16> b{0x6FC10000, 0x2386F2};
PrintInt("a", a);
PrintInt("b", b);
auto c = a / b;
PrintInt("c", c);
}
}