-
Notifications
You must be signed in to change notification settings - Fork 1
/
rat.h
57 lines (43 loc) · 1.37 KB
/
rat.h
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
47
48
49
50
51
52
53
54
55
56
57
/* rat.h
* typedef Bool
* computing with rationals
* 22 Apr 2000
*/
typedef int Bool; /* Boolean value 0/1 */
typedef struct
{
int num; /* numerator */
int den; /* denominator */
}
Rat;
/* returns sum a+b, normalized */
Rat ratadd (Rat a, Rat b);
/* returns quotient a/b, normalized */
Rat ratdiv (Rat a, Rat b);
/* converts integer i to rational */
Rat ratfromi(int i);
/* computes gcd of integers a and b, 0 if both 0 */
int ratgcd(int a, int b);
/* returns Boolean condition that a > b */
Bool ratgreat (Rat a, Rat b);
/* returns quotient 1/a, normalized only if a is */
Rat ratinv (Rat a);
/* returns Boolean condition that a==b
* a, b are assumed to be normalized
*/
Bool ratiseq (Rat a, Rat b);
/* returns product a*b, normalized */
Rat ratmult (Rat a, Rat b);
/* returns -a, normalized only if a normalized */
Rat ratneg (Rat a);
/* normalizes (make den>0, =1 if num==0)
* and reduces by gcd(num,den)
*/
Rat ratreduce (Rat a);
/* converts rational r to string s, omit den 1
* s must be sufficiently long to contain result
* returns length of string
*/
int rattoa (Rat r, char *s);
/* converts rational a to double */
double rattodouble (Rat a);