build mpir and mpfr with visual studio 2015 Step2: Build MPIR Step3: Build MPFR Step4: Copy output files to desired directory.(say: C:multiprecision) Step5: MPIR example Step6: MPFR example

  • https://github.com/BrianGladman/mpir
  • https://github.com/BrianGladman/mpfr

unzip as mpir and mpfr respectively(removing-suffix -master, MPFR compilation require the correct path).

Step2: Build MPIR

  • Open “mpirmsvcvs15dll_mpir_gc” project with Visual Studio 2015
  • Build settings: Release, x86
  • Build…
  • Output files locate in: mpirdllWin32Release, which is required for building MPFR

Step3: Build MPFR

  • Open “mpfrbuild.vc15dll_mpfr” project with notepad++, this project is for 2017, so
  • Replace ToolsVersion=”15.0” to ToolsVersion=”14.0” and all “v141” to “v140
  • Open “mpfrbuild.vc15dll_mpfr” project with Visual Studio 2015
  • Build settings: Release, x86
  • Build…
  • Output files locate in: mpfrbuild.vc15dllWin32Release

Step4: Copy output files to desired directory.(say: C:multiprecision)

  • C:multiprecisioninclude : header files
  • C:multiprecisionbin : dll, should be added to system PATH
  • C:multiprecisionlib : lib files

Step5: MPIR example

factorial.cpp:

#include <iostream>
#include <mpirxx.h>

int main (int argc, char *argv[])
{
  mpz_class n;
  n =  1;
  for(int i = 2; i<= 100; i++) {
    n *= i;
    std::cout <<i << "!:" <<  n << std::endl;
  }
  return 0;  
}

namke Makefile:

factorial.exe : factorial.obj C:multiprecisionlibmpir.lib
    cl /[email protected] $**

factorial.obj : factorial.cpp
    cl /EHsc -I"C:multiprecisioninclude" -c factorial.cpp

clean:
    del -f *.obj factorial.exe

Step6: MPFR example

series.cpp

#include <stdio.h>
#include <gmp.h>
#include <mpfr.h>

int main (void)
{
  unsigned int i;
  mpfr_t s, t, u;

  mpfr_init2 (t, 200);
  mpfr_set_d (t, 1.0, MPFR_RNDD);
  mpfr_init2 (s, 200);
  mpfr_set_d (s, 1.0, MPFR_RNDD);
  mpfr_init2 (u, 200);
  for (i = 1; i <= 100; i++) {
      mpfr_mul_ui (t, t, i, MPFR_RNDU);
      mpfr_set_d (u, 1.0, MPFR_RNDD);
      mpfr_div (u, u, t, MPFR_RNDD);
      mpfr_add (s, s, u, MPFR_RNDD);
    }
  printf ("Sum is ");
  mpfr_out_str (stdout, 10, 0, s, MPFR_RNDD);
  putchar ('n');
  mpfr_clear (s);
  mpfr_clear (t);
  mpfr_clear (u);
  mpfr_free_cache ();
  return 0;
}

nmake Makefile:

series.exe : series.obj C:multiprecisionlibmpfr.lib
    cl /[email protected] $**

series.obj : series.cpp
    cl /EHsc -I"C:multiprecisioninclude" -c series.cpp

clean:
    del -f *.obj series.exe