| Bill Allombert on Mon, 15 Jul 2024 23:11:42 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: vector of t_FRAC questions |
On Mon, Jul 15, 2024 at 10:01:47PM +0200, hermann@stamm-wilbrandt.de wrote:
> I convert 3-dimensional vector or GMP mpq_t rational numbers from
> CGAL function get_build_direction() to GP this way:
>
> https://github.com/Hermann-SW/cgal4gp/blob/main/cgal4gp.cpp#L107-L123
>
> extern "C"
> GEN
> get_build_direction() {
> assert(_simplex != NULL);
> _Vector_3 _dir = _simplex->get_build_direction();
>
> return mkvec3(
> mkfrac(
> mpz2GEN(_dir[0].num.mpz()),
> mpz2GEN(_dir[0].den.mpz())),
> mkfrac(
> mpz2GEN(_dir[1].num.mpz()),
> mpz2GEN(_dir[1].den.mpz())),
> mkfrac(
> mpz2GEN(_dir[2].num.mpz()),
> mpz2GEN(_dir[2].den.mpz())));
> }
>
> That works nicely, but I get denominators of 1:
You are not supposed to use mkfrac with a denominator of 1,
since you already have a t_INT.
Instead you can use
GEN
mkfrac_or_int(GEN a, GEN b)
{
return equali1(b) ? a: mkfrac(a,b);
}
Cheers,
Bill