Attempted to separate the snippets of code to small functions and each set of functions have its own file. Also made some improvements by using pools instead of constantly mallocing space.

This commit is contained in:
2026-05-07 02:00:15 +03:00
parent 00396f86fe
commit e3239bf564
15 changed files with 561 additions and 289 deletions
+53 -10
View File
@@ -1,28 +1,71 @@
#ifndef MATHS_H
#define MATHS_H
#include "core.h"
#include "utils.h"
// Check if a 128 bit integer is a prime number or not
int is_prime(int128_t n);
/**
* @brief Checks if a 128 bit integer is a prime number
* @param n The integer to check
* @return true if the integer is prime, false otherwise
*/
bool is_prime(int128_t n);
// Calculate the GCD for 3 128 bit integers
/**
* @brief Checks if a 128 bit integer is within the safe limit
* @param x The integer to check
* @return true if the integer is within the safe limit, false otherwise
*/
bool safe_val(int128_t x);
/**
* @brief Calculates the GCD for 3 128 bit integers
* @param a The first integer
* @param b The second integer
* @param c The third integer
* @return The GCD of the three integers
*/
int128_t gcd3(int128_t a, int128_t b, int128_t c);
// Calculate the GCD for 2 128 bit integers
/**
* @brief Calculates the GCD for 2 128 bit integers
* @param a The first integer
* @param b The second integer
* @return The GCD of the two integers
*/
int128_t gcd2(int128_t a, int128_t b);
// Return the absolute value of a 128 bit integer
/**
* @brief Returns the absolute value of a 128 bit integer
* @param x The integer to get the absolute value of
* @return The absolute value of the integer
*/
int128_t abs128(int128_t x);
// Raise a number a certain exponent
/**
* @brief Calculates b raised to the power of ex for 128 bit integers
* @param b The base integer
* @param ex The exponent integer
* @return The result of b raised to the power of ex
*/
int128_t power(int128_t b, int128_t ex);
// Generate the factor pairs
/**
* @brief Generates factor pairs for a 128 bit integer
* @param sum Pointer to store the sum of the factor pairs
* @param prime_index The index of the prime number to use
* @param exponents Pointer to the array of exponents
* @param values Pointer to the array of values
* @param n1 The first integer
* @param print_mode The mode for printing the results
*/
void generate_factor_pairs(int128_t* sum, int prime_index, int* exponents,
int128_t* values, int128_t n1, int print_mode);
int128_t* values, int128_t n1, int print_mode);
// Calculate the square root of an unsigned 128 bit integer
/**
* @brief Calculates the square root of an unsigned 128 bit integer
* @param number The integer to calculate the square root of
* @return The square root of the integer
*/
uint128_t mysqrt_uint128(uint128_t number);
#endif