Error referencing function powMod in BigNumber

Hi,

In the following sample (and useless) code fragment:

#include <bcconfig.h>
#include <BigNumber.h>
#include <number.h>

void setup()
{
  BigNumber x;
  BigNumber y (2);
  BigNumber z (2);
  
  BigNumber a;
  
  a = x/y;
  
  a = sqrt(x);

  x = a.powMod (y, z);
 
}

void loop()
{
}

the function powMod generates this error:
sketch_aug03a:15: error: ‘class BigNumber’ has no member named ‘powMod’.

Please note this is a test fragment only. It is not meant to run.

Looking at Bignum .h and Bignum.cpp there seems to be a function powMod

BigNumber.h:
// raise number by power, modulus modulus
BigNumber powMod (const BigNumber power, const BigNumber & modulus) const;

BigNumber.cpp:
// raise number by power, modulus modulus
BigNumber BigNumber::powMod (const BigNumber power, const BigNumber & modulus) const
{
BigNumber result;
bc_raisemod (num_, power.num_, modulus.num_, &result.num_, scale_);
return result;
}

This question is derived from a post by Nick Gammon on his site:
Gammon Forum : Electronics : Microprocessors : Arduino generating prime numbers.

See the post and the code posted Fri 29 Nov 2013 at 11:42PM (UTC). I am trying to use this code which generates huge prime numbers and uses BigNumbers.

There is this function Miller:

bool Miller(BigNumber source, int certainty)
{

  if (source == 2 || source == 3)
    return true;
  if (source < two || source % two == 0)
    return false;
  
  BigNumber d = source - one;
  int s = 0;

  while(d % two == 0)
  {
    d /= two;
    s += one;
  }

  BigNumber a;

  for(int i = 0; i < certainty; i++)
  {
    do
    {
      rng (a);
    } 
    while(a < two || a >= source - two);

    BigNumber x = a.powMod (d, source);
    if(x == one || x == source - one)
      continue;

    for(int r = 1; r < s; r++)
    {
      x = x.powMod(two, source);
      if(x == one)
        return false;
      if(x == source - one)
        break;
    }

    if(x != source - one)
      return false;
  }

  return true;
}  // end of Miller

which also fails to compile for the same reason. It is something I have missed I am sure as I trust this code source.

What am I missing?

Regards, Fred.

  a = x/y;

x is uninitialized.

  a = sqrt(x);

x is still uninitialized.

When I compile your example, I get:

Binary sketch size: 10,568 bytes (of a 32,256 byte maximum)

Sounds like you are using an older/different version of BigNumber library to
the one you think you are using...

Thanks MarkT. Somehow I mis-installed the library. I uninstalled the IDE, deleted the directory and re-installed. Then I added the library using the Sketch -> Import Library -> Add Library function. Worked like a bought one. Thanks. Must watch that I was using that. I was just copying libraries into the library folder as was done in older versions off the IDE.

Thanks PaulS, but I did note in the post that the fragment shown was never meant to run, just to highlight the compile problem. While I do forget to initialize variables from time to time I do appreciate the importance. It is probably never good practice to show uninitialized variables.

Regards, Fred.