forked from github/server
also implement subtraction.
This commit is contained in:
parent
234eb62226
commit
e0229be500
|
@ -49,6 +49,12 @@ variant frac_add(variant a, variant b)
|
|||
return frac_make(num, den);
|
||||
}
|
||||
|
||||
variant frac_sub(variant a, variant b)
|
||||
{
|
||||
b.sa[0] = -b.sa[0];
|
||||
return frac_add(a, b);
|
||||
}
|
||||
|
||||
variant frac_mul(variant a, variant b)
|
||||
{
|
||||
return frac_make(a.sa[0] * b.sa[0], a.sa[1] * b.sa[1]);
|
||||
|
|
|
@ -23,6 +23,7 @@ extern "C" {
|
|||
|
||||
variant frac_make(int num, int den);
|
||||
variant frac_add(variant a, variant b);
|
||||
variant frac_sub(variant a, variant b);
|
||||
variant frac_mul(variant a, variant b);
|
||||
variant frac_div(variant a, variant b);
|
||||
|
||||
|
|
|
@ -18,6 +18,10 @@ static void test_fractions(CuTest *tc) {
|
|||
a = frac_div(b, b);
|
||||
CuAssertIntEquals(tc, 1, a.sa[0]);
|
||||
CuAssertIntEquals(tc, 1, a.sa[1]);
|
||||
a = frac_sub(a, a);
|
||||
CuAssertIntEquals(tc, 0, a.sa[0]);
|
||||
a = frac_mul(a, b);
|
||||
CuAssertIntEquals(tc, 0, a.sa[0]);
|
||||
}
|
||||
|
||||
CuSuite *get_variant_suite(void)
|
||||
|
|
Loading…
Reference in New Issue