← Back to team overview

dolfin team mailing list archive

Re: Scons test for GMP

 

> On Tue, October 7, 2008 14:45, Johannes Ring wrote:
>> On Tue, October 7, 2008 14:38, Anders Logg wrote:
>>> I would like to add a test for GMP (gmplib.org). Can someone who knows
the build system add this?
>> I can do that.
>>> We need to check for the header file gmpxx.h and we want to use the
latest GMP (4.2.4). If found and enabled, a variable HAS_GMP should be
defined. The default value of enableGmp should be false.
>> Ok.
>> Do you have a small example program for GMP? It will be useful to add
as
>> a
>> test-program for the pkg-config generator to verify that the selected
compiler will work.
>
> I just used the example found here:
>
> http://www.gnu.org/software/gmp/manual/html_node/Parameter-Conventions.html#Parameter
Conventions
>
This program is in C and doesn't use the C++ wrapper. Here is a small
program that uses both the C types and the C++ classes from GMP.

> I have no idea what it does, but it seems to work. If anyone has a more
suitable test program, please let me know and I will add it to the
pkg-config generator.
>
> Johannes
>

Also, the linker needs the flags -lgmp and -lgmpxx

Benjamin

#include <iostream>
#include <gmpxx.h>

int main (void)
{
  mpz_class integer1("1000000023457323");
  mpz_class integer2("54367543212");
  mpz_class int_result = integer1*integer2;


  std::cout << integer1 << " * " << integer2 << " = " << int_result << std::endl;

  
  mpf_set_default_prec(10000);
  mpf_class float1("68.2365436723453423465434512387678997");
  mpf_class res(1.0);

  for (int i = 0; i < 65; ++i) 
    res = res*float1;

  gmp_printf("%Ff ^65 = %Ff\n", float1.get_mpf_t(), res.get_mpf_t());

  return EXIT_SUCCESS;
}

Follow ups

References