forked from preda/gpuowl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGmpUtil.h
36 lines (25 loc) · 957 Bytes
/
GmpUtil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (C) Mihai Preda.
#pragma once
#include "common.h"
#include <gmpxx.h>
#include <string>
#include <vector>
// return GCD(bits - sub, 2^exp - 1) as a decimal string if GCD!=1, or empty string otherwise.
std::string GCD(u32 exp, const std::vector<u32>& words, u32 sub = 0);
// Represent mpz value as vector of bits with the most significant bit first.
vector<bool> bitsMSB(const mpz_class& a);
vector<bool> powerSmoothMSB(u32 exp, u32 B1);
vector<bool> powerSmoothLSB(u32 exp, u32 B1);
// Bitlen of powerSmooth
u32 powerSmoothBits(u32 exp, u32 B1);
// Returns jacobi-symbol(words, 2**exp - 1)
int jacobi(u32 exp, const std::vector<u32>& words);
inline mpz_class mpz64(u64 h) {
mpz_class ret{u32(h >> 32)};
ret <<= 32;
ret += u32(h);
return ret;
}
// Split the "k" of a P-1 factor of the form 2*k*exponent +1 into subfactors.
vector<u32> factorize(const string& str, u32 exponent, u32 B1, u32 B2);
double log2(const string& str);