aboutsummaryrefslogtreecommitdiff
path: root/ic-reals-6.3/math-lib/cos_Q.c~
blob: b1a4a693897b4cf9c80760a22c4ca27f6b404611 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Copyright (C) 2000, Imperial College
 *
 * This file is part of the Imperial College Exact Real Arithmetic Library.
 * See the copyright notice included in the distribution for conditions
 * of use.
 */

#include <stdio.h>
#include "real.h"

Real
cos_QZ(mpz_t a, mpz_t b)
{
	mpz_t x;
	Real r;

	mpz_init(x);
	mpz_mul_ui(x, b, 2);
	r = tan_QZ(a, x);
	mpz_clear(x);
	r = tensor_Int(r, r, -1, 1, 0, 0, 0, 0, 1, 1);
	return r;
}

Real
cos_QInt(int a, int b)
{
	Real r;
	mpz_t ap, bp;

	/* check for overflow */
	if (b > 0x3FFFFFFF || b < 0xC0000000) {
		mpz_init_set_si(ap, a);
		mpz_init_set_si(bp, b);
		mpz_mul_ui(bp, bp, 2);
		r = tan_QZ(ap, bp);
		mpz_clear(ap);
		mpz_clear(bp);
	}
	else 
		r = tan_QInt(a, b * 2);

	r = tensor_Int(r, r, -1, 1, 0, 0, 0, 0, 1, 1);
	return r;
}