34 lines
793 B
C
34 lines
793 B
C
#ifndef RATIONAL_NUMBERS
|
|
#define RATIONAL_NUMBERS
|
|
|
|
#include <stdint.h>
|
|
|
|
typedef struct {
|
|
int16_t numerator;
|
|
int16_t denominator;
|
|
} rational_t;
|
|
|
|
rational_t add(rational_t r1, rational_t r2);
|
|
rational_t subtract(rational_t r1, rational_t r2);
|
|
rational_t multiply(rational_t r1, rational_t r2);
|
|
rational_t divide(rational_t r1, rational_t r2);
|
|
rational_t absolute(rational_t r);
|
|
rational_t exp_rational(rational_t r, uint16_t n);
|
|
float exp_real(uint16_t x, rational_t r);
|
|
rational_t reduce(rational_t r);
|
|
|
|
/* See GNUmakefile below for explanation
|
|
* https://github.com/braoult/exercism/blob/master/c/templates/GNUmakefile
|
|
*/
|
|
#if defined UNIT_TEST || defined DEBUG
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#endif
|
|
|
|
#ifdef TESTALL
|
|
#undef TEST_IGNORE
|
|
#define TEST_IGNORE() {}
|
|
#endif
|
|
|
|
#endif
|