Newbie question

Jonathan Leto jonathan at leto.net
Mon Jun 8 23:26:16 CEST 2009


Howdy,

> ...
>    v2 = A[0][1] * ((2-h)/(2+h))   + A[1][1] * (2+h);
> ...
>
> The matrix elements, 'v2' and 'h' are "doubles".
> I need more precision when calculating this equation, so
> started trying gmp.
>
> The problem I found is that cannot express the equation
> in a single line with gmp.  Is it right ?

Yeah, pretty much, although you don't need as many auxiliary variables
to accomplish what you are doing.

If you initialized two variables, one to (2-h), and one to (2+h), then
you won't need as many extra variables.

Also, you can use mpf_add_ui/mpf_sub_ui, so you don't need your
uno/dos/tres variables.

In general though, you will find that you will need (roughly) a line
for each binary operation in your formula.

If you are more interested in ease of writing than speed, then you may
want to look at the Perl interface to GMP floats, Math::GMPf [1],
which could render your equation in one line via the magic of operator
overloading. You can also use the faster low-level functions from
Perl, so you can choose how much ease you are trading for how much
speed, which I think is a nice option to have.

Cheers,

[1] http://search.cpan.org/dist/Math-GMPf/

> I found my simple equation grows in complexity!  :)
> I'm doing a correct use of the library or missing something?
> So, can I do the work in a single line with gmp ?
>
> Julio
>
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-discuss
>



-- 

Jonathan Leto
jonathan at leto.net
http://leto.net


More information about the gmp-discuss mailing list