Exemplo n.º 1
0
int
rational_div(struct rational* a, const struct rational* b, const struct rational* c)
{
  rational_printf("rational_div");
  struct rational d;
  return rational_inv(&d, c) && (rational_mult(a, b, &d), 1);
}
Exemplo n.º 2
0
void
rational_mult(struct rational* a, const struct rational* b, const struct rational* c)
{
  rational_printf("rational_mult");
  a->p = (b->p)*(c->p);
  a->q = (b->q)*(c->q);
  rational_error = RATIONAL_SUCCESS;
}
Exemplo n.º 3
0
void
rational_sub(struct rational* a, const struct rational* b, const struct rational* c)
{
  struct rational d;
  rational_printf("rational_sub");
  rational_neg(&d, c);
  rational_add(a, b, &d);
}
Exemplo n.º 4
0
void
rational_neg(struct rational* a, const struct rational* b)
{
  rational_printf("rational_neg");
  a->p = - b->p;
  a->q = b->q;
  rational_error = RATIONAL_SUCCESS;
}
Exemplo n.º 5
0
int
rational_inv(struct rational* a, const struct rational* b)
{
  rational_printf("rational_inv");
  if(b->q == 0)
  {
    rational_error = RATIONAL_DIVISION_BY_ZERO;
  }
  else
  {
    a->p = b->q;
    a->q = b->p;
    rational_error = RATIONAL_SUCCESS;
  }
  return (rational_error == RATIONAL_SUCCESS);
}
Exemplo n.º 6
0
int
rational_print(const struct rational* a)
{
  rational_printf("rational_print");
  return printf("%d/%d", a->p, a->q);
}