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; }
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; }
static void test_all_exp() { test_exp(zero, one, "0"); test_exp(cent, dec64_new(10100501670841681, -16), "0.01"); test_exp(half, dec64_new(16487212707001281, -16), "0.5"); test_exp(one, e, "1"); test_exp(two, dec64_new(7389056098930650, -15), "2"); test_exp(ten, dec64_new(22026465794806717, -12), "10"); }
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; }
/* expx is the value of exp(X) rounded toward -infinity */ static void check_worst_case (const char *Xs, const char *expxs) { mpfr_t x, y; mpfr_inits2 (53, x, y, (mpfr_ptr) 0); mpfr_set_str1(x, Xs); test_exp(y, x, MPFR_RNDD); if (mpfr_cmp_str1 (y, expxs)) { printf ("exp(x) rounded toward -infinity is wrong\n"); exit(1); } mpfr_set_str1(x, Xs); test_exp(x, x, MPFR_RNDU); mpfr_nexttoinf (y); if (mpfr_cmp(x,y)) { printf ("exp(x) rounded toward +infinity is wrong\n"); exit(1); } mpfr_clears (x, y, (mpfr_ptr) 0); }
/* returns the number of ulp of error */ static void check3 (const char *op, mpfr_rnd_t rnd, const char *res) { mpfr_t x, y; mpfr_inits2 (53, x, y, (mpfr_ptr) 0); /* y negative. If we forget to set the sign in mpfr_exp, we'll see it. */ mpfr_set_si (y, -1, MPFR_RNDN); mpfr_set_str1 (x, op); test_exp (y, x, rnd); if (mpfr_cmp_str1 (y, res) ) { printf ("mpfr_exp failed for x=%s, rnd=%s\n", op, mpfr_print_rnd_mode (rnd)); printf ("expected result is %s, got ", res); mpfr_out_str (stdout, 10, 0, y, MPFR_RNDN); putchar('\n'); exit (1); } mpfr_clears (x, y, (mpfr_ptr) 0); }
/* check sign of inexact flag */ static void check_inexact (void) { mpfr_t x, y; int inexact; mpfr_init2 (x, 53); mpfr_init2 (y, 53); mpfr_set_str_binary (x, "1.0000000000001001000110100100101000001101101011100101e2"); inexact = test_exp (y, x, MPFR_RNDN); if (inexact <= 0) { printf ("Wrong inexact flag (Got %d instead of 1)\n", inexact); exit (1); } mpfr_clear (x); mpfr_clear (y); }
int main(int argc, char *argv[]) { BN_CTX *ctx; BIO *out; char *outfile = NULL; results = 0; argc--; argv++; while (argc >= 1) { if (strcmp(*argv, "-results") == 0) results = 1; else if (strcmp(*argv, "-out") == 0) { if (--argc < 1) break; outfile= *(++argv); } argc--; argv++; } ctx = BN_CTX_new(); if (ctx == NULL) exit(1); out = BIO_new(BIO_s_file()); if (out == NULL) exit(1); if (outfile == NULL) { BIO_set_fp(out, stdout, BIO_NOCLOSE); } else { if (!BIO_write_filename(out, outfile)) { perror(outfile); exit(1); } } if (!results) BIO_puts(out, "obase=16\nibase=16\n"); message(out, "BN_add"); if (!test_add(out)) goto err; (void)BIO_flush(out); message(out, "BN_sub"); if (!test_sub(out)) goto err; (void)BIO_flush(out); message(out, "BN_lshift1"); if (!test_lshift1(out)) goto err; (void)BIO_flush(out); message(out, "BN_lshift (fixed)"); if (!test_lshift(out, ctx, BN_bin2bn(lst, sizeof(lst) - 1, NULL))) goto err; (void)BIO_flush(out); message(out, "BN_lshift"); if (!test_lshift(out, ctx, NULL)) goto err; (void)BIO_flush(out); message(out, "BN_rshift1"); if (!test_rshift1(out)) goto err; (void)BIO_flush(out); message(out, "BN_rshift"); if (!test_rshift(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_sqr"); if (!test_sqr(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mul"); if (!test_mul(out)) goto err; (void)BIO_flush(out); message(out, "BN_div"); if (!test_div(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_div_word"); if (!test_div_word(out)) goto err; (void)BIO_flush(out); message(out, "BN_div_recp"); if (!test_div_recp(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mod"); if (!test_mod(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mod_mul"); if (!test_mod_mul(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mont"); if (!test_mont(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mod_exp"); if (!test_mod_exp(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mod_exp_mont_consttime"); if (!test_mod_exp_mont_consttime(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_exp"); if (!test_exp(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_kronecker"); if (!test_kron(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mod_sqrt"); if (!test_sqrt(out, ctx)) goto err; (void)BIO_flush(out); message(out, "Modexp with different sizes"); if (!test_mod_exp_sizes(out, ctx)) goto err; (void)BIO_flush(out); #ifndef OPENSSL_NO_EC2M message(out, "BN_GF2m_add"); if (!test_gf2m_add(out)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod"); if (!test_gf2m_mod(out)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_mul"); if (!test_gf2m_mod_mul(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_sqr"); if (!test_gf2m_mod_sqr(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_inv"); if (!test_gf2m_mod_inv(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_div"); if (!test_gf2m_mod_div(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_exp"); if (!test_gf2m_mod_exp(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_sqrt"); if (!test_gf2m_mod_sqrt(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_solve_quad"); if (!test_gf2m_mod_solve_quad(out, ctx)) goto err; (void)BIO_flush(out); #endif BN_CTX_free(ctx); BIO_free(out); exit(0); err: BIO_puts(out,"1\n"); /* make sure the Perl script fed by bc notices * the failure, see test_bn in test/Makefile.ssl*/ (void)BIO_flush(out); ERR_load_crypto_strings(); ERR_print_errors_fp(stderr); exit(1); }
int main(int argc, char *argv[]) { BN_CTX *ctx; BIO *out; char *outfile=NULL; results = 0; RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */ argc--; argv++; while (argc >= 1) { if (strcmp(*argv,"-results") == 0) results=1; else if (strcmp(*argv,"-out") == 0) { if (--argc < 1) break; outfile= *(++argv); } argc--; argv++; } ctx=BN_CTX_new(); if (ctx == NULL) EXIT(1); out=BIO_new(BIO_s_file()); if (out == NULL) EXIT(1); if (outfile == NULL) { BIO_set_fp(out,stdout,BIO_NOCLOSE); } else { if (!BIO_write_filename(out,outfile)) { perror(outfile); EXIT(1); } } if (!results) BIO_puts(out,"obase=16\nibase=16\n"); message(out,"BN_add"); if (!test_add(out)) goto err; BIO_flush(out); message(out,"BN_sub"); if (!test_sub(out)) goto err; BIO_flush(out); message(out,"BN_lshift1"); if (!test_lshift1(out)) goto err; BIO_flush(out); message(out,"BN_lshift (fixed)"); if (!test_lshift(out,ctx,BN_bin2bn(lst,sizeof(lst)-1,NULL))) goto err; BIO_flush(out); message(out,"BN_lshift"); if (!test_lshift(out,ctx,NULL)) goto err; BIO_flush(out); message(out,"BN_rshift1"); if (!test_rshift1(out)) goto err; BIO_flush(out); message(out,"BN_rshift"); if (!test_rshift(out,ctx)) goto err; BIO_flush(out); message(out,"BN_sqr"); if (!test_sqr(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mul"); if (!test_mul(out)) goto err; BIO_flush(out); message(out,"BN_div"); if (!test_div(out,ctx)) goto err; BIO_flush(out); message(out,"BN_div_recp"); if (!test_div_recp(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mod"); if (!test_mod(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mod_mul"); if (!test_mod_mul(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mont"); if (!test_mont(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mod_exp"); if (!test_mod_exp(out,ctx)) goto err; BIO_flush(out); message(out,"BN_exp"); if (!test_exp(out,ctx)) goto err; BIO_flush(out); message(out,"BN_kronecker"); if (!test_kron(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mod_sqrt"); if (!test_sqrt(out,ctx)) goto err; BIO_flush(out); BN_CTX_free(ctx); BIO_free(out); /**/ EXIT(0); err: BIO_puts(out,"1\n"); /* make sure the Perl script fed by bc notices * the failure, see test_bn in test/Makefile.ssl*/ BIO_flush(out); ERR_load_crypto_strings(); ERR_print_errors_fp(stderr); EXIT(1); return(1); }
static void check_special (void) { mpfr_t x, y, z; mpfr_exp_t emin, emax; emin = mpfr_get_emin (); emax = mpfr_get_emax (); mpfr_init (x); mpfr_init (y); mpfr_init (z); /* check exp(NaN) = NaN */ mpfr_set_nan (x); test_exp (y, x, MPFR_RNDN); if (!mpfr_nan_p (y)) { printf ("Error for exp(NaN)\n"); exit (1); } /* check exp(+inf) = +inf */ mpfr_set_inf (x, 1); test_exp (y, x, MPFR_RNDN); if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0) { printf ("Error for exp(+inf)\n"); exit (1); } /* check exp(-inf) = +0 */ mpfr_set_inf (x, -1); test_exp (y, x, MPFR_RNDN); if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0) { printf ("Error for exp(-inf)\n"); exit (1); } /* Check overflow. Corner case of mpfr_exp_2 */ mpfr_set_prec (x, 64); mpfr_set_emax (MPFR_EMAX_DEFAULT); mpfr_set_emin (MPFR_EMIN_DEFAULT); mpfr_set_str (x, "0.1011000101110010000101111111010100001100000001110001100111001101E30", 2, MPFR_RNDN); mpfr_exp (x, x, MPFR_RNDD); if (mpfr_cmp_str (x, ".1111111111111111111111111111111111111111111111111111111111111111E1073741823", 2, MPFR_RNDN) != 0) { printf ("Wrong overflow detection in mpfr_exp\n"); mpfr_dump (x); exit (1); } /* Check underflow. Corner case of mpfr_exp_2 */ mpfr_set_str (x, "-0.1011000101110010000101111111011111010001110011110111100110101100E30", 2, MPFR_RNDN); mpfr_exp (x, x, MPFR_RNDN); if (mpfr_cmp_str (x, "0.1E-1073741823", 2, MPFR_RNDN) != 0) { printf ("Wrong underflow (1) detection in mpfr_exp\n"); mpfr_dump (x); exit (1); } mpfr_set_str (x, "-0.1011001101110010000101111111011111010001110011110111100110111101E30", 2, MPFR_RNDN); mpfr_exp (x, x, MPFR_RNDN); if (mpfr_cmp_ui (x, 0) != 0) { printf ("Wrong underflow (2) detection in mpfr_exp\n"); mpfr_dump (x); exit (1); } /* Check overflow. Corner case of mpfr_exp_3 */ if (MPFR_PREC_MAX >= MPFR_EXP_THRESHOLD + 10 && MPFR_PREC_MAX >= 64) { /* this ensures that for small MPFR_EXP_THRESHOLD, the following mpfr_set_str conversion is exact */ mpfr_set_prec (x, (MPFR_EXP_THRESHOLD + 10 > 64) ? MPFR_EXP_THRESHOLD + 10 : 64); mpfr_set_str (x, "0.1011000101110010000101111111010100001100000001110001100111001101E30", 2, MPFR_RNDN); mpfr_clear_overflow (); mpfr_exp (x, x, MPFR_RNDD); if (!mpfr_overflow_p ()) { printf ("Wrong overflow detection in mpfr_exp_3\n"); mpfr_dump (x); exit (1); } /* Check underflow. Corner case of mpfr_exp_3 */ mpfr_set_str (x, "-0.1011000101110010000101111111011111010001110011110111100110101100E30", 2, MPFR_RNDN); mpfr_clear_underflow (); mpfr_exp (x, x, MPFR_RNDN); if (!mpfr_underflow_p ()) { printf ("Wrong underflow detection in mpfr_exp_3\n"); mpfr_dump (x); exit (1); } mpfr_set_prec (x, 53); } /* check overflow */ set_emax (10); mpfr_set_ui (x, 7, MPFR_RNDN); test_exp (y, x, MPFR_RNDN); if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0) { printf ("Error for exp(7) for emax=10\n"); exit (1); } set_emax (emax); /* check underflow */ set_emin (-10); mpfr_set_si (x, -9, MPFR_RNDN); test_exp (y, x, MPFR_RNDN); if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0) { printf ("Error for exp(-9) for emin=-10\n"); printf ("Expected +0\n"); printf ("Got "); mpfr_print_binary (y); puts (""); exit (1); } set_emin (emin); /* check case EXP(x) < -precy */ mpfr_set_prec (y, 2); mpfr_set_str_binary (x, "-0.1E-3"); test_exp (y, x, MPFR_RNDD); if (mpfr_cmp_ui_2exp (y, 3, -2)) { printf ("Error for exp(-1/16), prec=2, RNDD\n"); printf ("expected 0.11, got "); mpfr_dump (y); exit (1); } test_exp (y, x, MPFR_RNDZ); if (mpfr_cmp_ui_2exp (y, 3, -2)) { printf ("Error for exp(-1/16), prec=2, RNDZ\n"); printf ("expected 0.11, got "); mpfr_dump (y); exit (1); } mpfr_set_str_binary (x, "0.1E-3"); test_exp (y, x, MPFR_RNDN); if (mpfr_cmp_ui (y, 1)) { printf ("Error for exp(1/16), prec=2, RNDN\n"); exit (1); } test_exp (y, x, MPFR_RNDU); if (mpfr_cmp_ui_2exp (y, 3, -1)) { printf ("Error for exp(1/16), prec=2, RNDU\n"); exit (1); } /* bug reported by Franky Backeljauw, 28 Mar 2003 */ mpfr_set_prec (x, 53); mpfr_set_prec (y, 53); mpfr_set_str_binary (x, "1.1101011000111101011110000111010010101001101001110111e28"); test_exp (y, x, MPFR_RNDN); mpfr_set_prec (x, 153); mpfr_set_prec (z, 153); mpfr_set_str_binary (x, "1.1101011000111101011110000111010010101001101001110111e28"); test_exp (z, x, MPFR_RNDN); mpfr_prec_round (z, 53, MPFR_RNDN); if (mpfr_cmp (y, z)) { printf ("Error in mpfr_exp for large argument\n"); exit (1); } /* corner cases in mpfr_exp_3 */ mpfr_set_prec (x, 2); mpfr_set_ui (x, 1, MPFR_RNDN); mpfr_set_prec (y, 2); mpfr_exp_3 (y, x, MPFR_RNDN); /* Check some little things about overflow detection */ set_emin (-125); set_emax (128); mpfr_set_prec (x, 107); mpfr_set_prec (y, 107); mpfr_set_str_binary (x, "0.11110000000000000000000000000000000000000000000" "0000000000000000000000000000000000000000000000000000" "00000000E4"); test_exp (y, x, MPFR_RNDN); if (mpfr_cmp_str (y, "0.11000111100001100110010101111101011010010101010000" "1101110111100010111001011111111000110111001011001101010" "01E22", 2, MPFR_RNDN)) { printf ("Special overflow error (1)\n"); mpfr_dump (y); exit (1); } set_emin (emin); set_emax (emax); /* Check for overflow producing a segfault with HUGE exponent */ mpfr_set_ui (x, 3, MPFR_RNDN); mpfr_mul_2ui (x, x, 32, MPFR_RNDN); test_exp (y, x, MPFR_RNDN); /* Can't test return value: May overflow or not*/ /* Bug due to wrong approximation of (x)/log2 */ mpfr_set_prec (x, 163); mpfr_set_str (x, "-4.28ac8fceeadcda06bb56359017b1c81b85b392e7", 16, MPFR_RNDN); mpfr_exp (x, x, MPFR_RNDN); if (mpfr_cmp_str (x, "3.fffffffffffffffffffffffffffffffffffffffe8@-2", 16, MPFR_RNDN)) { printf ("Error for x= -4.28ac8fceeadcda06bb56359017b1c81b85b392e7"); printf ("expected 3.fffffffffffffffffffffffffffffffffffffffe8@-2"); printf ("Got "); mpfr_out_str (stdout, 16, 0, x, MPFR_RNDN); putchar ('\n'); } /* bug found by Guillaume Melquiond, 13 Sep 2005 */ mpfr_set_prec (x, 53); mpfr_set_str_binary (x, "-1E-400"); mpfr_exp (x, x, MPFR_RNDZ); if (mpfr_cmp_ui (x, 1) == 0) { printf ("Error for exp(-2^(-400))\n"); exit (1); } mpfr_clear (x); mpfr_clear (y); mpfr_clear (z); }
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(); }