1. GNU Multiple Precision library

This module provides a wrapper for the Gnu Multiple Precision Arithmetic library known as gmp. The C++ interface is required for this library, you may need to download it. The library and include files must be available in standard places for the scripting harness to find them.

REQUIRES: -lgmpxx -lgmp

Start python section to cpkgs/target/gmpxx.py[1 /1 ]
     1: #line 16 "./lpsrc/flx_gmp.pak"
     2: execfile("config"+os.sep+"config.py")
     3: try:
     4:   cload(globals(),"target_gmpxx")
     5: except:
     6:   HAVE_GMPXX=TARGET_CXX.check_header_exists(xqt,'gmpxx.h')
     7:   f=cwrite('target_gmpxx')
     8:   pa(f,locals(),"HAVE_GMPXX")
     9:   f.close()
    10:   cload(globals(),"target_gmpxx")
    11: 
End python section to cpkgs/target/gmpxx.py[1]
Start python section to spkgs/gmpxx.py[1 /1 ]
     1: #line 28 "./lpsrc/flx_gmp.pak"
     2: execfile('cpkgs'+os.sep+'target'+os.sep+'gmpxx.py')
     3: if HAVE_GMPXX:
     4:   unit_tests = glob.glob('test/gmp/gmp-*.flx')
     5: 
     6: iscr_source = ['lpsrc/flx_gmp.pak']
     7: weaver_directory = 'doc/gmp/'
     8: 
End python section to spkgs/gmpxx.py[1]
Start data section to config/gmpxx.fpc[1 /1 ]
     1: requires_slibs: -lgmp
     2: requires_dlibs: -lgmp
     3: provides_dlib: -lgmpxx
     4: provides_slib: -lgmpxx
     5: 
End data section to config/gmpxx.fpc[1]
Start data section to lib/flx_gmp.flx[1 /1 ]
     1: // THIS WRAPPER IS FFAU .. it is NOT LGPL licenced
     2: // This is because the wrapper was hand written from
     3: // scratch .. it was NOT derived from any LGPL headers
     4: // Code LINKED against libgmp, however, may be governed
     5: // by the LGPL licence, since the object files ARE
     6: // derived from gmp.h
     7: 
     8: header "#include <cstdio>";
     9: header gmpxx_h = """
    10: #include <gmpxx.h>
    11: namespace flx { namespace gmp {
    12: extern mpz_class lcm(mpz_class const&,mpz_class const&);
    13: extern mpz_class gcd(mpz_class const&,mpz_class const&);
    14: }}
    15: """;
    16: 
    17: body gmpxx_lcm = """
    18: namespace flx { namespace gmp {
    19: mpz_class lcm(mpz_class const &a, mpz_class const &b)
    20: {
    21:   mpz_t r; mpz_init(r);
    22:   mpz_lcm(r,a.get_mpz_t(),b.get_mpz_t());
    23:   return mpz_class(r);
    24: }
    25: }}
    26: """;
    27: 
    28: body gmpxx_gcd = """
    29: namespace flx { namespace gmp {
    30: mpz_class gcd(mpz_class const &a, mpz_class const &b)
    31: {
    32:   mpz_t r; mpz_init(r);
    33:   mpz_gcd(r,a.get_mpz_t(),b.get_mpz_t());
    34:   return mpz_class(r);
    35: }
    36: }}
    37: """;
    38: 
    39: module Gmp
    40: {
    41:   requires gmpxx_h;
    42:   requires package "gmpxx";
    43:   type mpz='mpz_class';
    44:   type mpq='mpq_class';
    45:   type mpf='mpf_class';
    46:   fun add:mpz*mpz->mpz="$1+$2";
    47:   fun sub:mpz*mpz->mpz="$1-$2";
    48:   fun mul:mpz*mpz->mpz="$1*$2";
    49:   fun div:mpz*mpz->mpz="$1/$2";
    50:   fun neg:mpz->mpz="-$1";
    51:   fun abs:mpz->mpz="abs($1)";
    52:   fun sgn:mpz->int="sgn($1)";
    53:   fun sqrt:mpz->mpz="sqrt($1)";
    54:   fun cmp:mpz*mpz->int="cmp($1,$2)";
    55:   proc fprint: ostream * mpz="*$1<<$2;";
    56:   fun eq:mpz*mpz->bool="$1==2";
    57:   fun ne:mpz*mpz->bool="$1!=$2";
    58:   fun lt:mpz*mpz->bool="$1<$2";
    59:   fun le:mpz*mpz->bool="$1<=$2";
    60:   fun gt:mpz*mpz->bool="$1>$2";
    61:   fun ge:mpz*mpz->bool="$1>=$2";
    62:   fun add:mpq*mpq->mpq="$1+$2";
    63:   fun sub:mpq*mpq->mpq="$1-$2";
    64:   fun mul:mpq*mpq->mpq="$1*$2";
    65:   fun div:mpq*mpq->mpq="$1/$2";
    66:   fun neg:mpq->mpq="-$1";
    67:   fun abs:mpq->mpq="abs($1)";
    68:   fun sgn:mpq->int="sgn($1)";
    69:   fun sqrt:mpq->mpq="sqrt($1)";
    70:   fun cmp:mpq*mpq->int="cmp($1,$2)";
    71:   proc fprint: ostream * mpq="*$1<<$2;";
    72:   fun eq:mpq*mpq->bool="$1==2";
    73:   fun ne:mpq*mpq->bool="$1!=$2";
    74:   fun lt:mpq*mpq->bool="$1<$2";
    75:   fun le:mpq*mpq->bool="$1<=$2";
    76:   fun gt:mpq*mpq->bool="$1>$2";
    77:   fun ge:mpq*mpq->bool="$1>=$2";
    78:   fun add:mpf*mpf->mpf="$1+$2";
    79:   fun sub:mpf*mpf->mpf="$1-$2";
    80:   fun mul:mpf*mpf->mpf="$1*$2";
    81:   fun div:mpf*mpf->mpf="$1/$2";
    82:   fun neg:mpf->mpf="-$1";
    83:   fun abs:mpf->mpf="abs($1)";
    84:   fun sgn:mpf->int="sgn($1)";
    85:   fun sqrt:mpf->mpf="sqrt($1)";
    86:   fun cmp:mpf*mpf->int="cmp($1,$2)";
    87:   proc fprint: ostream * mpf="*$1<<$2;";
    88:   fun eq:mpf*mpf->bool="$1==2";
    89:   fun ne:mpf*mpf->bool="$1!=$2";
    90:   fun lt:mpf*mpf->bool="$1<$2";
    91:   fun le:mpf*mpf->bool="$1<=$2";
    92:   fun gt:mpf*mpf->bool="$1>$2";
    93:   fun ge:mpf*mpf->bool="$1>=$2";
    94: fun lcm: mpz * mpz -> mpz = "flx::gmp::lcm($1,$2)" requires gmpxx_lcm;
    95: fun gcd: mpz * mpz -> mpz = "flx::gmp::gcd($1,$2)" requires gmpxx_gcd;
    96: fun wedge: mpz * mpz -> mpz = "flx::gmp::lcm($1,$2)" requires gmpxx_lcm;
    97: fun vee: mpz * mpz -> mpz = "flx::gmp::gcd($1,$2)" requires gmpxx_gcd;
    98: 
    99: fun mod: mpz * mpz -> mpz = "$1%$2";
   100: fun mpz_of_int: int -> mpz = "mpz_class($1)";
   101: fun mpq_of_int: int -> mpq = "mpq_class($1)";
   102: fun mpf_of_double: double -> mpf = "mpf_class($1)";
   103: }
End data section to lib/flx_gmp.flx[1]