-
Notifications
You must be signed in to change notification settings - Fork 0
/
rational.h
47 lines (34 loc) · 1.22 KB
/
rational.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
#include <stdio.h>
#include <string.h>
#include "bigint.h"
/*
* Rational struct members
*
* numerator: numerator of the rational number
* denominator: denominator of the rational number
*
*/
struct _rational {
bigint numerator;
bigint denominator;
}; typedef struct _rational rational;
/* Add two rationals: return frac1 + frac2 */
rational rational_add(rational a, rational b);
/* Subtract two rationals: return frac1 - frac2 */
rational rational_sub(rational a, rational b);
/* Multiply two rationals: return frac1 x frac2 */
rational rational_mul(rational a, rational b);
/* Divide two rationals: return frac1 / frac2 */
rational rational_div(rational a, rational b);
/* Simlify a rational */
rational rational_simplify(rational frac);
/*Used to check if a number could be rational*/
int isRational(char *argv);
/*Completes the check if an argument is rational*/
rational rational_true(char *argv);
/*Converts the argument into a rational number*/
rational rational_frac(char *token, char *ptr);
/*used to print rational numbers*/
void rational_print(rational fraction, int state);
/*Converts bigints to rational*/
rational rational_from_bigint(bigint num, bigint denom);