void mpfr_taylor_nat_log(mpfr_t R, mpfr_t x, mpz_t n) { assert(mpz_cmp_ui(n, 0) > 0); assert(mpfr_cmp_ui(x, 0) > 0); mpfr_t a, t, tt; mpfr_exp_t b; mpz_t k; unsigned int f = 1000, F = 1000; mpfr_init(a); mpfr_frexp(&b, a, x, MPFR_RNDN); mpfr_ui_sub(a, 1, a, MPFR_RNDN); mpfr_init_set(t, a, MPFR_RNDN); mpfr_init(tt); mpfr_set(R, a, MPFR_RNDN); for(mpz_init_set_ui(k, 2); mpz_cmp(k, n) < 0; mpz_add_ui(k, k, 1)) { mpfr_mul(t, t, a, MPFR_RNDN); mpfr_div_z(tt, t, k, MPFR_RNDN); mpfr_add(R, R, tt, MPFR_RNDN); } mpfr_mul_si(a, MPFR_NAT_LOG_2, b, MPFR_RNDN); mpfr_sub(R, a, R, MPFR_RNDN); }
void mpfr_squaring_int_exp(mpfr_t R, mpfr_t x, mpz_t a) { if(mpz_cmp_ui(a, 0) < 0) { mpz_t b; mpz_init_set(b, a); mpz_neg(b, b); mpfr_squaring_int_exp(R, x, b); mpfr_ui_div(R, 1, R, MPFR_RNDN); } else { mpfr_t y; mpz_t n; mpfr_init_set(y, x, MPFR_RNDN); mpfr_set_ui(R, 1, MPFR_RNDN); mpz_init_set(n, a); while(mpz_cmp_ui(n, 0) > 0) { if(mpz_odd_p(n)) { mpfr_mul(R, R, y, MPFR_RNDN); mpz_sub_ui(n, n, 1); } mpfr_mul(y, y, y, MPFR_RNDN); mpz_div_ui(n, n, 2); } } }
int main (void) { mpfr_t x, y, z, u; int inexact; mpfr_exp_t emax; tests_start_mpfr (); /* check prototypes of mpfr_init_set_* */ inexact = mpfr_init_set_si (x, -1, MPFR_RNDN); inexact = mpfr_init_set (y, x, MPFR_RNDN); inexact = mpfr_init_set_ui (z, 1, MPFR_RNDN); inexact = mpfr_init_set_d (u, 1.0, MPFR_RNDN); emax = mpfr_get_emax (); set_emax (0); mpfr_set_prec (x, 3); mpfr_set_str_binary (x, "0.111"); mpfr_set_prec (y, 2); mpfr_set (y, x, MPFR_RNDU); if (!(MPFR_IS_INF (y) && MPFR_SIGN (y) > 0)) { printf ("Error for y=x=0.111 with px=3, py=2 and emax=0\nx="); mpfr_dump (x); printf ("y="); mpfr_dump (y); exit (1); } set_emax (emax); mpfr_set_prec (y, 11); mpfr_set_str_binary (y, "0.11111111100E-8"); mpfr_set_prec (x, 2); mpfr_set (x, y, MPFR_RNDN); mpfr_set_str_binary (y, "1.0E-8"); if (mpfr_cmp (x, y)) { printf ("Error for y=0.11111111100E-8, prec=2, rnd=MPFR_RNDN\n"); exit (1); } mpfr_clear (x); mpfr_clear (y); mpfr_clear (z); mpfr_clear (u); check_ternary_value (); check_special (); check_neg_special (); test_generic (2, 1000, 10); tests_end_mpfr (); return 0; }
int mpfi_init_set (mpfi_ptr a, mpfi_srcptr b) { int inexact_left, inexact_right, inexact = 0; inexact_left = mpfr_init_set (&(a->left), &(b->left), MPFI_RNDD); inexact_right = mpfr_init_set (&(a->right), &(b->right), MPFI_RNDU); if ( MPFI_NAN_P (a) ) MPFR_RET_NAN; if (inexact_left) inexact += 1; if (inexact_right) inexact += 2; return inexact; }
int main (void) { mp_prec_t p, q; mpfr_t x, y, z, u; mp_rnd_t rnd; int inexact, cmp; /* check prototypes of mpfr_init_set_* */ inexact = mpfr_init_set_si (x, -1, GMP_RNDN); inexact = mpfr_init_set (y, x, GMP_RNDN); inexact = mpfr_init_set_ui (z, 1, GMP_RNDN); inexact = mpfr_init_set_d (u, 1.0, GMP_RNDN); mpfr_set_prec (y, 11); mpfr_set_str_raw (y, "0.11111111100E-8"); mpfr_set_prec (x, 2); mpfr_set (x, y, GMP_RNDN); mpfr_set_str_raw (y, "1.0E-8"); if (mpfr_cmp (x, y)) { fprintf (stderr, "Error for y=0.11111111100E-8, prec=2, rnd=GMP_RNDN\n"); exit (1); } for (p=2; p<500; p++) { mpfr_set_prec (x, p); mpfr_random (x); if (LONG_RAND () % 2) mpfr_neg (x, x, GMP_RNDN); for (q=2; q<2*p; q++) { mpfr_set_prec (y, q); for (rnd=0; rnd<4; rnd++) { inexact = mpfr_set (y, x, rnd); cmp = mpfr_cmp (y, x); if (((inexact == 0) && (cmp != 0)) || ((inexact > 0) && (cmp <= 0)) || ((inexact < 0) && (cmp >= 0))) { fprintf (stderr, "Wrong inexact flag in mpfr_set: expected %d, got %d\n", cmp, inexact); exit (1); } } } } mpfr_clear (x); mpfr_clear (y); mpfr_clear (z); mpfr_clear (u); return 0; }
void mpfr_taylor_sin_bounded(mpfr_t R, mpfr_t x, unsigned int N) { mpfr_printf("%.20RNF\n", x); assert(mpfr_cmp_ui(x, 0) >= 0 && mpfr_cmp(x, MPFR_HALF_PI) <= 0); mpfr_t t, x_2; mpfr_init_set(R, x, MPFR_RNDN); mpfr_init_set(t, x, MPFR_RNDN); mpfr_init(x_2); mpfr_mul(x_2, x, x, MPFR_RNDN); for(int n = 1; n < N; n++) { mpfr_div_ui(t, t, (2*n+1)*(2*(n++)), MPFR_RNDN); mpfr_mul(t, t, x_2, MPFR_RNDN); mpfr_sub(R, R, t, MPFR_RNDN); mpfr_div_ui(t, t, (2*n+1)*(2*n), MPFR_RNDN); mpfr_mul(t, t, x_2, MPFR_RNDN); mpfr_add(R, R, t, MPFR_RNDN); } }
APLVFP PrimFnMonQuoteDotVisV (APLVFP aplVfpRht, LPPRIMSPEC lpPrimSpec) { APLMPI mpzRes = {0}; APLVFP mpfRes = {0}; // Check for indeterminates: !N for integer N < 0 if (mpfr_integer_p (&aplVfpRht) && mpfr_cmp_ui (&aplVfpRht, 0) < 0) return *mpfr_QuadICValue (&aplVfpRht, // No left arg ICNDX_QDOTn, &aplVfpRht, &mpfRes, FALSE); // Check for PosInfinity if (IsMpfPosInfinity (&aplVfpRht)) return mpfPosInfinity; // If the arg is an integer, // and it fits in a ULONG, ... if (mpfr_integer_p (&aplVfpRht) && mpfr_fits_uint_p (&aplVfpRht, MPFR_RNDN)) { mpz_init (&mpzRes); mpfr_init0 (&mpfRes); mpz_fac_ui (&mpzRes, mpfr_get_ui (&aplVfpRht, MPFR_RNDN)); mpfr_set_z (&mpfRes, &mpzRes, MPFR_RNDN); Myz_clear (&mpzRes); } else { // Initialize the result mpfr_init_set (&mpfRes, &aplVfpRht, MPFR_RNDN); mpfr_add_ui (&mpfRes, &mpfRes, 1, MPFR_RNDN); // Let MPFR handle it mpfr_gamma (&mpfRes, &mpfRes, MPFR_RNDN); #ifdef DEBUG mpfr_free_cache (); #endif } // End IF/ELSE return mpfRes; } // End PrimFnMonQuoteDotVisV
void mpfr_taylor_sin(mpfr_t R, mpfr_t x, unsigned int N) { mpfr_t y, t; mpfr_init_set(y, x, MPFR_RNDN); mpfr_init(t); if(mpfr_cmp_ui(y, 0) >= 0) { while(mpfr_cmp(y, MPFR_TWO_PI) >= 0) mpfr_sub(y, y, MPFR_TWO_PI, MPFR_RNDN); if(mpfr_cmp(y, MPFR_PI) >= 0) { mpfr_sub(t, y, MPFR_PI, MPFR_RNDN); if(mpfr_cmp(t, MPFR_PI) >= 0) { mpfr_sub(y, MPFR_TWO_PI, y, MPFR_RNDN); mpfr_taylor_sin_bounded(R, y, N); mpfr_neg(R, R, MPFR_RNDN); } else { mpfr_sub(y, y, MPFR_PI, MPFR_RNDN); mpfr_taylor_sin_bounded(R, y, N); mpfr_neg(R, R, MPFR_RNDN); } } else { if(mpfr_cmp(y, MPFR_HALF_PI) >= 0) { mpfr_sub(y, MPFR_PI, y, MPFR_RNDN); mpfr_taylor_sin_bounded(R, y, N); } else { mpfr_taylor_sin_bounded(R, y, N); } } } else { mpfr_neg(y, y, MPFR_RNDN); mpfr_taylor_sin(R, y, N); mpfr_neg(R, R, MPFR_RNDN); } }
void mpfr_naive_exp(mpfr_t R, mpfr_t x, mpz_t n) { assert(mpz_cmp_ui(n, 0) >= 0); mpfr_t z; mpfr_init_set(z, x, MPFR_RNDN); mpfr_div_z(z, z, n, MPFR_RNDN); mpfr_add_ui(z, z, 1, MPFR_RNDN); if(mpfr_cmp_ui(z, 0) > 0) mpfr_squaring_int_exp(R, z, n); else { mpfr_neg(z, z, MPFR_RNDN); mpfr_squaring_int_exp(R, z, n); if(mpz_odd_p(n)) mpfr_neg(R, R, MPFR_RNDN); } }
void from_ring_elem(elem &result, const ring_elem &a) const { mpfr_init_set(&result, reinterpret_cast<mpfr_ptr>(a.poly_val), GMP_RNDN); }
void init_set(elem &result, elem a) const { mpfr_init_set(&result, &a, GMP_RNDN); }
int nth_new_moon( mpfr_t *result, int n_int ) { mpfr_t n, k, C, approx, E, solar_anomaly, lunar_anomaly, moon_argument, omega, extra, correction, additional; #if(0) PerlIO_printf(PerlIO_stderr(), "nth_new_moon = %d\n", n_int ); #endif if ( dt_astro_global_cache.cache_size > n_int ) { mpfr_t *cached = dt_astro_global_cache.cache[n_int]; if (cached != NULL) { #if(0) PerlIO_printf(PerlIO_stderr(), "Cache HIT for %d\n", n_int); #endif mpfr_set( *result, *cached, GMP_RNDN ); return 1; } } mpfr_init_set_ui( n, n_int, GMP_RNDN ); /* k = n - 24724 */ mpfr_init_set(k, n, GMP_RNDN); mpfr_sub_ui(k, k, 24724, GMP_RNDN ); /* c = k / 1236.85 */ mpfr_init_set(C, k, GMP_RNDN ); mpfr_div_d(C, C, 1236.85, GMP_RNDN); { mpfr_t a, b, c, d, e; mpfr_init(approx); mpfr_init_set_d(a, 730125.59765, GMP_RNDN ); mpfr_init_set_d(b, MEAN_SYNODIC_MONTH * 1236.85, GMP_RNDN ); mpfr_init_set_d(c, 0.0001337, GMP_RNDN ); mpfr_init_set_d(d, -0.000000150, GMP_RNDN ); mpfr_init_set_d(e, 0.00000000073, GMP_RNDN ); polynomial( &approx, &C, 5, &a, &b, &c, &d, &e ); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); mpfr_clear(d); mpfr_clear(e); #ifdef ANNOYING_DEBUG #if (ANNOYING_DEBUG) mpfr_fprintf(stderr, "approx = %.10RNf\n", approx); #endif #endif } { mpfr_t a, b, c; mpfr_init(E); mpfr_init_set_ui(a, 1, GMP_RNDN); mpfr_init_set_d(b, -0.002516, GMP_RNDN ); mpfr_init_set_d(c, -0.0000074, GMP_RNDN ); polynomial( &E, &C, 3, &a, &b, &c ); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); } { mpfr_t a, b, c, d; mpfr_init(solar_anomaly); mpfr_init_set_d(a, 2.5534, GMP_RNDN); mpfr_init_set_d(b, 1236.85, GMP_RNDN); mpfr_mul_d(b, b, 29.10535669, GMP_RNDN); mpfr_init_set_d(c, -0.0000218, GMP_RNDN ); mpfr_init_set_d(d, -0.00000011, GMP_RNDN ); polynomial( &solar_anomaly, &C, 4, &a, &b, &c, &d); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); mpfr_clear(d); } { mpfr_t a, b, c, d, e; mpfr_init(lunar_anomaly); mpfr_init_set_d(a, 201.5643, GMP_RNDN); mpfr_init_set_d(b, 385.81693528 * 1236.85, GMP_RNDN); mpfr_init_set_d(c, 0.0107438, GMP_RNDN); mpfr_init_set_d(d, 0.00001239, GMP_RNDN); mpfr_init_set_d(e, -0.000000058, GMP_RNDN); polynomial( &lunar_anomaly, &C, 5, &a, &b, &c, &d, &e); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); mpfr_clear(d); mpfr_clear(e); } { mpfr_t a, b, c, d, e; mpfr_init(moon_argument); mpfr_init_set_d(a, 160.7108, GMP_RNDN); mpfr_init_set_d(b, 390.67050274 * 1236.85, GMP_RNDN); mpfr_init_set_d(c, -0.0016431, GMP_RNDN); mpfr_init_set_d(d, -0.00000227, GMP_RNDN); mpfr_init_set_d(e, 0.000000011, GMP_RNDN); polynomial( &moon_argument, &C, 5, &a, &b, &c, &d, &e); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); mpfr_clear(d); mpfr_clear(e); } { mpfr_t a, b, c, d; mpfr_init(omega); mpfr_init_set_d(a, 124.7746, GMP_RNDN); mpfr_init_set_d(b, -1.56375580 * 1236.85, GMP_RNDN); mpfr_init_set_d(c, 0.0020691, GMP_RNDN); mpfr_init_set_d(d, 0.00000215, GMP_RNDN); polynomial( &omega, &C, 4, &a, &b, &c, &d); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); mpfr_clear(d); } { mpfr_t a, b, c; mpfr_init(extra); mpfr_init_set_d(a, 299.77, GMP_RNDN); mpfr_init_set_d(b, 132.8475848, GMP_RNDN); mpfr_init_set_d(c, -0.009173, GMP_RNDN); polynomial(&extra, &c, 3, &a, &b, &c); dt_astro_sin(&extra, &extra); mpfr_mul_d(extra, extra, 0.000325, GMP_RNDN); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); } mpfr_init(correction); dt_astro_sin(&correction, &omega); mpfr_mul_d(correction, correction, -0.00017, GMP_RNDN); { int i; for( i = 0; i < NTH_NEW_MOON_CORRECTION_ARGS_SIZE; i++ ) { mpfr_t a, v, w, x, y, z; mpfr_init_set_d(v, NTH_NEW_MOON_CORRECTION_ARGS[i][0], GMP_RNDN); mpfr_init_set_d(w, NTH_NEW_MOON_CORRECTION_ARGS[i][1], GMP_RNDN); mpfr_init_set_d(x, NTH_NEW_MOON_CORRECTION_ARGS[i][2], GMP_RNDN); mpfr_init_set_d(y, NTH_NEW_MOON_CORRECTION_ARGS[i][3], GMP_RNDN); mpfr_init_set_d(z, NTH_NEW_MOON_CORRECTION_ARGS[i][4], GMP_RNDN); mpfr_mul(x, x, solar_anomaly, GMP_RNDN); mpfr_mul(y, y, lunar_anomaly, GMP_RNDN); mpfr_mul(z, z, moon_argument, GMP_RNDN); mpfr_add(x, x, y, GMP_RNDN); mpfr_add(x, x, z, GMP_RNDN); dt_astro_sin(&x, &x); mpfr_init(a); mpfr_pow(a, E, w, GMP_RNDN); mpfr_mul(a, a, v, GMP_RNDN); mpfr_mul(a, a, x, GMP_RNDN); mpfr_add( correction, correction, a, GMP_RNDN ); mpfr_clear(a); mpfr_clear(v); mpfr_clear(w); mpfr_clear(x); mpfr_clear(y); mpfr_clear(z); } } { int z; mpfr_init_set_ui(additional, 0, GMP_RNDN); for (z = 0; z < NTH_NEW_MOON_ADDITIONAL_ARGS_SIZE; z++) { mpfr_t i, j, l; mpfr_init_set_d(i, NTH_NEW_MOON_ADDITIONAL_ARGS[z][0], GMP_RNDN); mpfr_init_set_d(j, NTH_NEW_MOON_ADDITIONAL_ARGS[z][1], GMP_RNDN); mpfr_init_set_d(l, NTH_NEW_MOON_ADDITIONAL_ARGS[z][2], GMP_RNDN); mpfr_mul(j, j, k, GMP_RNDN); mpfr_add(j, j, i, GMP_RNDN); dt_astro_sin(&j, &j); mpfr_mul(l, l, j, GMP_RNDN); mpfr_add(additional, additional, l, GMP_RNDN); mpfr_clear(i); mpfr_clear(j); mpfr_clear(l); } } #ifdef ANNOYING_DEBUG #if (ANNOYING_DEBUG) mpfr_fprintf(stderr, "correction = %.10RNf\nextra = %.10RNf\nadditional = %.10RNf\n", correction, extra, additional ); #endif #endif mpfr_set(*result, approx, GMP_RNDN); mpfr_add(*result, *result, correction, GMP_RNDN); mpfr_add(*result, *result, extra, GMP_RNDN); mpfr_add(*result, *result, additional, GMP_RNDN); adjust_lunar_phase_to_zero( result ); mpfr_clear(n); mpfr_clear(k); mpfr_clear(C); mpfr_clear(approx); mpfr_clear(E); mpfr_clear(solar_anomaly); mpfr_clear(lunar_anomaly); mpfr_clear(moon_argument); mpfr_clear(omega); mpfr_clear(extra); mpfr_clear(correction); mpfr_clear(additional); if (dt_astro_global_cache.cache_size == 0) { dt_astro_global_cache.cache_size = 200000; Newxz( dt_astro_global_cache.cache, dt_astro_global_cache.cache_size, mpfr_t * ); }
int lunar_longitude( mpfr_t *result, mpfr_t *moment ) { mpfr_t C, mean_moon, elongation, solar_anomaly, lunar_anomaly, moon_node, E, correction, venus, jupiter, flat_earth, N, fullangle; mpfr_init(C); julian_centuries( &C, moment ); { mpfr_t a, b, c, d, e; mpfr_init(mean_moon); mpfr_init_set_d(a, 218.316591, GMP_RNDN); mpfr_init_set_d(b, 481267.88134236, GMP_RNDN); mpfr_init_set_d(c, -0.0013268, GMP_RNDN); mpfr_init_set_ui(d, 1, GMP_RNDN); mpfr_div_ui(d, d, 538841, GMP_RNDN); mpfr_init_set_si(e, -1, GMP_RNDN); mpfr_div_ui(e, e, 65194000, GMP_RNDN); polynomial( &mean_moon, &C, 5, &a, &b, &c, &d, &e ); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); mpfr_clear(d); mpfr_clear(e); } { mpfr_t a, b, c, d, e; mpfr_init(elongation); mpfr_init_set_d(a, 297.8502042, GMP_RNDN); mpfr_init_set_d(b, 445267.1115168, GMP_RNDN); mpfr_init_set_d(c, -0.00163, GMP_RNDN); mpfr_init_set_ui(d, 1, GMP_RNDN); mpfr_div_ui(d, d, 545868, GMP_RNDN); mpfr_init_set_si(e, -1, GMP_RNDN); mpfr_div_ui(e, e, 113065000, GMP_RNDN); polynomial( &elongation, &C, 5, &a, &b, &c, &d, &e ); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); mpfr_clear(d); mpfr_clear(e); } { mpfr_t a, b, c, d; mpfr_init(solar_anomaly); mpfr_init_set_d(a, 357.5291092, GMP_RNDN); mpfr_init_set_d(b, 35999.0502909, GMP_RNDN); mpfr_init_set_d(c, -0.0001536, GMP_RNDN); mpfr_init_set_ui(d, 1, GMP_RNDN); mpfr_div_ui(d, d, 24490000, GMP_RNDN); polynomial( &solar_anomaly, &C, 4, &a, &b, &c, &d ); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); mpfr_clear(d); } { mpfr_t a, b, c, d, e; mpfr_init(lunar_anomaly); mpfr_init_set_d(a, 134.9634114, GMP_RNDN); mpfr_init_set_d(b, 477198.8676313, GMP_RNDN); mpfr_init_set_d(c, 0.0008997, GMP_RNDN); mpfr_init_set_ui(d, 1, GMP_RNDN); mpfr_div_ui(d, d, 69699, GMP_RNDN); mpfr_init_set_si(e, -1, GMP_RNDN); mpfr_div_ui(e, e, 14712000, GMP_RNDN); polynomial( &lunar_anomaly, &C, 5, &a, &b, &c, &d, &e); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); mpfr_clear(d); mpfr_clear(e); } { mpfr_t a, b, c, d, e; mpfr_init(moon_node); mpfr_init_set_d(a, 93.2720993, GMP_RNDN); mpfr_init_set_d(b, 483202.0175273, GMP_RNDN); mpfr_init_set_d(c, -0.0034029, GMP_RNDN); mpfr_init_set_si(d, -1, GMP_RNDN); mpfr_div_ui(d, d, 3526000, GMP_RNDN); mpfr_init_set_ui(e, 1, GMP_RNDN); mpfr_div_ui(e, e, 863310000, GMP_RNDN); polynomial(&moon_node, &C, 5, &a, &b, &c, &d, &e); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); mpfr_clear(d); mpfr_clear(e); } { mpfr_t a, b, c; mpfr_init(E); mpfr_init_set_ui(a, 1, GMP_RNDN); mpfr_init_set_d(b, -0.002516, GMP_RNDN); mpfr_init_set_d(c, -0.0000074, GMP_RNDN); polynomial( &E, &C, 3, &a, &b, &c ); mpfr_clear(a); mpfr_clear(b); mpfr_clear(c); } { int i; mpfr_t fugly; mpfr_init_set_ui(fugly, 0, GMP_RNDN); for(i = 0; i < LUNAR_LONGITUDE_ARGS_SIZE; i++) { mpfr_t a, b, v, w, x, y, z; mpfr_init_set_d( v, LUNAR_LONGITUDE_ARGS[i][0], GMP_RNDN ); mpfr_init_set_d( w, LUNAR_LONGITUDE_ARGS[i][1], GMP_RNDN ); mpfr_init_set_d( x, LUNAR_LONGITUDE_ARGS[i][2], GMP_RNDN ); mpfr_init_set_d( y, LUNAR_LONGITUDE_ARGS[i][3], GMP_RNDN ); mpfr_init_set_d( z, LUNAR_LONGITUDE_ARGS[i][4], GMP_RNDN ); mpfr_init(b); mpfr_pow(b, E, x, GMP_RNDN); mpfr_mul(w, w, elongation, GMP_RNDN); mpfr_mul(x, x, solar_anomaly, GMP_RNDN); mpfr_mul(y, y, lunar_anomaly, GMP_RNDN); mpfr_mul(z, z, moon_node, GMP_RNDN); mpfr_init_set(a, w, GMP_RNDN); mpfr_add(a, a, x, GMP_RNDN); mpfr_add(a, a, y, GMP_RNDN); mpfr_add(a, a, z, GMP_RNDN); dt_astro_sin(&a, &a); mpfr_mul(a, a, v, GMP_RNDN); mpfr_mul(a, a, b, GMP_RNDN); mpfr_add(fugly, fugly, a, GMP_RNDN); mpfr_clear(a); mpfr_clear(b); mpfr_clear(v); mpfr_clear(w); mpfr_clear(x); mpfr_clear(y); mpfr_clear(z); } mpfr_init_set_d( correction, 0.000001, GMP_RNDN ); mpfr_mul( correction, correction, fugly, GMP_RNDN); mpfr_clear(fugly); } { mpfr_t a, b; mpfr_init(venus); mpfr_init_set_d(a, 119.75, GMP_RNDN); mpfr_init_set(b, C, GMP_RNDN); mpfr_mul_d(b, b, 131.849, GMP_RNDN); mpfr_add(a, a, b, GMP_RNDN); dt_astro_sin(&a, &a); mpfr_mul_d(venus, a, 0.003957, GMP_RNDN ); mpfr_clear(a); mpfr_clear(b); } { mpfr_t a, b; mpfr_init(jupiter); mpfr_init_set_d(a, 53.09, GMP_RNDN); mpfr_init_set(b, C, GMP_RNDN); mpfr_mul_d(b, b, 479264.29, GMP_RNDN); mpfr_add(a, a, b, GMP_RNDN); dt_astro_sin(&a, &a); mpfr_mul_d(jupiter, a, 0.000318, GMP_RNDN ); mpfr_clear(a); mpfr_clear(b); } { mpfr_t a; mpfr_init(flat_earth); mpfr_init_set(a, mean_moon, GMP_RNDN); mpfr_sub(a, a, moon_node, GMP_RNDN); dt_astro_sin(&a, &a); mpfr_mul_d(flat_earth, a, 0.001962, GMP_RNDN); mpfr_clear(a); } mpfr_set(*result, mean_moon, GMP_RNDN); mpfr_add(*result, *result, correction, GMP_RNDN); mpfr_add(*result, *result, venus, GMP_RNDN); mpfr_add(*result, *result, jupiter, GMP_RNDN); mpfr_add(*result, *result, flat_earth, GMP_RNDN); #ifdef ANNOYING_DEBUG #if (ANNOYING_DEBUG) mpfr_fprintf(stderr, "mean_moon = %.10RNf\ncorrection = %.10RNf\nvenus = %.10RNf\njupiter = %.10RNf\nflat_earth = %.10RNf\n", mean_moon, correction, venus, jupiter, flat_earth); #endif #endif mpfr_init(N); nutation(&N, moment); mpfr_add(*result, *result, N, GMP_RNDN); mpfr_init_set_ui(fullangle, 360, GMP_RNDN); #ifdef ANNOYING_DEBUG #if (ANNOYING_DEBUG) mpfr_fprintf(stderr, "lunar = mod(%.10RNf) = ", *result ); #endif #endif dt_astro_mod(result, result, &fullangle); #ifdef ANNOYING_DEBUG #if (ANNOYING_DEBUG) mpfr_fprintf(stderr, "%.10RNf\n", *result ); #endif #endif mpfr_clear(C); mpfr_clear(mean_moon); mpfr_clear(elongation); mpfr_clear(solar_anomaly); mpfr_clear(lunar_anomaly); mpfr_clear(moon_node); mpfr_clear(E); mpfr_clear(correction); mpfr_clear(venus); mpfr_clear(jupiter); mpfr_clear(flat_earth); mpfr_clear(N); mpfr_clear(fullangle); return 1; }
int main (void) { mp_prec_t p, q; mpfr_t x, y, z, u; int rnd; int inexact, cmp; mp_exp_t emax; tests_start_mpfr (); /* check prototypes of mpfr_init_set_* */ inexact = mpfr_init_set_si (x, -1, GMP_RNDN); inexact = mpfr_init_set (y, x, GMP_RNDN); inexact = mpfr_init_set_ui (z, 1, GMP_RNDN); inexact = mpfr_init_set_d (u, 1.0, GMP_RNDN); mpfr_set_nan (x); (mpfr_set) (y, x, GMP_RNDN); MPFR_ASSERTN(mpfr_nan_p (y)); mpfr_set_inf (x, 1); mpfr_set (y, x, GMP_RNDN); MPFR_ASSERTN(mpfr_inf_p (y) && mpfr_sgn (y) > 0); mpfr_set_inf (x, -1); mpfr_set (y, x, GMP_RNDN); MPFR_ASSERTN(mpfr_inf_p (y) && mpfr_sgn (y) < 0); mpfr_set_ui (x, 0, GMP_RNDN); mpfr_set (y, x, GMP_RNDN); MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS(y)); mpfr_set_ui (x, 0, GMP_RNDN); mpfr_neg (x, x, GMP_RNDN); mpfr_set (y, x, GMP_RNDN); MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_NEG(y)); emax = mpfr_get_emax (); set_emax (0); mpfr_set_prec (x, 3); mpfr_set_str_binary (x, "0.111"); mpfr_set_prec (y, 2); mpfr_set (y, x, GMP_RNDU); if (!(MPFR_IS_INF (y) && MPFR_SIGN (y) > 0)) { printf ("Error for y=x=0.111 with px=3, py=2 and emax=0\nx="); mpfr_dump (x); printf ("y="); mpfr_dump (y); exit (1); } MPFR_ASSERTN (MPFR_IS_INF (y) && MPFR_SIGN (y) > 0); set_emax (emax); mpfr_set_prec (y, 11); mpfr_set_str_binary (y, "0.11111111100E-8"); mpfr_set_prec (x, 2); mpfr_set (x, y, GMP_RNDN); mpfr_set_str_binary (y, "1.0E-8"); if (mpfr_cmp (x, y)) { printf ("Error for y=0.11111111100E-8, prec=2, rnd=GMP_RNDN\n"); exit (1); } for (p=2; p<500; p++) { mpfr_set_prec (x, p); mpfr_random (x); if (randlimb () % 2) mpfr_neg (x, x, GMP_RNDN); for (q=2; q<2*p; q++) { mpfr_set_prec (y, q); for (rnd = 0; rnd < GMP_RND_MAX; rnd++) { inexact = mpfr_set (y, x, (mp_rnd_t) rnd); cmp = mpfr_cmp (y, x); if (((inexact == 0) && (cmp != 0)) || ((inexact > 0) && (cmp <= 0)) || ((inexact < 0) && (cmp >= 0))) { printf ("Wrong inexact flag in mpfr_set: expected %d," " got %d\n", cmp, inexact); exit (1); } } } } mpfr_clear (x); mpfr_clear (y); mpfr_clear (z); mpfr_clear (u); check_neg_special (); tests_end_mpfr (); return 0; }