Open wictory opened 9 years ago
The returned Mpfr need to be initiated with new2(max(values in input)).
I think I'd go with the first approach. The second one looks too much like a "dirty hack" to me and indeed could easily break. The O(n) memory requirement also isn't that bad, I think, considering that it is only an array of pointers (so max. 8 bytes per element).
Hi,
I would like to add an mpfr_sum wrapper and I would like some input on how to it should best be implemented.
I have two candidates with different caveats.
First I have a function which first creates a Vec<*const Mpfr> of pointers to mpfr_strptr:s. The downside with this is that the call requires O(n) memory, for summing n elements which could be huge.
Second I have a function which bravely unsafely casts a nice &[&Mpfr] into a *const mpfr_srcptr. This function is "correct" in the sense that the tests go through, but is not correct in the sense that it is making assumption which might not hold on other platforms or future versions of the language/compiler/mpfr library. The function brakes without compiler error if another field is added the Mpfr type.
I have a branch in my repo with the code and tests if you would like to check it out further.