openGPMP
Open Source Mathematics Package
Public Member Functions | List of all members
gpmp::Basics Class Reference

Arithmetic Operations More...

#include <arithmetic.hpp>

Public Member Functions

int64_t greatest_power (int64_t n, int64_t p)
 Find greatest power of 2 itegers. More...
 
int64_t op_gcd (int64_t x, int64_t y)
 Find Greatest Common Divisor of 2 integers. More...
 

Detailed Description

Arithmetic Operations

Encompasses Arithmetic related operations

Examples
arithmetic.cpp.

Definition at line 101 of file arithmetic.hpp.

Member Function Documentation

◆ greatest_power()

int64_t gpmp::Basics::greatest_power ( int64_t  n,
int64_t  p 
)

Find greatest power of 2 itegers.

Parameters
[in]n: integer 1
[in]p: integer 2
Returns
result : (int)
Examples
arithmetic.cpp.

Definition at line 39 of file arith.cpp.

39  {
40  int64_t result = 0;
41 
42  // Calculate x = n/p + n/(p^2) + n/(p^3) + ....
43  while (n) {
44  n /= p;
45  result += n;
46  }
47  return result;
48 }

Referenced by main().

◆ op_gcd()

int64_t gpmp::Basics::op_gcd ( int64_t  x,
int64_t  y 
)

Find Greatest Common Divisor of 2 integers.

Parameters
[in]x: integer 1
[in]y: integer 2
Returns
result : (int)
Examples
arithmetic.cpp.

Definition at line 50 of file arith.cpp.

50  {
51  if (x < y)
52  return op_gcd(y, x);
53 
54  else if (x % y == 0)
55  return y;
56 
57  else
58  return op_gcd(y, x % y);
59 }
int64_t op_gcd(int64_t x, int64_t y)
Find Greatest Common Divisor of 2 integers.
Definition: arith.cpp:50

Referenced by gpmp::PrimalityTest::carmichael_num(), gpmp::PrimalityTest::ETF(), and main().


The documentation for this class was generated from the following files: