Example #1
0
File: mod.c Project: OCForks/urbit
/* functions
*/
  u3_noun
  u3qa_mod(u3_atom a,
           u3_atom b)
  {
#if 0
    if ( b == 3 && a == 2684227708 ) {
      printf("dword at 0x27ff84ff8 is %" PRIu64 "\r\n", *(c3_d *)0x27ff84ff8);
      *(c3_d *)0x27ff84ff8 = 25;
      printf("see, we modified it\r\n");
    }
#endif
    if ( 0 == b ) {
      return u3m_bail(c3__exit);
    } else {
      mpz_t a_mp, b_mp;

      u3r_mp(a_mp, a);
      u3r_mp(b_mp, b);

      mpz_tdiv_r(a_mp, a_mp, b_mp);
      mpz_clear(b_mp);

      return u3i_mp(a_mp);
    }
  }
Example #2
0
File: sqar.c Project: dcow/urbit
/* functions
*/
  u3_noun
  u3qg_sqar(u3_atom a)
  {
    mpz_t a_mp;

    fprintf(stderr, "C squared %d!\r\n", a);

    u3r_mp(a_mp, a);
    mpz_mul(a_mp, a_mp, a_mp);

    return u3i_mp(a_mp);
  }
Example #3
0
  u3_noun
  u3qa_dec(u3_atom a)
  {
    if ( 0 == a ) {
      return u3m_error("decrement-underflow");
    }
    else {
      if ( _(u3a_is_cat(a)) ) {
        return a - 1;
      }
      else {
        mpz_t a_mp;

        u3r_mp(a_mp, a);
        mpz_sub_ui(a_mp, a_mp, 1);

        return u3i_mp(a_mp);
      }
    }
  }
Example #4
0
File: mul.c Project: aulux/urbit
/* functions
*/
  u3_noun
  u3qa_mul(u3_atom a,
                   u3_atom b)
  {
    if ( _(u3a_is_cat(a)) && _(u3a_is_cat(b)) ) {
      c3_d c = ((c3_d) a) * ((c3_d) b);

      return u3i_chubs(1, &c);
    }
    else {
      mpz_t a_mp, b_mp;

      u3r_mp(a_mp, a);
      u3r_mp(b_mp, b);

      mpz_mul(a_mp, a_mp, b_mp);
      mpz_clear(b_mp);

      return u3i_mp(a_mp);
    }
  }