int main (int argc, char **argv) { mpfr_t a; mpfr_t b; mpfr_t c; char * lpsz; mpfr_exp_t exp = 0; int num = 100 * MPFR_VERSION_MAJOR + 10 * MPFR_VERSION_MINOR + MPFR_VERSION_PATCHLEVEL; if (!(num >= 312 && strlen(mpfr_get_version()) > 0)) { return 1; } mpfr_inits2(32, a, b, c, NULL); mpfr_set_str(a, "3.1415926535897932384626433832795028841971693993751058209749445923078164062862", 10, MPFR_RNDN); mpfr_set_si(b, 12345678); mpfr_mul(c, a, b, MPFR_RNDN); lpsz = mpfr_get_str(NULL, &exp, 10, 13, c, MPFR_RNDN); if (strcmp(lpsz, "3878509131250") != 0) { return 1; } return 0; }
int main (void) { char buffer[256]; const char *version; test_version (); version = mpfr_get_version (); /* This test is disabled when a suffix (e.g. -dev) has been defined. */ #if 1 sprintf (buffer, "%d.%d.%d", MPFR_VERSION_MAJOR, MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL); if (strcmp (buffer, version) != 0) { /* All the other problems should have been detected by test_version. */ printf ("Incorrect MPFR version! (%s header vs %s library)\n" "This error should have never occurred and may be due " "to a corrupted 'mpfr.h'.\n", buffer, version); exit (1); } #endif if (__GNU_MP_VERSION_PATCHLEVEL != 0) sprintf (buffer, "%d.%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL); else sprintf (buffer, "%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR); /* In some cases, it may be acceptable to have different versions for the header and the library, in particular when shared libraries are used (e.g., after a bug-fix upgrade of the library). Versioning takes care of that, as long as the user has a correct configuration (which is not always the case, hence the following warning). Moreover MPFR uses GMP internals, which may lead to incompatibilities even though GMP's public interface has not changed (the following warning is useful in that case too). */ if (strcmp (buffer, gmp_version) != 0) printf ("The versions of gmp.h (%s) and libgmp (%s) do not seem to " "match.\nThis may lead to errors, in particular with MPFR. " "If some tests fail,\nplease check that first. As we are not " "sure, we do not regard this as\nan error.\n", buffer, gmp_version); return 0; }
int main (void) { unsigned long c; mp_limb_t t[4] = { -1, -1, -1, -1 }; #if defined(__cplusplus) printf ("A C++ compiler is used.\n"); #endif printf ("GMP ..... Library: %-12s Header: %d.%d.%d\n", gmp_version, __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL); printf ("MPFR .... Library: %-12s Header: %s (based on %d.%d.%d)\n", mpfr_get_version (), MPFR_VERSION_STRING, MPFR_VERSION_MAJOR, MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL); printf ("MPFR patches: %s\n\n", mpfr_get_patches ()); #ifdef __GMP_CC printf ("__GMP_CC = \"%s\"\n", __GMP_CC); #endif #ifdef __GMP_CFLAGS printf ("__GMP_CFLAGS = \"%s\"\n", __GMP_CFLAGS); #endif printf ("GMP_LIMB_BITS = %d\n", (int) GMP_LIMB_BITS); printf ("GMP_NAIL_BITS = %d\n", (int) GMP_NAIL_BITS); printf ("GMP_NUMB_BITS = %d\n", (int) GMP_NUMB_BITS); printf ("mp_bits_per_limb = %d\n", (int) mp_bits_per_limb); printf ("sizeof(mp_limb_t) = %d\n", (int) sizeof(mp_limb_t)); if (mp_bits_per_limb != GMP_LIMB_BITS) printf ("Warning! mp_bits_per_limb != GMP_LIMB_BITS\n"); if (GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT) printf ("Warning! GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT\n"); c = mpn_popcount (t, 1); printf ("The GMP library expects %lu bits in a mp_limb_t.\n", c); if (c != GMP_LIMB_BITS) printf ("Warning! This is different from GMP_LIMB_BITS!\n" "Different ABI caused by a GMP library upgrade?\n"); failure_test (); return 0; }
void test_version (void) { const char *version; /* VL: I get the following error on an OpenSUSE machine, and changing the value of shlibpath_overrides_runpath in the libtool file from 'no' to 'yes' fixes the problem. */ version = mpfr_get_version (); if (strcmp (MPFR_VERSION_STRING, version) == 0) { char buffer[16]; int i; sprintf (buffer, "%d.%d.%d", MPFR_VERSION_MAJOR, MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL); for (i = 0; buffer[i] == version[i]; i++) if (buffer[i] == '\0') return; if (buffer[i] == '\0' && version[i] == '-') return; printf ("MPFR_VERSION_MAJOR.MPFR_VERSION_MINOR.MPFR_VERSION_PATCHLEVEL" " (%s)\nand MPFR_VERSION_STRING (%s) do not match!\nIt seems " "that the mpfr.h file has been corrupted.\n", buffer, version); exit (1); } printf ("Incorrect MPFR version! (%s header vs %s library)\n" "Nothing else has been tested since for this reason,\n" "any other test may fail. Please fix this one first.\n\n" "You can try to avoid this problem by changing the value of\n" "shlibpath_overrides_runpath in the libtool file and rebuild\n" "MPFR (make clean && make && make check).\n" "Otherwise this error may be due to a corrupted mpfr.h, an\n" "incomplete build (try to rebuild MPFR from scratch and/or\n" "use 'make clean'), or something wrong in the system.\n", MPFR_VERSION_STRING, version); exit (1); }
int main (void) { printf ("GMP: include %d.%d.%d, lib %s\n", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL, gmp_version); printf ("MPFR: include %s, lib %s\n", MPFR_VERSION_STRING, mpfr_get_version ()); printf ("MPC: include %s, lib %s\n", MPC_VERSION_STRING, mpc_get_version ()); if (strcmp (mpc_get_version (), MPC_VERSION_STRING) != 0) { printf ("Error: header and library do not match\n" "mpc_get_version: \"%s\"\nMPC_VERSION_STRING: \"%s\"\n", mpc_get_version(), MPC_VERSION_STRING); exit (1); } return 0; }
int main (void) { unsigned long c; mp_limb_t t[4] = { -1, -1, -1, -1 }; #if defined(__cplusplus) printf ("A C++ compiler is used.\n"); #endif printf ("GMP ..... Library: %-12s Header: %d.%d.%d\n", gmp_version, __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL); printf ("MPFR .... Library: %-12s Header: %s (based on %d.%d.%d)\n", mpfr_get_version (), MPFR_VERSION_STRING, MPFR_VERSION_MAJOR, MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL); #if MPFR_VERSION_MAJOR >= 3 printf ("MPFR features: TLS = %s, decimal = %s", mpfr_buildopt_tls_p () ? "yes" : "no", mpfr_buildopt_decimal_p () ? "yes" : "no"); # if MPFR_VERSION_MAJOR > 3 || MPFR_VERSION_MINOR >= 1 printf (", GMP internals = %s\nMPFR tuning: %s", mpfr_buildopt_gmpinternals_p () ? "yes" : "no", mpfr_buildopt_tune_case ()); # endif printf ("\n"); #endif printf ("MPFR patches: %s\n\n", mpfr_get_patches ()); #ifdef __GMP_CC printf ("__GMP_CC = \"%s\"\n", __GMP_CC); #endif #ifdef __GMP_CFLAGS printf ("__GMP_CFLAGS = \"%s\"\n", __GMP_CFLAGS); #endif printf ("GMP_LIMB_BITS = %d\n", (int) GMP_LIMB_BITS); printf ("GMP_NAIL_BITS = %d\n", (int) GMP_NAIL_BITS); printf ("GMP_NUMB_BITS = %d\n", (int) GMP_NUMB_BITS); printf ("mp_bits_per_limb = %d\n", (int) mp_bits_per_limb); printf ("sizeof(mp_limb_t) = %d\n", (int) sizeof(mp_limb_t)); if (mp_bits_per_limb != GMP_LIMB_BITS) printf ("Warning! mp_bits_per_limb != GMP_LIMB_BITS\n"); if (GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT) printf ("Warning! GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT\n"); c = mpn_popcount (t, 1); printf ("The GMP library expects %lu bits in a mp_limb_t.\n", c); if (c != GMP_LIMB_BITS) printf ("Warning! This is different from GMP_LIMB_BITS!\n" "Different ABI caused by a GMP library upgrade?\n"); printf ("\n"); printf ("sizeof(mpfr_prec_t) = %d (%s type)\n", (int) sizeof(mpfr_prec_t), SIGNED_STR((mpfr_prec_t) -1)); #if MPFR_VERSION_MAJOR >= 3 printf ("sizeof(mpfr_exp_t) = %d (%s type)\n", (int) sizeof(mpfr_exp_t), SIGNED_STR((mpfr_exp_t) -1)); #endif #ifdef _MPFR_PREC_FORMAT printf ("_MPFR_PREC_FORMAT = %d\n", (int) _MPFR_PREC_FORMAT); #endif /* Note: "long" is sufficient for all current _MPFR_PREC_FORMAT values (1, 2, 3). Thus we do not need to depend on ISO C99 or later. */ printf ("MPFR_PREC_MIN = %ld (%s)\n", (long) MPFR_PREC_MIN, SIGNED (MPFR_PREC_MIN)); printf ("MPFR_PREC_MAX = %ld (%s)\n", (long) MPFR_PREC_MAX, SIGNED (MPFR_PREC_MAX)); #ifdef _MPFR_EXP_FORMAT printf ("_MPFR_EXP_FORMAT = %d\n", (int) _MPFR_EXP_FORMAT); #endif printf ("sizeof(mpfr_t) = %d\n", (int) sizeof(mpfr_t)); failure_test (); return 0; }
void print_lib_version() { printf("GMP : %s\n", gmp_version); printf("MPFR library: %-12s\n\n", mpfr_get_version()); }
/* Various version checks. A mismatch on the GMP version is not regarded as fatal. A mismatch on the MPFR version is regarded as fatal, since this means that we would not check the MPFR library that has just been built (the goal of "make check") but a different library that is already installed, i.e. any test result would be meaningless; in such a case, we exit immediately with an error (exit status = 1). Return value: 0 for no errors, 1 in case of any non-fatal error. */ int test_version (void) { const char *version; char buffer[256]; int err = 0; #ifndef MPFR_USE_MINI_GMP sprintf (buffer, "%d.%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL); if (strcmp (buffer, gmp_version) != 0 && (__GNU_MP_VERSION_PATCHLEVEL != 0 || (sprintf (buffer, "%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR), strcmp (buffer, gmp_version) != 0))) err = 1; #endif /* In some cases, it may be acceptable to have different versions for the header and the library, in particular when shared libraries are used (e.g., after a bug-fix upgrade of the library, and versioning ensures that this can be done only when the binary interface is compatible). However, when recompiling software like here, this should never happen (except if GMP has been upgraded between two "make check" runs, but there's no reason for that). A difference between the versions of gmp.h and libgmp probably indicates either a bad configuration or some other inconsistency in the development environment, and it is better to fail (in particular for automatic installations). */ if (err) { printf ("ERROR! The versions of gmp.h (%s) and libgmp (%s) do not " "match.\nThe possible causes are:\n", buffer, gmp_version); printf (" * A bad configuration in your include/library search paths.\n" " * An inconsistency in the include/library search paths of\n" " your development environment; an example:\n" " https://gcc.gnu.org/ml/gcc-help/2010-11/msg00359.html\n" " * GMP has been upgraded after the first \"make check\".\n" " In such a case, try again after a \"make clean\".\n" " * A new or non-standard version naming is used in GMP.\n" " In this case, a patch may already be available on the\n" " MPFR web site. Otherwise please report the problem.\n"); printf ("In the first two cases, this may lead to errors, in particular" " with MPFR.\nIf some other tests fail, please solve that" " problem first.\n"); } /* VL: I get the following error on an OpenSUSE machine, and changing the value of shlibpath_overrides_runpath in the libtool file from 'no' to 'yes' fixes the problem. */ version = mpfr_get_version (); if (strcmp (MPFR_VERSION_STRING, version) == 0) { char buffer[16]; int i; sprintf (buffer, "%d.%d.%d", MPFR_VERSION_MAJOR, MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL); for (i = 0; buffer[i] == version[i]; i++) if (buffer[i] == '\0') return err; if (buffer[i] == '\0' && version[i] == '-') return err; printf ("%sMPFR_VERSION_MAJOR.MPFR_VERSION_MINOR.MPFR_VERSION_PATCHLEVEL" " (%s)\nand MPFR_VERSION_STRING (%s) do not match!\nIt seems " "that the mpfr.h file has been corrupted.\n", err ? "\n" : "", buffer, version); } else printf ( "%sIncorrect MPFR version! (%s header vs %s library)\n" "Nothing else has been tested since for this reason, any other test\n" "may fail. Please fix this problem first, as suggested below. It\n" "probably comes from libtool (included in the MPFR tarball), which\n" "is responsible for setting up the search paths depending on the\n" "platform, or automake.\n" " * On some platforms such as Solaris, $LD_LIBRARY_PATH overrides\n" " the rpath, and if the MPFR library is already installed in a\n" " $LD_LIBRARY_PATH directory, you typically get this error. Do\n" " not use $LD_LIBRARY_PATH on such platforms; it may also break\n" " other things.\n" " * Then look at http://www.mpfr.org/mpfr-current/ for any update.\n" " * Try again on a completely clean source (some errors might come\n" " from a previous build or previous source changes).\n" " * If the error still occurs, you can try to change the value of\n" " shlibpath_overrides_runpath ('yes' or 'no') in the \"libtool\"\n" " file and rebuild MPFR (make clean && make && make check). You\n" " may want to report the problem to the libtool and/or automake\n" " developers, with the effect of this change.\n", err ? "\n" : "", MPFR_VERSION_STRING, version); /* Note about $LD_LIBRARY_PATH under Solaris: * https://en.wikipedia.org/wiki/Rpath#Solaris_ld.so * This cause has been confirmed by a user who got this error. */ exit (1); }
#ifdef DARWIN #include <crt_externs.h> #define environ (*_NSGetEnviron()) #else extern char **environ; #endif #include <vector> int qore_trace = 0; int debug = 0; int qore_library_options = QLO_NONE; qore_license_t qore_license; const QoreStringMaker mpfrInfo("runtime: %s built with: %s (%d.%d.%d)", mpfr_get_version(), MPFR_VERSION_STRING, MPFR_VERSION_MAJOR, MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL); // static locks for openssl typedef std::vector<QoreThreadLock*> mutex_vec_t; static mutex_vec_t q_openssl_mutex_list; static unsigned long q_openssl_id_function(void) { #ifdef _Q_WINDOWS return GetCurrentThreadId(); #else return (unsigned long)pthread_self(); #endif } static void q_openssl_locking_function(int mode, int n, const char* file, int line) {
void print_welcome_message(FILE *OUT) /***************************************************************\ * USAGE: print welcome message * \***************************************************************/ { int i, max, count[3] = {0, 0, 0}; // count the number of characeters in each message count[0] = snprintf(NULL, 0, "alphaCertified v%s (%s)\n", VERSION_STRING, DATE_STRING); count[1] = snprintf(NULL, 0, "Jonathan D. Hauenstein and Frank Sottile\n"); count[2] = snprintf(NULL, 0, "GMP v%d.%d.%d & MPFR v%s\n\n", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL, mpfr_get_version()); // find the maximum max = count[0]; if (max < count[1]) max = count[1]; if (max < count[2]) max = count[2]; fprintf(OUT, "\n"); // pad and then print each line count[0] = (max - count[0]) / 2 + 2; for (i = 0; i < count[0]; i++) fprintf(OUT, " "); fprintf(OUT, "alphaCertified v%s (%s)\n", VERSION_STRING, DATE_STRING); count[1] = (max - count[1]) / 2 + 2; for (i = 0; i < count[1]; i++) fprintf(OUT, " "); fprintf(OUT, "Jonathan D. Hauenstein and Frank Sottile\n"); count[2] = (max - count[2]) / 2 + 2; for (i = 0; i < count[2]; i++) fprintf(OUT, " "); fprintf(OUT, "GMP v%d.%d.%d & MPFR v%s\n\n", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL, mpfr_get_version()); return; }
void print_lib_version() { PRINT(my_rank, "GMP : %s\n", gmp_version); PRINT(my_rank, "MPFR library: %-12s\n\n", mpfr_get_version ()); }
int main (void) { unsigned long c; mp_limb_t t[4]; int i; /* Casts are for C++ compilers. */ for (i = 0; i < (int) (sizeof (t) / sizeof (mp_limb_t)); i++) t[i] = (mp_limb_t) -1; /**************** Information about the C implementation ****************/ /* This is useful, as this can affect the behavior of MPFR. */ #define COMP "Compiler: " #ifdef __INTEL_COMPILER # ifdef __VERSION__ # define ICCV " [" __VERSION__ "]" # else # define ICCV "" # endif printf (COMP "ICC %d.%d.%d" ICCV "\n", __INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE); #elif (defined(__GNUC__) || defined(__clang__)) && defined(__VERSION__) # ifdef __clang__ # define COMP2 COMP # else # define COMP2 COMP "GCC " # endif printf (COMP2 "%s\n", __VERSION__); #endif #if defined(__STDC__) || defined(__STDC_VERSION__) printf ("C/C++: __STDC__ = " #if defined(__STDC__) MAKE_STR(__STDC__) #else "undef" #endif ", __STDC_VERSION__ = " #if defined(__STDC_VERSION__) MAKE_STR(__STDC_VERSION__) #else "undef" #endif #if defined(__cplusplus) ", C++" #endif "\n"); #endif #if defined(__GNUC__) printf ("GNU compatibility: __GNUC__ = " MAKE_STR(__GNUC__) ", __GNUC_MINOR__ = " #if defined(__GNUC_MINOR__) MAKE_STR(__GNUC_MINOR__) #else "undef" #endif "\n"); #endif #if defined(__ICC) || defined(__INTEL_COMPILER) printf ("Intel compiler: __ICC = " #if defined(__ICC) MAKE_STR(__ICC) #else "undef" #endif ", __INTEL_COMPILER = " #if defined(__INTEL_COMPILER) MAKE_STR(__INTEL_COMPILER) #else "undef" #endif "\n"); #endif #if defined(_WIN32) || defined(_MSC_VER) printf ("MS Windows: _WIN32 = " #if defined(_WIN32) MAKE_STR(_WIN32) #else "undef" #endif ", _MSC_VER = " #if defined(_MSC_VER) MAKE_STR(_MSC_VER) #else "undef" #endif "\n"); #endif #if defined(__GLIBC__) printf ("GNU C library: __GLIBC__ = " MAKE_STR(__GLIBC__) ", __GLIBC_MINOR__ = " #if defined(__GLIBC_MINOR__) MAKE_STR(__GLIBC_MINOR__) #else "undef" #endif "\n"); #endif printf ("\n"); /************************************************************************/ #if defined(__MPIR_VERSION) printf ("MPIR .... Library: %-12s Header: %d.%d.%d\n", mpir_version, __MPIR_VERSION, __MPIR_VERSION_MINOR, __MPIR_VERSION_PATCHLEVEL); #else printf ("GMP ..... Library: %-12s Header: %d.%d.%d\n", gmp_version, __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL); #endif printf ("MPFR .... Library: %-12s Header: %s (based on %d.%d.%d)\n", mpfr_get_version (), MPFR_VERSION_STRING, MPFR_VERSION_MAJOR, MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL); printf ("MPFR features: TLS = %s, decimal = %s", mpfr_buildopt_tls_p () ? "yes" : "no", mpfr_buildopt_decimal_p () ? "yes" : "no"); #if MPFR_VERSION_MAJOR > 3 || MPFR_VERSION_MINOR >= 1 printf (", GMP internals = %s\nMPFR tuning: %s", mpfr_buildopt_gmpinternals_p () ? "yes" : "no", mpfr_buildopt_tune_case ()); #endif /* 3.1 */ printf ("\n"); patches (); printf ("\n"); #ifdef __GMP_CC printf ("__GMP_CC = \"%s\"\n", __GMP_CC); #endif #ifdef __GMP_CFLAGS printf ("__GMP_CFLAGS = \"%s\"\n", __GMP_CFLAGS); #endif printf ("GMP_LIMB_BITS = %d\n", (int) GMP_LIMB_BITS); printf ("GMP_NAIL_BITS = %d\n", (int) GMP_NAIL_BITS); printf ("GMP_NUMB_BITS = %d\n", (int) GMP_NUMB_BITS); printf ("mp_bits_per_limb = %d\n", (int) mp_bits_per_limb); printf ("sizeof(mp_limb_t) = %d\n", (int) sizeof(mp_limb_t)); if (mp_bits_per_limb != GMP_LIMB_BITS) printf ("Warning! mp_bits_per_limb != GMP_LIMB_BITS\n"); if (GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT) printf ("Warning! GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT\n"); c = mpn_popcount (t, 1); printf ("The GMP library expects %lu bits in a mp_limb_t.\n", c); if (c != GMP_LIMB_BITS) printf ("Warning! This is different from GMP_LIMB_BITS!\n" "Different ABI caused by a GMP library upgrade?\n"); printf ("\n"); printf ("sizeof(mpfr_prec_t) = %d (%s type)\n", (int) sizeof(mpfr_prec_t), SIGNED_STR((mpfr_prec_t) -1)); printf ("sizeof(mpfr_exp_t) = %d (%s type)\n", (int) sizeof(mpfr_exp_t), SIGNED_STR((mpfr_exp_t) -1)); #ifdef _MPFR_PREC_FORMAT printf ("_MPFR_PREC_FORMAT = %d\n", (int) _MPFR_PREC_FORMAT); #endif /* Note: "long" is sufficient for all current _MPFR_PREC_FORMAT values (1, 2, 3). Thus we do not need to depend on ISO C99 or later. */ printf ("MPFR_PREC_MIN = %ld (%s)\n", (long) MPFR_PREC_MIN, SIGNED (MPFR_PREC_MIN)); printf ("MPFR_PREC_MAX = %ld (%s)\n", (long) MPFR_PREC_MAX, SIGNED (MPFR_PREC_MAX)); #ifdef _MPFR_EXP_FORMAT printf ("_MPFR_EXP_FORMAT = %d\n", (int) _MPFR_EXP_FORMAT); #endif printf ("sizeof(mpfr_t) = %d\n", (int) sizeof(mpfr_t)); printf ("sizeof(mpfr_ptr) = %d\n", (int) sizeof(mpfr_ptr)); failure_test (); return 0; }
SEXP R_mpfr_get_version(void) { return mkString(mpfr_get_version()); }
int main(int argc, char *argv[]) { char const *program=rasqal_basename(*argv); int failures=0; rasqal_xsd_decimal a; rasqal_xsd_decimal b; rasqal_xsd_decimal *result; rasqal_xsd_decimal *result2; double result_d; char *result_s; int result_i; const long a_long = 1234567890L; const double a_double = 1234567890e0; const char* b_string = "123456789012345678"; const char* expected_a_plus_b = "123456790246913568"; const char* expected_a_plus_b_minus_b = "1234567890"; const char* expected_a_plus_b_minus_b_minus_a = "0"; const char* expected_negative_b = "-123456789012345678"; int expected_a_compare_b= -1; int expected_a_equals_b= 0; rasqal_world *world; world = rasqal_new_world(); #ifdef RASQAL_DECIMAL_MPFR fprintf(stderr, "%s: Using MPFR %s\n", program, mpfr_get_version()); #endif #ifdef RASQAL_DECIMAL_GMP #ifdef HAVE_GMP_VERSION fprintf(stderr, "%s: Using GMP %s\n", program, gmp_version); #else fprintf(stderr, "%s: Using GMP version unknown\n", program); #endif #endif #ifdef RASQAL_DECIMAL_NONE fprintf(stderr, "%s: Using double\n", program); #endif #ifdef RASQAL_DECIMAL_NONE #define FAIL_LABEL #define FAIL failures++ #else #define FAIL_LABEL tidy: #define FAIL failures++; goto tidy #endif rasqal_xsd_decimal_init(&a); rasqal_xsd_decimal_init(&b); result = rasqal_new_xsd_decimal(world); result2 = rasqal_new_xsd_decimal(world); if(!result || !result2) { fprintf(stderr, "%s: rasqal_new_xsd_decimal() failed\n", program); FAIL; } rasqal_xsd_decimal_set_long(&a, a_long); rasqal_xsd_decimal_set_string(&b, b_string); result_d=rasqal_xsd_decimal_get_double(&a); if(result_d != a_double) { fprintf(stderr, "FAILED: a=%f expected %f\n", result_d, a_double); FAIL; } result_s=rasqal_xsd_decimal_as_string(&b); if(strcmp(result_s, b_string)) { fprintf(stderr, "FAILED: b=%s expected %s\n", result_s, b_string); FAIL; } /* result = a+b */ rasqal_xsd_decimal_add(result, &a, &b); result_s=rasqal_xsd_decimal_as_string(result); if(strcmp(result_s, expected_a_plus_b)) { fprintf(stderr, "FAILED: a+b=%s expected %s\n", result_s, expected_a_plus_b); FAIL; } /* result2 = result-b */ rasqal_xsd_decimal_subtract(result2, result, &b); result_s=rasqal_xsd_decimal_as_string(result2); if(strcmp(result_s, expected_a_plus_b_minus_b)) { fprintf(stderr, "FAILED: (a+b)-b=%s expected %s\n", result_s, expected_a_plus_b_minus_b); FAIL; } /* result = result2-a */ rasqal_xsd_decimal_subtract(result, result2, &a); result_s=rasqal_xsd_decimal_as_string(result); if(strcmp(result_s, expected_a_plus_b_minus_b_minus_a)) { fprintf(stderr, "FAILED: (a+b)-b-a=%s expected %s\n", result_s, expected_a_plus_b_minus_b_minus_a); FAIL; } result_i=rasqal_xsd_decimal_compare(&a, &b); if((expected_a_compare_b < 0 && result_i >= 0) || (expected_a_compare_b > 0 && result_i <= 0) || (expected_a_compare_b == 0 && result_i != 0)) { fprintf(stderr, "FAILED: a compare b = %d expected %d\n", result_i, expected_a_compare_b); FAIL; } result_i=rasqal_xsd_decimal_equals(&a, &b); if(result_i != expected_a_equals_b) { fprintf(stderr, "FAILED: a equals b = %d expected %d\n", result_i, expected_a_equals_b); FAIL; } /* result2 = -b */ rasqal_xsd_decimal_negate(result, &b); result_s=rasqal_xsd_decimal_as_string(result); if(strcmp(result_s, expected_negative_b)) { fprintf(stderr, "FAILED: -b=%s expected %s\n", result_s, expected_negative_b); FAIL; } FAIL_LABEL rasqal_xsd_decimal_clear(&a); rasqal_xsd_decimal_clear(&b); if(result) rasqal_free_xsd_decimal(result); if(result2) rasqal_free_xsd_decimal(result2); rasqal_free_world(world); #ifdef RASQAL_DECIMAL_NONE if(failures) fprintf(stderr, "%s: ignoring %d failures as RASQAL_DECIMAL_NONE specified\n", program, failures); return 0; #else return failures; #endif }