diff options
author | Teddy <ted.sybil@gmail.com> | 2013-08-14 14:52:46 +0800 |
---|---|---|
committer | Teddy <ted.sybil@gmail.com> | 2013-08-14 14:52:46 +0800 |
commit | 8c93190f057399889425a9103fe0615dcef4e1b7 (patch) | |
tree | e6b3dbc1967c3dc98cca6e8f2046f4a32afbbf92 /types.cpp | |
parent | c2522466d2fcb5273004f1989b89186cd68001d7 (diff) |
gc detect in list-specific built-ins, proper numeric conversion
Diffstat (limited to 'types.cpp')
-rw-r--r-- | types.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -404,6 +404,7 @@ ReprCons *Continuation::get_repr_cons() { ReprCons::ReprCons(bool _done, EvalObj *_ori) : ori(_ori), done(_done) {} ReprStr::ReprStr(string _repr) : ReprCons(true) { repr = _repr; } EvalObj *ReprStr::next(const string &prev) { + fprintf(stderr, "Oops in ReprStr::next\n"); throw NormalError(INT_ERR); } @@ -995,6 +996,12 @@ void RatNumObj::abs() { #endif } +IntNumObj *RatNumObj::to_int() { + if (val.get_den() != 1) + throw TokenError("an integer", RUN_ERR_WRONG_TYPE); + return new IntNumObj(val.get_num()); +} + ReprCons *RatNumObj::get_repr_cons() { #ifndef GMP_SUPPORT return new ReprStr(int_to_str(A) + "/" + int_to_str(B)); @@ -1088,15 +1095,15 @@ void IntNumObj::div(NumObj *_r) { } void IntNumObj::gcd(NumObj *_r) { - mpz_t g; - mpz_gcd(g, val.get_mpz_t(), static_cast<IntNumObj*>(_r)->val.get_mpz_t()); - val = mpz_class(g); + mpz_gcd(val.get_mpz_t(), + val.get_mpz_t(), + static_cast<IntNumObj*>(_r)->val.get_mpz_t()); } void IntNumObj::lcm(NumObj *_r) { - mpz_t l; - mpz_lcm(l, val.get_mpz_t(), static_cast<IntNumObj*>(_r)->val.get_mpz_t()); - val = mpz_class(l); + mpz_lcm(val.get_mpz_t(), + val.get_mpz_t(), + static_cast<IntNumObj*>(_r)->val.get_mpz_t()); } bool IntNumObj::lt(NumObj *_r) { @@ -1120,6 +1127,10 @@ bool IntNumObj::eq(NumObj *_r) { return val == static_cast<IntNumObj*>(_r)->val; } +IntNumObj* IntNumObj::to_int() { + return new IntNumObj(val); +} + ReprCons *IntNumObj::get_repr_cons() { #ifndef GMP_SUPPORT return new ReprStr(int_to_str(val)); |