Files
stergios/include/maths.h
T

108 lines
3.0 KiB
C
Executable File

#ifndef MATHS_H
#define MATHS_H
#include "utils.h"
#include <stdio.h>
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @brief Returns the maximum of 3 128 bit integers
* @param a The first integer
* @param b The second integer
* @param c The third integer
* @return The maximum of the three integers
*/
int128_t max3(int128_t a, int128_t b, int128_t c);
/**
* @brief Returns the maximum of 2 128 bit integers
* @param a The first integer
* @param b The second integer
* @return The maximum of the two integers
*/
int128_t max2(int128_t a, int128_t b);
/**
* @brief Returns the minimum of 3 128 bit integers
* @param a The first integer
* @param b The second integer
* @param c The third integer
* @return The minimum of the three integers
*/
int128_t min3(int128_t a, int128_t b, int128_t c);
/**
* @brief Returns the minimum of 2 128 bit integers
* @param a The first integer
* @param b The second integer
* @return The minimum of the two integers
*/
int128_t min2(int128_t a, int128_t b);
/**
* @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);
/**
* @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);
/**
* @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
* @param output The file pointer for output (can be NULL)
*/
void generate_factor_pairs(int128_t* sum, int32_t prime_index, int32_t* exponents,
int128_t* values, int128_t n1, int print_mode, FILE* output);
/**
* @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