int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: MAIN is the main program for C_INTRINSICS. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 April 2011 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "C_INTRINSICS:\n" ); printf ( " Test the C intrinsic library.\n" ); test_abs ( ); test_acos ( ); test_asin ( ); test_atan ( ); test_atan2 ( ); test_ceil ( ); test_cos ( ); test_cosh ( ); test_exp ( ); test_fabs ( ); test_floor ( ); test_fmod ( ); test_frexp ( ); test_ldexp ( ); test_log ( ); test_log10 ( ); test_modf ( ); test_pow ( ); test_sin ( ); test_sinh ( ); test_sqrt ( ); test_tan ( ); test_tanh ( ); /* Terminate. */ printf ( "\n" ); printf ( "C_INTRINSICS:\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; }
int main(int argc, char *argv[]) { ULONG res = 0; MathIeeeSingTransBase = (BaseType *)OpenLibrary("mathieeesingtrans.library", 34); if(MathIeeeSingTransBase) { PutStr("ok!\n"); test_const(); test_acos(); test_asin(); test_atan(); test_cos(); test_cosh(); test_exp(); test_fieee(); test_log(); test_log10(); test_pow(); test_sin(); test_sincos(); test_sinh(); test_sqrt(); test_tan(); test_tanh(); test_tieee(); CloseLibrary((struct Library *)MathIeeeSingTransBase); } else { PutStr("No mathieeesingtrans.library!\n"); res = 1; } return res; }
static void check_special_pow_si () { mpfr_t a, b; mp_exp_t emin; mpfr_init (a); mpfr_init (b); mpfr_set_str (a, "2E100000000", 10, GMP_RNDN); mpfr_set_si (b, -10, GMP_RNDN); test_pow (b, a, b, GMP_RNDN); if (!MPFR_IS_ZERO(b)) { printf("Pow(2E10000000, -10) failed\n"); mpfr_dump (a); mpfr_dump (b); exit(1); } emin = mpfr_get_emin (); mpfr_set_emin (-10); mpfr_set_si (a, -2, GMP_RNDN); mpfr_pow_si (b, a, -10000, GMP_RNDN); if (!MPFR_IS_ZERO (b)) { printf ("Pow_so (1, -10000) doesn't underflow if emin=-10.\n"); mpfr_dump (a); mpfr_dump (b); exit (1); } mpfr_set_emin (emin); mpfr_clear (a); mpfr_clear (b); }
static char * createGUID() { sodium_init(); unsigned char out[crypto_hash_sha512_BYTES]; unsigned char sk[crypto_sign_SECRETKEYBYTES]; int valid_pow = 0; while (valid_pow == 0){ //Generate a key pair unsigned char pk[crypto_sign_PUBLICKEYBYTES]; unsigned char sk[crypto_sign_SECRETKEYBYTES]; crypto_sign_keypair(pk, sk); //Sign the public key const unsigned char * message = pk; int message_len = crypto_sign_PUBLICKEYBYTES; unsigned char signed_message[crypto_sign_BYTES + message_len]; unsigned long long signed_message_len; crypto_sign(signed_message, &signed_message_len, message, message_len, sk); //Hash the signed key with sha512 crypto_hash_sha512(out, signed_message, signed_message_len); char proof_of_work[32]; memcpy(proof_of_work, &out[32], 32); char * pow = to_hex(proof_of_work, 3); valid_pow = test_pow(pow); } to_hex(sk, 32); return to_hex(sk, 32); }
void main(int argc, char *argv[]) { srand(time(NULL)); /*test_add();*/ /*test_multiply();*/ /*test_divide();*/ test_pow(); /*test_round();*/ }
int main() { int Error(0); Error += test_pow(); Error += test_exp(); Error += test_log(); Error += test_exp2(); Error += test_log2(); Error += test_sqrt(); Error += test_inversesqrt(); return Error; }
int main() { test_cos_det(); test_sin_det(); test_atan2_det(); test_atan2(); test_pow_det(); test_pow_singleton_exp(); test_pow(); test_fmod_det(); test_fmod(); test_sqrt_det(); test_sqrt(); test_exp_det(); test_log_det(); test_log10_det(); test_powf_det(); test_powf_singleton_exp(); test_powf(); test_sqrtf_det(); test_sqrtf(); test_expf_det(); test_logf_det(); test_log10f_det(); test_diff_pow_powf(); test_floor_det(); test_ceil_det(); test_trunc_det(); test_round_det(); test_floor(); test_ceil(); test_trunc(); test_round(); test_floorf_det(); test_ceilf_det(); test_truncf_det(); test_roundf_det(); test_floorf(); test_ceilf(); test_truncf(); test_roundf(); return 0; }
int main(int argc, char** argv) { if (argc != 2) { printf("Usage: %s <opt>\n", argv[0]); printf("\n"); printf("Where <opt> is one of:\n"); printf(" --basic\t test compose, square, cube for 64, 128, mpz, and generic\n"); printf(" --pow\t\t test NAF against DBNS\n"); printf("\n"); return 0; } if (strcmp(argv[1], "--basic") == 0) { test_basic(); } else if (strcmp(argv[1], "--pow") == 0) { test_pow(); } else { printf("Unrecognized command line option\n"); } return 0; }
static void overflows (void) { mpfr_t a, b; /* bug found by Ming J. Tsai <*****@*****.**>, 4 Oct 2003 */ mpfr_init_set_str (a, "5.1e32", 10, GMP_RNDN); mpfr_init (b); test_pow (b, a, a, GMP_RNDN); if (!(mpfr_inf_p (b) && mpfr_sgn (b) > 0)) { printf ("Error for a^a for a=5.1e32\n"); printf ("Expected +Inf, got "); mpfr_out_str (stdout, 10, 0, b, GMP_RNDN); printf ("\n"); exit (1); } mpfr_clear(a); mpfr_clear(b); }
double test_sqrt(double y, double x) { return (test_pow(y, 2) <= x+PRECISION && test_pow(y, 2) >= x-PRECISION) ? y : test_sqrt(((y + (x/y))/2), x); }
static void particular_cases (void) { mpfr_t t[11], r; static const char *name[11] = { "NaN", "+inf", "-inf", "+0", "-0", "+1", "-1", "+2", "-2", "+0.5", "-0.5" }; int i, j; int error = 0; for (i = 0; i < 11; i++) mpfr_init2 (t[i], 2); mpfr_init2 (r, 6); mpfr_set_nan (t[0]); mpfr_set_inf (t[1], 1); mpfr_set_ui (t[3], 0, GMP_RNDN); mpfr_set_ui (t[5], 1, GMP_RNDN); mpfr_set_ui (t[7], 2, GMP_RNDN); mpfr_div_2ui (t[9], t[5], 1, GMP_RNDN); for (i = 1; i < 11; i += 2) mpfr_neg (t[i+1], t[i], GMP_RNDN); for (i = 0; i < 11; i++) for (j = 0; j < 11; j++) { double d; int p; static int q[11][11] = { /* NaN +inf -inf +0 -0 +1 -1 +2 -2 +0.5 -0.5 */ /* NaN */ { 0, 0, 0, 128, 128, 0, 0, 0, 0, 0, 0 }, /* +inf */ { 0, 1, 2, 128, 128, 1, 2, 1, 2, 1, 2 }, /* -inf */ { 0, 1, 2, 128, 128, -1, -2, 1, 2, 1, 2 }, /* +0 */ { 0, 2, 1, 128, 128, 2, 1, 2, 1, 2, 1 }, /* -0 */ { 0, 2, 1, 128, 128, -2, -1, 2, 1, 2, 1 }, /* +1 */ {128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 }, /* -1 */ { 0, 128, 128, 128, 128,-128,-128, 128, 128, 0, 0 }, /* +2 */ { 0, 1, 2, 128, 128, 256, 64, 512, 32, 180, 90 }, /* -2 */ { 0, 1, 2, 128, 128,-256, -64, 512, 32, 0, 0 }, /* +0.5 */ { 0, 2, 1, 128, 128, 64, 256, 32, 512, 90, 180 }, /* -0.5 */ { 0, 2, 1, 128, 128, -64,-256, 32, 512, 0, 0 } }; test_pow (r, t[i], t[j], GMP_RNDN); p = mpfr_nan_p (r) ? 0 : mpfr_inf_p (r) ? 1 : mpfr_cmp_ui (r, 0) == 0 ? 2 : (d = mpfr_get_d (r, GMP_RNDN), (int) (ABS(d) * 128.0)); if (p != 0 && MPFR_SIGN(r) < 0) p = -p; if (p != q[i][j]) { printf ("Error in mpfr_pow for particular case (%s)^(%s) (%d,%d):\n" "got %d instead of %d\n", name[i], name[j], i,j,p, q[i][j]); mpfr_dump (r); error = 1; } } for (i = 0; i < 11; i++) mpfr_clear (t[i]); mpfr_clear (r); if (error) exit (1); }
static void underflows (void) { mpfr_t x, y, z; int err = 0; int inexact; int i; mp_exp_t emin; mpfr_init2 (x, 64); mpfr_init2 (y, 64); mpfr_set_ui (x, 1, GMP_RNDN); mpfr_set_exp (x, mpfr_get_emin()); for (i = 3; i < 10; i++) { mpfr_set_ui (y, i, GMP_RNDN); mpfr_div_2ui (y, y, 1, GMP_RNDN); test_pow (y, x, y, GMP_RNDN); if (!MPFR_IS_FP(y) || mpfr_cmp_ui (y, 0)) { printf ("Error in mpfr_pow for "); mpfr_out_str (stdout, 2, 0, x, GMP_RNDN); printf (" ^ (%d/2)\nGot ", i); mpfr_out_str (stdout, 2, 0, y, GMP_RNDN); printf (" instead of 0.\n"); exit (1); } } mpfr_init2 (z, 55); mpfr_set_str (x, "0.110011010011101001110001110100010000110111101E0", 2, GMP_RNDN); mpfr_set_str (y, "0.101110010011111001011010100011011100111110011E40", 2, GMP_RNDN); mpfr_clear_flags (); inexact = mpfr_pow (z, x, y, GMP_RNDU); if (!mpfr_underflow_p ()) { printf ("Underflow flag is not set for special underflow test.\n"); err = 1; } if (inexact <= 0) { printf ("Ternary value is wrong for special underflow test.\n"); err = 1; } mpfr_set_ui (x, 0, GMP_RNDN); mpfr_nextabove (x); if (mpfr_cmp (x, z) != 0) { printf ("Wrong value for special underflow test.\nGot "); mpfr_out_str (stdout, 2, 0, z, GMP_RNDN); printf ("\ninstead of "); mpfr_out_str (stdout, 2, 2, x, GMP_RNDN); printf ("\n"); err = 1; } if (err) exit (1); /* MPFR currently (2006-08-19) segfaults on the following code (and possibly makes other programs crash due to the lack of memory), because y is converted into an mpz_t, and the required precision is too high. */ mpfr_set_prec (x, 2); mpfr_set_prec (y, 2); mpfr_set_prec (z, 12); mpfr_set_ui_2exp (x, 3, -2, GMP_RNDN); mpfr_set_ui_2exp (y, 1, mpfr_get_emax () - 1, GMP_RNDN); mpfr_clear_flags (); mpfr_pow (z, x, y, GMP_RNDN); if (!mpfr_underflow_p () || MPFR_NOTZERO (z)) { printf ("Underflow test with large y fails.\n"); exit (1); } emin = mpfr_get_emin (); mpfr_set_emin (-256); mpfr_set_prec (x, 2); mpfr_set_prec (y, 2); mpfr_set_prec (z, 12); mpfr_set_ui_2exp (x, 3, -2, GMP_RNDN); mpfr_set_ui_2exp (y, 1, 38, GMP_RNDN); mpfr_clear_flags (); inexact = mpfr_pow (z, x, y, GMP_RNDN); if (!mpfr_underflow_p () || MPFR_NOTZERO (z) || inexact >= 0) { printf ("Bad underflow detection for 0.75^(2^38). Obtained:\n" "Underflow flag... %-3s (should be 'yes')\n" "Zero result...... %-3s (should be 'yes')\n" "Inexact value.... %-3d (should be negative)\n", mpfr_underflow_p () ? "yes" : "no", MPFR_IS_ZERO (z) ? "yes" : "no", inexact); exit (1); } mpfr_set_emin (emin); emin = mpfr_get_emin (); mpfr_set_emin (-256); mpfr_set_prec (x, 2); mpfr_set_prec (y, 40); mpfr_set_prec (z, 12); mpfr_set_ui_2exp (x, 3, -1, GMP_RNDN); mpfr_set_si_2exp (y, -1, 38, GMP_RNDN); for (i = 0; i < 4; i++) { if (i == 2) mpfr_neg (x, x, GMP_RNDN); mpfr_clear_flags (); inexact = mpfr_pow (z, x, y, GMP_RNDN); if (!mpfr_underflow_p () || MPFR_NOTZERO (z) || (i == 3 ? (inexact <= 0) : (inexact >= 0))) { printf ("Bad underflow detection for ("); mpfr_out_str (stdout, 10, 0, x, GMP_RNDN); printf (")^(-2^38-%d). Obtained:\n" "Overflow flag.... %-3s (should be 'no')\n" "Underflow flag... %-3s (should be 'yes')\n" "Zero result...... %-3s (should be 'yes')\n" "Inexact value.... %-3d (should be %s)\n", i, mpfr_overflow_p () ? "yes" : "no", mpfr_underflow_p () ? "yes" : "no", MPFR_IS_ZERO (z) ? "yes" : "no", inexact, i == 3 ? "positive" : "negative"); exit (1); } inexact = mpfr_sub_ui (y, y, 1, GMP_RNDN); MPFR_ASSERTN (inexact == 0); } mpfr_set_emin (emin); mpfr_clears (x, y, z, (void *) 0); }
static void special () { mpfr_t x, y, z, t; mpfr_init2 (x, 53); mpfr_init2 (y, 53); mpfr_init2 (z, 53); mpfr_init2 (t, 2); mpfr_set_ui (x, 2, GMP_RNDN); mpfr_pow_si (x, x, -2, GMP_RNDN); if (mpfr_cmp_ui_2exp (x, 1, -2)) { printf ("Error in pow_si(x,x,-2) for x=2\n"); exit (1); } mpfr_set_ui (x, 2, GMP_RNDN); mpfr_set_si (y, -2, GMP_RNDN); test_pow (x, x, y, GMP_RNDN); if (mpfr_cmp_ui_2exp (x, 1, -2)) { printf ("Error in pow(x,x,y) for x=2, y=-2\n"); exit (1); } mpfr_set_prec (x, 2); mpfr_set_str_binary (x, "1.0e-1"); mpfr_set_prec (y, 53); mpfr_set_str_binary (y, "0.11010110011100101010110011001010100111000001000101110E-1"); mpfr_set_prec (z, 2); test_pow (z, x, y, GMP_RNDZ); mpfr_set_str_binary (x, "1.0e-1"); if (mpfr_cmp (x, z)) { printf ("Error in mpfr_pow (1)\n"); exit (1); } mpfr_set_prec (x, 64); mpfr_set_prec (y, 64); mpfr_set_prec (z, 64); mpfr_set_prec (t, 64); mpfr_set_str_binary (x, "0.111011000111100000111010000101010100110011010000011"); mpfr_set_str_binary (y, "0.111110010100110000011101100011010111000010000100101"); mpfr_set_str_binary (t, "0.1110110011110110001000110100100001001111010011111000010000011001"); test_pow (z, x, y, GMP_RNDN); if (mpfr_cmp (z, t)) { printf ("Error in mpfr_pow for prec=64, rnd=GMP_RNDN\n"); exit (1); } mpfr_set_prec (x, 53); mpfr_set_prec (y, 53); mpfr_set_prec (z, 53); mpfr_set_str (x, "5.68824667828621954868e-01", 10, GMP_RNDN); mpfr_set_str (y, "9.03327850535952658895e-01", 10, GMP_RNDN); test_pow (z, x, y, GMP_RNDZ); if (mpfr_cmp_str1 (z, "0.60071044650456473235")) { printf ("Error in mpfr_pow for prec=53, rnd=GMP_RNDZ\n"); exit (1); } mpfr_set_prec (t, 2); mpfr_set_prec (x, 30); mpfr_set_prec (y, 30); mpfr_set_prec (z, 30); mpfr_set_str (x, "1.00000000001010111110001111011e1", 2, GMP_RNDN); mpfr_set_str (t, "-0.5", 10, GMP_RNDN); test_pow (z, x, t, GMP_RNDN); mpfr_set_str (y, "1.01101001111010101110000101111e-1", 2, GMP_RNDN); if (mpfr_cmp (z, y)) { printf ("Error in mpfr_pow for prec=30, rnd=GMP_RNDN\n"); exit (1); } mpfr_set_prec (x, 21); mpfr_set_prec (y, 21); mpfr_set_prec (z, 21); mpfr_set_str (x, "1.11111100100001100101", 2, GMP_RNDN); test_pow (z, x, t, GMP_RNDZ); mpfr_set_str (y, "1.01101011010001100000e-1", 2, GMP_RNDN); if (mpfr_cmp (z, y)) { printf ("Error in mpfr_pow for prec=21, rnd=GMP_RNDZ\n"); printf ("Expected "); mpfr_out_str (stdout, 2, 0, y, GMP_RNDN); printf ("\nGot "); mpfr_out_str (stdout, 2, 0, z, GMP_RNDN); printf ("\n"); exit (1); } /* From http://www.terra.es/personal9/ismaeljc/hall.htm */ mpfr_set_prec (x, 113); mpfr_set_prec (y, 2); mpfr_set_prec (z, 169); mpfr_set_str1 (x, "6078673043126084065007902175846955"); mpfr_set_ui_2exp (y, 3, -1, GMP_RNDN); test_pow (z, x, y, GMP_RNDZ); if (mpfr_cmp_str1 (z, "473928882491000966028828671876527456070714790264144")) { printf ("Error in mpfr_pow for 6078673043126084065007902175846955"); printf ("^(3/2), GMP_RNDZ\nExpected "); printf ("4.73928882491000966028828671876527456070714790264144e50"); printf ("\nGot "); mpfr_out_str (stdout, 10, 0, z, GMP_RNDN); printf ("\n"); exit (1); } test_pow (z, x, y, GMP_RNDU); if (mpfr_cmp_str1 (z, "473928882491000966028828671876527456070714790264145")) { printf ("Error in mpfr_pow for 6078673043126084065007902175846955"); printf ("^(3/2), GMP_RNDU\nExpected "); printf ("4.73928882491000966028828671876527456070714790264145e50"); printf ("\nGot "); mpfr_out_str (stdout, 10, 0, z, GMP_RNDN); printf ("\n"); exit (1); } mpfr_set_inf (x, 1); mpfr_set_prec (y, 2); mpfr_set_str_binary (y, "1E10"); test_pow (z, x, y, GMP_RNDN); MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); mpfr_set_inf (x, -1); test_pow (z, x, y, GMP_RNDN); MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); mpfr_set_prec (y, 10); mpfr_set_str_binary (y, "1.000000001E9"); test_pow (z, x, y, GMP_RNDN); MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_NEG(z)); mpfr_set_str_binary (y, "1.000000001E8"); test_pow (z, x, y, GMP_RNDN); MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); mpfr_set_inf (x, -1); mpfr_set_prec (y, 2 * mp_bits_per_limb); mpfr_set_ui (y, 1, GMP_RNDN); mpfr_mul_2exp (y, y, mp_bits_per_limb - 1, GMP_RNDN); /* y = 2^(mp_bits_per_limb - 1) */ test_pow (z, x, y, GMP_RNDN); MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); mpfr_nextabove (y); test_pow (z, x, y, GMP_RNDN); /* y = 2^(mp_bits_per_limb - 1) + epsilon */ MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); mpfr_nextbelow (y); mpfr_div_2exp (y, y, 1, GMP_RNDN); mpfr_nextabove (y); test_pow (z, x, y, GMP_RNDN); /* y = 2^(mp_bits_per_limb - 2) + epsilon */ MPFR_ASSERTN(mpfr_inf_p (z) && MPFR_IS_POS(z)); mpfr_set_si (x, -1, GMP_RNDN); mpfr_set_prec (y, 2); mpfr_set_str_binary (y, "1E10"); test_pow (z, x, y, GMP_RNDN); MPFR_ASSERTN(mpfr_cmp_ui (z, 1) == 0); /* Check (-0)^(17.0001) */ mpfr_set_prec (x, 6); mpfr_set_prec (y, 640); MPFR_SET_ZERO (x); MPFR_SET_NEG (x); mpfr_set_ui (y, 17, GMP_RNDN); mpfr_nextabove (y); test_pow (z, x, y, GMP_RNDN); MPFR_ASSERTN (MPFR_IS_ZERO (z) && MPFR_IS_POS (z)); mpfr_clear (x); mpfr_clear (y); mpfr_clear (z); mpfr_clear (t); }
static void check_inexact (mp_prec_t p) { mpfr_t x, y, z, t; unsigned long u; mp_prec_t q; int inexact, cmp; int rnd; mpfr_init2 (x, p); mpfr_init (y); mpfr_init (z); mpfr_init (t); mpfr_random (x); u = randlimb () % 2; for (q = 2; q <= p; q++) for (rnd = 0; rnd < GMP_RND_MAX; rnd++) { mpfr_set_prec (y, q); mpfr_set_prec (z, q + 10); mpfr_set_prec (t, q); inexact = mpfr_pow_ui (y, x, u, (mp_rnd_t) rnd); cmp = mpfr_pow_ui (z, x, u, (mp_rnd_t) rnd); if (mpfr_can_round (z, q + 10, (mp_rnd_t) rnd, (mp_rnd_t) rnd, q)) { cmp = mpfr_set (t, z, (mp_rnd_t) rnd) || cmp; if (mpfr_cmp (y, t)) { printf ("results differ for u=%lu rnd=%s\n", u, mpfr_print_rnd_mode ((mp_rnd_t) rnd)); printf ("x="); mpfr_print_binary (x); puts (""); printf ("y="); mpfr_print_binary (y); puts (""); printf ("t="); mpfr_print_binary (t); puts (""); printf ("z="); mpfr_print_binary (z); puts (""); exit (1); } if (((inexact == 0) && (cmp != 0)) || ((inexact != 0) && (cmp == 0))) { printf ("Wrong inexact flag for p=%u, q=%u, rnd=%s\n", (unsigned int) p, (unsigned int) q, mpfr_print_rnd_mode ((mp_rnd_t) rnd)); printf ("expected %d, got %d\n", cmp, inexact); printf ("u=%lu x=", u); mpfr_print_binary (x); puts (""); printf ("y="); mpfr_print_binary (y); puts (""); exit (1); } } } /* check exact power */ mpfr_set_prec (x, p); mpfr_set_prec (y, p); mpfr_set_prec (z, p); mpfr_set_ui (x, 4, GMP_RNDN); mpfr_set_str (y, "0.5", 10, GMP_RNDN); test_pow (z, x, y, GMP_RNDZ); mpfr_clear (x); mpfr_clear (y); mpfr_clear (z); mpfr_clear (t); }
int main(int argc, char *argv[]) { int ans; char *str, *strout; fmpz_poly_t zpoly; fmpz_poly_q_t qpoly1; mpz_t mpzzero, mpzone, mpztwo; mpq_t mpqzero, mpqone, mpqtwo, mpqtwoinv; FLINT_TEST_INIT(state); flint_printf("all... "); fflush(stdout); /* Accessing numerator and denominator ***********************************/ fmpz_poly_q_init(qpoly1); fmpz_poly_q_set_str(qpoly1, "2 -1 1/2 0 1"); str = "2 -1 1"; strout = fmpz_poly_get_str(fmpz_poly_q_numref(qpoly1)); ans = !strcmp(str, strout); if (!ans) { flint_printf("test_numref: failed\n"); flint_printf(" Expected \"%s\", got \"%s\"\n", str, strout); flint_printf(" qpoly1 = \""), fmpz_poly_q_print(qpoly1), flint_printf("\"\n"); abort(); } fmpz_poly_q_clear(qpoly1); flint_free(strout); fmpz_poly_q_init(qpoly1); fmpz_poly_q_set_str(qpoly1, "2 -1 1/2 0 1"); str = "2 0 1"; strout = fmpz_poly_get_str(fmpz_poly_q_denref(qpoly1)); ans = !strcmp(str, strout); if (!ans) { flint_printf("test_denref: failed\n"); flint_printf(" Expected \"%s\", got \"%s\"\n", str, strout); abort(); } fmpz_poly_q_clear(qpoly1); flint_free(strout); fmpz_poly_q_init(qpoly1); fmpz_poly_init(zpoly); fmpz_poly_q_set_str(qpoly1, "2 -1 1/2 0 1"); fmpz_poly_set(zpoly, fmpz_poly_q_numref(qpoly1)); str = "2 -1 1"; strout = fmpz_poly_get_str(zpoly); ans = !strcmp(str, strout); if (!ans) { flint_printf("test_get_num: failed\n"); flint_printf(" Expected \"%s\", got \"%s\"\n", str, strout); abort(); } fmpz_poly_q_clear(qpoly1); fmpz_poly_clear(zpoly); flint_free(strout); fmpz_poly_q_init(qpoly1); fmpz_poly_init(zpoly); fmpz_poly_q_set_str(qpoly1, "2 -1 1/2 0 1"); fmpz_poly_set(zpoly, fmpz_poly_q_denref(qpoly1)); str = "2 0 1"; strout = fmpz_poly_get_str(zpoly); ans = !strcmp(str, strout); if (!ans) { flint_printf("test_get_den: failed\n"); flint_printf(" Expected \"%s\", got \"%s\"\n", str, strout); abort(); } fmpz_poly_q_clear(qpoly1); fmpz_poly_clear(zpoly); flint_free(strout); fmpz_poly_q_init(qpoly1); fmpz_poly_init(zpoly); fmpz_poly_q_set_str(qpoly1, "1 1/1 1"); fmpz_poly_set_str(zpoly, "2 0 1"); fmpz_poly_set(fmpz_poly_q_numref(qpoly1), zpoly); str = "2 0 1"; strout = fmpz_poly_get_str(fmpz_poly_q_numref(qpoly1)); ans = !strcmp(str, strout); if (!ans) { flint_printf("test_set_num: failed\n"); flint_printf(" Expected \"%s\", got \"%s\"\n", str, strout); abort(); } fmpz_poly_q_clear(qpoly1); fmpz_poly_clear(zpoly); flint_free(strout); fmpz_poly_q_init(qpoly1); fmpz_poly_init(zpoly); fmpz_poly_q_set_str(qpoly1, "1 1/1 1"); fmpz_poly_set_str(zpoly, "2 0 1"); fmpz_poly_set(fmpz_poly_q_denref(qpoly1), zpoly); str = "2 0 1"; strout = fmpz_poly_get_str(fmpz_poly_q_denref(qpoly1)); ans = !strcmp(str, strout); if (!ans) { flint_printf("test_set_den: failed\n"); flint_printf(" Expected \"%s\", got \"%s\"\n", str, strout); abort(); } fmpz_poly_q_clear(qpoly1); fmpz_poly_clear(zpoly); flint_free(strout); /* Canonicalise **********************************************************/ fmpz_poly_q_init(qpoly1); str = "2 -1 1/2 0 1"; fmpz_poly_q_set_str(qpoly1, str); strout = fmpz_poly_q_get_str(qpoly1); ans = !strcmp(str, strout); if (!ans) { flint_printf("test_canonicalize: failed\n"); flint_printf(" Expected \"%s\", got \"%s\"\n", str, strout); abort(); } fmpz_poly_q_clear(qpoly1); flint_free(strout); fmpz_poly_q_init(qpoly1); str = "2 -1 -1/2 0 1"; fmpz_poly_q_set_str(qpoly1, "2 1 1/2 0 -1"); strout = fmpz_poly_q_get_str(qpoly1); ans = !strcmp("2 -1 -1/2 0 1", strout); if (!ans) { flint_printf("test_canonicalize: failed\n"); flint_printf(" Expected \"%s\", got \"%s\"\n", str, strout); abort(); } flint_free(strout); fmpz_poly_q_clear(qpoly1); /* Initialization, memory management and basic operations ****************/ test_set("0", "0"); test_set("0/1 1", "0"); test_set("3 -1 0 1/2 0 1", "3 -1 0 1/2 0 1"); test_set("3 -1 0 1/2 1 1", "2 -1 1"); test_set_si(-1, "1 -1"); test_set_si(13, "1 13"); test_set_si(0, "0"); test_swap("3 -1 0 1/2 0 1", "1 2/1 3", "1 2/1 3", "3 -1 0 1/2 0 1"); test_zero("0", "0"); test_zero("0/1 1", "0"); test_zero("3 -1 0 1/2 0 1", "0"); test_neg("0", "0"); test_neg("1 1/1 2", "1 -1/1 2"); test_neg("3 -1 0 1/2 0 1", "3 1 0 -1/2 0 1"); test_inv("1 1/1 2", "1 2"); test_inv("3 -1 0 1/2 0 1", "2 0 1/3 -1 0 1"); test_inv("3 -1 0 -1/2 0 1", "2 0 -1/3 1 0 1"); test_inv_inplace("1 1/1 2", "1 2"); test_inv_inplace("3 -1 0 1/2 0 1", "2 0 1/3 -1 0 1"); test_inv_inplace("3 -1 0 -1/2 0 1", "2 0 -1/3 1 0 1"); test_is_zero("0", 1); test_is_zero("0/1 1", 1); test_is_zero("3 -1 0 1/2 0 1", 0); test_is_zero("3 -1 0 1/2 1 1", 0); test_is_one("0", 0); test_is_one("0/1 1", 0); test_is_one("1 1/1 1", 1); test_is_one("2 1 1/2 1 1", 1); test_is_one("3 -1 0 1/2 0 1", 0); test_equal("1 1/1 2", "1 1/1 2", 1); test_equal("1 1/1 2", "1 1/1 2", 1); test_equal("3 -1 0 1/2 1 1", "2 -1 1", 1); test_equal("3 -1 0 1/2 -1 1", "2 -1 1", 0); /* Addition and subtraction **********************************************/ test_add("3 1 0 1/2 0 1", "2 0 -1/3 1 0 1", "5 1 0 1 0 1/4 0 1 0 1"); test_add("3 -1 0 1/2 1 1", "1 2/2 -1 1", "3 3 -2 1/2 -1 1"); test_add("0/2 1 1", "1 2/1 1", "1 2"); test_add("1 -3/1 4", "0/3 1 0 1", "1 -3/1 4"); test_add("2 1 1/1 1", "2 -1 1/1 1", "2 0 2"); test_add("2 1 1/2 0 1", "2 2 1/2 -1 1", "3 -1 2 2/3 0 -1 1"); test_add("2 -1 1/2 2 1", "3 4 4 1/2 1 1", "4 7 12 7 1/3 2 3 1"); test_add("2 1 1/2 -1 1", "2 1 1", "3 0 1 1/2 -1 1"); test_add("1 1/2 1 1", "2 0 1/2 1 1", "1 1"); test_add("2 1 1/3 4 -4 1", "1 1/2 -2 1", "2 -1 2/3 4 -4 1"); test_add("3 0 1 1/3 1 2 1", "2 0 -1/2 1 1", "0"); test_add("2 1 1/2 0 1", "2 -1 1/2 0 1", "1 2"); test_add("1 1/3 3 5 2", "1 1/3 6 7 2", "1 1/3 2 3 1"); test_add_in_place1("3 1 0 1/2 0 1", "2 0 -1/3 1 0 1", "5 1 0 1 0 1/4 0 1 0 1"); test_add_in_place1("3 -1 0 1/2 1 1", "1 2/2 -1 1", "3 3 -2 1/2 -1 1"); test_add_in_place1("0/2 1 1", "1 2/1 1", "1 2"); test_add_in_place1("1 -3/1 4", "0/3 1 0 1", "1 -3/1 4"); test_add_in_place1("2 1 1/1 1", "2 -1 1/1 1", "2 0 2"); test_add_in_place1("2 1 1/2 0 1", "2 2 1/2 -1 1", "3 -1 2 2/3 0 -1 1"); test_add_in_place1("2 -1 1/2 2 1", "3 4 4 1/2 1 1", "4 7 12 7 1/3 2 3 1"); test_add_in_place1("2 1 1/2 -1 1", "2 1 1", "3 0 1 1/2 -1 1"); test_add_in_place1("1 1/2 1 1", "2 0 1/2 1 1", "1 1"); test_add_in_place1("2 1 1/3 4 -4 1", "1 1/2 -2 1", "2 -1 2/3 4 -4 1"); test_add_in_place1("3 0 1 1/3 1 2 1", "2 0 -1/2 1 1", "0"); test_add_in_place1("2 1 1/2 0 1", "2 -1 1/2 0 1", "1 2"); test_add_in_place2("3 1 0 1/2 0 1", "2 0 -1/3 1 0 1", "5 1 0 1 0 1/4 0 1 0 1"); test_add_in_place2("3 -1 0 1/2 1 1", "1 2/2 -1 1", "3 3 -2 1/2 -1 1"); test_add_in_place2("0/2 1 1", "1 2/1 1", "1 2"); test_add_in_place2("1 -3/1 4", "0/3 1 0 1", "1 -3/1 4"); test_add_in_place2("2 1 1/1 1", "2 -1 1/1 1", "2 0 2"); test_add_in_place2("2 1 1/2 0 1", "2 2 1/2 -1 1", "3 -1 2 2/3 0 -1 1"); test_add_in_place2("2 -1 1/2 2 1", "3 4 4 1/2 1 1", "4 7 12 7 1/3 2 3 1"); test_add_in_place2("2 1 1/2 -1 1", "2 1 1", "3 0 1 1/2 -1 1"); test_add_in_place2("1 1/2 1 1", "2 0 1/2 1 1", "1 1"); test_add_in_place2("2 1 1/3 4 -4 1", "1 1/2 -2 1", "2 -1 2/3 4 -4 1"); test_add_in_place2("3 0 1 1/3 1 2 1", "2 0 -1/2 1 1", "0"); test_add_in_place2("2 1 1/2 0 1", "2 -1 1/2 0 1", "1 2"); test_add_in_place3("2 1 1", "2 2 2"); test_add_in_place3("2 1 1/1 2", "2 1 1"); test_sub("3 1 0 1/2 0 1", "2 0 -1/3 1 0 1", "5 1 0 3 0 1/4 0 1 0 1"); test_sub("3 -1 0 1/2 1 1", "1 2/2 -1 1", "3 -1 -2 1/2 -1 1"); test_sub("0/2 1 1", "1 2/1 1", "1 -2"); test_sub("1 -3/1 4", "0/3 1 0 1", "1 -3/1 4"); test_sub("2 1 1/1 1", "2 -1 1/1 1", "1 2"); test_sub("2 1 1/2 0 1", "2 2 1/2 -1 1", "2 -1 -2/3 0 -1 1"); test_sub("2 -1 1/2 2 1", "3 4 4 1/2 1 1", "4 -9 -12 -5 -1/3 2 3 1"); test_sub("2 -1 1/2 0 1", "1 1", "1 -1/2 0 1"); test_sub("3 1 0 1/2 0 1", "2 0 -1/3 1 0 1", "5 1 0 3 0 1/4 0 1 0 1"); test_sub("3 -1 0 1/2 1 1", "1 2/2 -1 1", "3 -1 -2 1/2 -1 1"); test_sub("0/2 1 1", "1 2/1 1", "1 -2"); test_sub("1 -3/1 4", "0/3 1 0 1", "1 -3/1 4"); test_sub("2 1 1/1 1", "2 -1 1/1 1", "1 2"); test_sub("2 1 1/2 0 1", "2 2 1/2 -1 1", "2 -1 -2/3 0 -1 1"); test_sub("2 -1 1/2 2 1", "3 4 4 1/2 1 1", "4 -9 -12 -5 -1/3 2 3 1"); test_sub("2 1 1/2 -1 1", "2 1 1", "3 2 1 -1/2 -1 1"); test_sub("1 1/2 1 1", "2 0 1/2 1 1", "2 1 -1/2 1 1"); test_sub("2 1 1/3 4 -4 1", "1 1/2 -2 1", "1 3/3 4 -4 1"); test_sub("3 0 1 1/3 1 2 1", "2 0 -1/2 1 1", "2 0 2/2 1 1"); test_sub("2 1 1/2 0 1", "2 -1 1/2 0 1", "1 2/2 0 1"); test_sub("1 1/3 3 5 2", "1 1/3 6 7 2", "1 1/4 6 13 9 2"); test_sub("2 1 1/2 0 2", "2 1 1/2 0 2", "0"); test_sub("2 -1 2/2 0 1", "2 -1 1/2 0 1", "1 1"); test_sub_in_place1("3 1 0 1/2 0 1", "2 0 -1/3 1 0 1", "5 1 0 3 0 1/4 0 1 0 1"); test_sub_in_place1("3 -1 0 1/2 1 1", "1 2/2 -1 1", "3 -1 -2 1/2 -1 1"); test_sub_in_place1("0/2 1 1", "1 2/1 1", "1 -2"); test_sub_in_place1("1 -3/1 4", "0/3 1 0 1", "1 -3/1 4"); test_sub_in_place1("2 1 1/1 1", "2 -1 1/1 1", "1 2"); test_sub_in_place1("2 1 1/2 0 1", "2 2 1/2 -1 1", "2 -1 -2/3 0 -1 1"); test_sub_in_place1("2 -1 1/2 2 1", "3 4 4 1/2 1 1", "4 -9 -12 -5 -1/3 2 3 1"); test_sub_in_place2("3 1 0 1/2 0 1", "2 0 -1/3 1 0 1", "5 1 0 3 0 1/4 0 1 0 1"); test_sub_in_place2("3 -1 0 1/2 1 1", "1 2/2 -1 1", "3 -1 -2 1/2 -1 1"); test_sub_in_place2("0/2 1 1", "1 2/1 1", "1 -2"); test_sub_in_place2("1 -3/1 4", "0/3 1 0 1", "1 -3/1 4"); test_sub_in_place2("2 1 1/1 1", "2 -1 1/1 1", "1 2"); test_sub_in_place2("2 1 1/2 0 1", "2 2 1/2 -1 1", "2 -1 -2/3 0 -1 1"); test_sub_in_place2("2 -1 1/2 2 1", "3 4 4 1/2 1 1", "4 -9 -12 -5 -1/3 2 3 1"); test_sub_in_place3("2 -1 1/2 2 1", "0"); test_addmul("1 1/2 0 2", "2 3 1/1 4", "3 1 0 1/4 -2 0 0 1", "5 -4 3 1 5 1/5 0 -8 0 0 4"); test_submul("1 1/2 0 2", "2 3 1/1 4", "3 1 0 1/4 -2 0 0 1", "5 -4 -3 -1 -1 -1/5 0 -8 0 0 4"); /* Scalar multiplication and devision ************************************/ flint_mpz_init_set_si(mpzzero, 0); flint_mpz_init_set_si(mpzone, 1); flint_mpz_init_set_si(mpztwo, 2); mpq_init(mpqzero); flint_mpq_set_si(mpqzero, 0, 1); mpq_init(mpqone); flint_mpq_set_si(mpqone, 1, 1); mpq_init(mpqtwo); flint_mpq_set_si(mpqtwo, 2, 1); mpq_init(mpqtwoinv); flint_mpq_set_si(mpqtwoinv, 1, 2); test_scalar_mul_si("0", 1, "0"); test_scalar_mul_si("0", 0, "0"); test_scalar_mul_si("1 2", 0, "0"); test_scalar_mul_si("1 1/1 2", -2, "1 -1"); test_scalar_mul_si("2 1 1/2 -2 3", 5, "2 5 5/2 -2 3"); test_scalar_mul_si("2 1 1/2 -2 2", 3, "2 3 3/2 -2 2"); test_scalar_mul_mpz("0", mpzone, "0"); test_scalar_mul_mpz("0", mpzzero, "0"); test_scalar_mul_mpz("1 2", mpzzero, "0"); test_scalar_mul_mpz("1 1/1 2", mpztwo, "1 1"); test_scalar_mul_mpq("0", mpqone, "0"); test_scalar_mul_mpq("0", mpqzero, "0"); test_scalar_mul_mpq("1 2", mpqzero, "0"); test_scalar_mul_mpq("1 1/1 2", mpqtwo, "1 1"); test_scalar_mul_mpq("1 -2/1 1", mpqtwoinv, "1 -1"); test_scalar_div_si("0", 1, "0"); test_scalar_div_si("1 2", 2, "1 1"); test_scalar_div_si("1 1/1 2", -2, "1 -1/1 4"); test_scalar_div_si("3 -5 0 3/2 1 1", 2, "3 -5 0 3/2 2 2"); test_scalar_div_si("3 2 8 4/2 0 1", 3, "3 2 8 4/2 0 3"); test_scalar_div_si("3 2 8 4/2 0 1", -3, "3 -2 -8 -4/2 0 3"); test_scalar_div_si("3 -27 0 9/2 0 1", -3, "3 9 0 -3/2 0 1"); test_scalar_div_mpz("0", mpzone, "0"); test_scalar_div_mpz("1 2", mpztwo, "1 1"); test_scalar_div_mpz("1 1/1 2", mpztwo, "1 1/1 4"); test_scalar_div_mpq("0", mpqone, "0"); test_scalar_div_mpq("1 2", mpqone, "1 2"); test_scalar_div_mpq("1 1/1 2", mpqtwo, "1 1/1 4"); test_scalar_div_mpq("1 -2/1 1", mpqtwoinv, "1 -4"); mpz_clear(mpzzero); mpz_clear(mpzone); mpz_clear(mpztwo); mpq_clear(mpqzero); mpq_clear(mpqone); mpq_clear(mpqtwo); mpq_clear(mpqtwoinv); /* Multiplication, division and powing *********************************/ test_mul("3 1 0 1/2 0 1", "2 0 -1/3 1 0 1", "1 -1"); test_mul("3 -1 0 1/2 1 1", "1 2/2 -1 1", "1 2"); test_mul("0/2 1 1", "1 2/1 1", "0"); test_mul("1 -3/1 4", "0/3 1 0 1", "0"); test_mul("2 1 1/1 1", "2 -1 1/1 1", "3 -1 0 1"); test_mul("2 1 1/2 0 1", "2 2 1/2 -1 1", "3 2 3 1/3 0 -1 1"); test_mul("2 -1 1/2 2 1", "3 4 4 1/2 1 1", "3 -2 1 1/2 1 1"); test_mul_in_place1("3 1 0 1/2 0 1", "2 0 -1/3 1 0 1", "1 -1"); test_mul_in_place1("3 -1 0 1/2 1 1", "1 2/2 -1 1", "1 2"); test_mul_in_place1("0/2 1 1", "1 2/1 1", "0"); test_mul_in_place1("1 -3/1 4", "0/3 1 0 1", "0"); test_mul_in_place1("2 1 1/1 1", "2 -1 1/1 1", "3 -1 0 1"); test_mul_in_place1("2 1 1/2 0 1", "2 2 1/2 -1 1", "3 2 3 1/3 0 -1 1"); test_mul_in_place1("2 -1 1/2 2 1", "3 4 4 1/2 1 1", "3 -2 1 1/2 1 1"); test_mul_in_place2("3 1 0 1/2 0 1", "2 0 -1/3 1 0 1", "1 -1"); test_mul_in_place2("3 -1 0 1/2 1 1", "1 2/2 -1 1", "1 2"); test_mul_in_place2("0/2 1 1", "1 2/1 1", "0"); test_mul_in_place2("1 -3/1 4", "0/3 1 0 1", "0"); test_mul_in_place2("2 1 1/1 1", "2 -1 1/1 1", "3 -1 0 1"); test_mul_in_place2("2 1 1/2 0 1", "2 2 1/2 -1 1", "3 2 3 1/3 0 -1 1"); test_mul_in_place2("2 -1 1/2 2 1", "3 4 4 1/2 1 1", "3 -2 1 1/2 1 1"); test_mul_in_place3("2 0 1/2 1 1", "3 0 0 1/3 1 2 1"); test_div("3 -1 0 1/1 2", "2 1 1/1 1", "2 -1 1/1 2"); test_div("0/2 1 1", "2 1 1/1 1", "0"); test_div("3 -1 0 1/1 4", "2 -1 -1/1 2", "2 1 -1/1 2"); test_div("2 1 1", "2 1 -1/2 1 -1", "2 1 1"); test_div("2 1 1/3 4 4 1", "2 -1 1/3 6 5 1", "3 3 4 1/3 -2 1 1"); test_div_in_place1("3 -1 0 1/1 2", "2 1 1/1 1", "2 -1 1/1 2"); test_div_in_place1("0/2 1 1", "2 1 1/1 1", "0"); test_div_in_place1("3 -1 0 1/1 4", "2 -1 -1/1 2", "2 1 -1/1 2"); test_div_in_place1("2 1 1", "2 1 -1/2 1 -1", "2 1 1"); test_div_in_place1("2 1 1/3 4 4 1", "2 -1 1/3 6 5 1", "3 3 4 1/3 -2 1 1"); test_div_in_place1("0", "1 2/2 3 5", "0"); test_div_in_place2("3 -1 0 1/1 2", "2 1 1/1 1", "2 -1 1/1 2"); test_div_in_place2("0/2 1 1", "2 1 1/1 1", "0"); test_div_in_place2("3 -1 0 1/1 4", "2 -1 -1/1 2", "2 1 -1/1 2"); test_div_in_place2("2 1 1", "2 1 -1/2 1 -1", "2 1 1"); test_div_in_place2("2 1 1/3 4 4 1", "2 -1 1/3 6 5 1", "3 3 4 1/3 -2 1 1"); test_div_in_place3("3 -1 0 1/1 2", "1 1"); test_pow("2 0 -1/1 2", 3, "4 0 0 0 -1/1 8"); test_pow("0", 0, "1 1"); test_pow("2 1 -1", 0, "1 1"); test_pow("2 1 1/2 0 1", 0, "1 1"); /* Derivative ************************************************************/ test_derivative("0", "0"); test_derivative("1 2", "0"); test_derivative("1 -1/1 2", "0"); test_derivative("2 0 1", "1 1"); test_derivative("3 1 0 1", "2 0 2"); test_derivative("1 1/2 0 1", "1 -1/3 0 0 1"); test_derivative("2 2 1/2 -1 1", "1 -3/3 1 -2 1"); test_derivative("2 0 1/3 1 2 1", "2 1 -1/4 1 3 3 1"); /* Bug which allowed constant factors */ test_derivative("3 5 1 -2/2 10 2", "3 0 -10 -1/3 25 10 1"); /* Evaluation ************************************************************/ test_evaluate("1 1/1 2", -2, 3, "1/2"); test_evaluate("3 1 0 1/2 0 1", -1, 2, "-5/2"); test_evaluate("2 3 1/2 -1 1", 1, 1, "P"); test_evaluate("2 3 1/2 -1 1", 2, 3, "-11"); test_evaluate("2 3 1/2 -1 2", 1, 2, "P"); test_evaluate("2 1 1/2 -1 1", 2, 1, "3"); /* String methods ********************************************************/ fmpz_poly_q_init(qpoly1); ans = fmpz_poly_q_set_str(qpoly1, "1 3/xyz"); if ((ans == 0) || !fmpz_poly_q_is_zero(qpoly1)) { flint_printf("test_set_str: failed\n"); abort(); } fmpz_poly_q_clear(qpoly1); fmpz_poly_q_init(qpoly1); ans = fmpz_poly_q_set_str(qpoly1, "abc/1 3"); if ((ans == 0) || !fmpz_poly_q_is_zero(qpoly1)) { flint_printf("test_set_str: failed\n"); abort(); } fmpz_poly_q_clear(qpoly1); fmpz_poly_q_init(qpoly1); ans = fmpz_poly_q_set_str(qpoly1, "abc/xyz"); if ((ans == 0) || !fmpz_poly_q_is_zero(qpoly1)) { flint_printf("test_set_str: failed\n"); abort(); } fmpz_poly_q_clear(qpoly1); test_get_str_pretty("1 -3", "-3"); test_get_str_pretty("3 1 2 1", "t^2+2*t+1"); test_get_str_pretty("1 -2/2 1 1", "-2/(t+1)"); test_get_str_pretty("2 1 1/2 -1 1", "(t+1)/(t-1)"); test_get_str_pretty("2 1 1/1 2", "(t+1)/2"); test_get_str_pretty("1 1/1 2", "1/2"); FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int test_main(int, char *[]) { BOOST_CHECK(test_pow(2, 3, 8, 27, 3)); BOOST_CHECK(test_pow(2, 3, 16, 81, 4)); BOOST_CHECK(test_pow(-3, 2, -27, 8, 3)); BOOST_CHECK(test_pow(-3, 2, 0, 81, 4)); BOOST_CHECK(test_pow(-3, -2, -27, -8, 3)); BOOST_CHECK(test_pow(-3, -2, 16, 81, 4)); BOOST_CHECK(test_pow(2, 4, 1./64, 1./8, -3)); BOOST_CHECK(test_pow(2, 4, 1./256, 1./16, -4)); BOOST_CHECK(test_pow(-4, -2, -1./8, -1./64, -3)); BOOST_CHECK(test_pow(-4, -2, 1./256, 1./16, -4)); BOOST_CHECK(test_pow(2, 3, 1, 1, 0)); BOOST_CHECK(test_pow(-3, 2, 1, 1, 0)); BOOST_CHECK(test_pow(-3, -2, 1, 1, 0)); # ifdef __BORLANDC__ ::detail::ignore_warnings(); # endif return 0; }
double test_pow(double x, int p) { return p == 0 ? 1 : x * test_pow(x, p-1); }
int main() { test_acos(); test_asin(); test_atan(); test_atan2(); test_ceil(); test_cos(); test_cosh(); test_exp(); test_fabs(); test_floor(); test_fmod(); test_frexp(); test_ldexp(); test_log(); test_log10(); test_modf(); test_pow(); test_sin(); test_sinh(); test_sqrt(); test_tan(); test_tanh(); test_signbit(); test_fpclassify(); test_isfinite(); test_isinf(); test_isnan(); test_isnormal(); test_isgreater(); test_isgreaterequal(); test_isless(); test_islessequal(); test_islessgreater(); test_isunordered(); test_acosh(); test_asinh(); test_atanh(); test_cbrt(); test_copysign(); test_erf(); test_erfc(); test_exp2(); test_expm1(); test_fdim(); test_fma(); test_fmax(); test_fmin(); test_hypot(); test_ilogb(); test_lgamma(); test_llrint(); test_llround(); test_log1p(); test_log2(); test_logb(); test_lrint(); test_lround(); test_nan(); test_nearbyint(); test_nextafter(); test_nexttoward(); test_remainder(); test_remquo(); test_rint(); test_round(); test_scalbln(); test_scalbn(); test_tgamma(); test_trunc(); }
int test_main(int, char *[]) { BOOST_TEST(test_pow(2, 3, 8, 27, 3)); BOOST_TEST(test_pow(2, 3, 16, 81, 4)); BOOST_TEST(test_pow(-3, 2, -27, 8, 3)); BOOST_TEST(test_pow(-3, 2, 0, 81, 4)); BOOST_TEST(test_pow(-3, -2, -27, -8, 3)); BOOST_TEST(test_pow(-3, -2, 16, 81, 4)); BOOST_TEST(test_pow(2, 4, 1./64, 1./8, -3)); BOOST_TEST(test_pow(2, 4, 1./256, 1./16, -4)); BOOST_TEST(test_pow(-4, -2, -1./8, -1./64, -3)); BOOST_TEST(test_pow(-4, -2, 1./256, 1./16, -4)); BOOST_TEST(test_pow(2, 3, 1, 1, 0)); BOOST_TEST(test_pow(-3, 2, 1, 1, 0)); BOOST_TEST(test_pow(-3, -2, 1, 1, 0)); return 0; }